private static ParamInfo parseTerm(FunctionQParser fp) throws SyntaxError { ParamInfo paramInfo = new ParamInfo(); paramInfo.field = fp.parseArg(); String textVal = fp.parseArg(); if(textVal == null || textVal.trim().length() == 0){ return paramInfo; } if(fp.hasMoreArguments()){ String similarity = fp.parseArg().toLowerCase().trim(); if( !similarity.equals(SimilarityType.DOC_LEN) && !similarity.equals(SimilarityType.PARAM_LEN) && !similarity.equals(SimilarityType.DICE) && !similarity.equals(SimilarityType.JACCARD)){ log.error(String.format("Invalid similarity class: %s. Defaulting to %s", similarity, SimilarityType.DOC_LEN)); similarity = SimilarityType.DOC_LEN; } paramInfo.similarity = similarity; } // need to do analysis on the term Analyzer analyzer = fp.getReq().getSchema().getIndexAnalyzer(); paramInfo.analyzer = analyzer; try { List<String> terms = TermExtractionHelper.getTermsFromString(analyzer, paramInfo.field, textVal); paramInfo.terms = new HashSet<String>(terms); } catch (IOException e) { SolrException.log(log, "Exception during debug", e); return null; } return paramInfo; }
public ValueSource parse(FunctionQParser fp) throws SyntaxError { String indexedField = fp.parseArg(); Analyzer analyzer = fp.getReq().getSchema().getIndexAnalyzer(); return new FieldIndexedValueSource(indexedField, analyzer); } }
public ValueSource parse(FunctionQParser fp) throws SyntaxError { String indexedField = fp.parseArg(); Analyzer analyzer = fp.getReq().getSchema().getIndexAnalyzer(); return new FieldLenValueSource(indexedField, analyzer); } }
Analyzer analyzer = fp.getReq().getSchema().getIndexAnalyzer(); TokenStream ts = analyzer.tokenStream(fieldInfo.field, new StringReader(textVal)); try {
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { FieldInfo fieldInfo = parseTerm(fp); if(fieldInfo == null){ return new DoubleConstValueSource(-1.0d); } if(fieldInfo.terms.size() == 0){ return new DoubleConstValueSource(0.0d); } ValueSource[] matches = new ValueSource[fieldInfo.terms.size()]; for(int i = 0; i < fieldInfo.terms.size(); i++){ TermInfo termInfo = fieldInfo.terms.get(i); matches[i] = new BinaryTermExistsValueSource(fieldInfo.field, termInfo.indexedBytes.utf8ToString(), fieldInfo.indexedField, termInfo.indexedBytes); } final SumFloatFunction sum = new SumFloatFunction(matches); ValueSource length = null; if(fieldInfo.useDocLength){ Analyzer analyzer = fp.getReq().getSchema().getIndexAnalyzer(); length = new FieldLenValueSource(fieldInfo.indexedField, analyzer); } else{ length = new DoubleConstValueSource(fieldInfo.terms.size()); } return new DivFloatFunction(sum, length); }