@Override protected Query newFuzzyQuery(String text, int fuzziness) { BooleanQuery.Builder bq = new BooleanQuery.Builder(); bq.setDisableCoord(true); for (Map.Entry<String, Float> entry : weights.entrySet()) { String field = entry.getKey(); FieldType type = schema.getFieldType(field); Query fuzzy; if (type instanceof TextField) { // If the field type is a TextField then use the multi term analyzer. Analyzer analyzer = ((TextField) type).getMultiTermAnalyzer(); String term = TextField.analyzeMultiTerm(field, text, analyzer).utf8ToString(); fuzzy = new FuzzyQuery(new Term(entry.getKey(), term), fuzziness); } else { // If the type is *not* a TextField don't do any analysis. fuzzy = new FuzzyQuery(new Term(entry.getKey(), text), fuzziness); } float boost = entry.getValue(); if (boost != 1f) { fuzzy = new BoostQuery(fuzzy, boost); } bq.add(fuzzy, BooleanClause.Occur.SHOULD); } return simplify(bq.build()); }
@Override protected Query newPrefixQuery(String text) { BooleanQuery.Builder bq = new BooleanQuery.Builder(); bq.setDisableCoord(true); for (Map.Entry<String, Float> entry : weights.entrySet()) { String field = entry.getKey(); FieldType type = schema.getFieldType(field); Query prefix; if (type instanceof TextField) { // If the field type is a TextField then use the multi term analyzer. Analyzer analyzer = ((TextField) type).getMultiTermAnalyzer(); String term = TextField.analyzeMultiTerm(field, text, analyzer).utf8ToString(); SchemaField sf = schema.getField(field); prefix = sf.getType().getPrefixQuery(qParser, sf, term); } else { // If the type is *not* a TextField don't do any analysis. SchemaField sf = schema.getField(field); prefix = type.getPrefixQuery(qParser, sf, text); } float boost = entry.getValue(); if (boost != 1f) { prefix = new BoostQuery(prefix, boost); } bq.add(prefix, BooleanClause.Occur.SHOULD); } return simplify(bq.build()); }