FuzzyCondition extends SingleColumnCondition { @Override public Query doQuery(SingleColumnMapper<?> mapper, Analyzer analyzer) { if (mapper.base == String.class) { Term term = new Term(field, value); return new FuzzyQuery(term, maxEdits, prefixLength, maxExpansions, transpositions); } else { throw new IndexException("Fuzzy queries are not supported by mapper {}", mapper); } } FuzzyCondition(Float boost,
                          String field,
                          String value,
                          Integer maxEdits,
                          Integer prefixLength,
                          Integer maxExpansions,
                          Boolean transpositions); @Override Query doQuery(SingleColumnMapper<?> mapper, Analyzer analyzer); @Override MoreObjects.ToStringHelper toStringHelper(); static final int DEFAULT_MAX_EDITS; static final int DEFAULT_PREFIX_LENGTH; static final int DEFAULT_MAX_EXPANSIONS; static final boolean DEFAULT_TRANSPOSITIONS; final String value; final int maxEdits; final int prefixLength; final int maxExpansions; final boolean transpositions; }
@Test public void testQuery() { Schema schema = schema().mapper("name", stringMapper()).build(); FuzzyCondition condition = new FuzzyCondition(0.5f, "name", "tr", 1, 2, 49, true); Query query = condition.doQuery(schema); assertNotNull("Query is not built", query); assertEquals("Query type is wrong", FuzzyQuery.class, query.getClass()); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; assertEquals("Query field is wrong", "name", fuzzyQuery.getField()); assertEquals("Query term is wrong", "tr", fuzzyQuery.getTerm().text()); assertEquals("Query max edits is wrong", 1, fuzzyQuery.getMaxEdits()); assertEquals("Query prefix length is wrong", 2, fuzzyQuery.getPrefixLength()); }