Search in sources :

Example 6 with Fuzziness

use of org.elasticsearch.common.unit.Fuzziness in project fess by codelibs.

the class QueryHelper method convertFuzzyQuery.

protected QueryBuilder convertFuzzyQuery(final QueryContext context, final FuzzyQuery fuzzyQuery, final float boost) {
    final Term term = fuzzyQuery.getTerm();
    final String field = term.field();
    // TODO fuzzy value
    if (Constants.DEFAULT_FIELD.equals(field)) {
        context.addFieldLog(field, term.text());
        return buildDefaultQueryBuilder((f, b) -> QueryBuilders.fuzzyQuery(f, term.text()).fuzziness(Fuzziness.fromEdits(fuzzyQuery.getMaxEdits())).boost(b * boost));
    } else if (isSearchField(field)) {
        context.addFieldLog(field, term.text());
        return QueryBuilders.fuzzyQuery(field, term.text()).boost(boost).fuzziness(Fuzziness.fromEdits(fuzzyQuery.getMaxEdits()));
    } else {
        final String origQuery = fuzzyQuery.toString();
        context.addFieldLog(Constants.DEFAULT_FIELD, origQuery);
        context.addHighlightedQuery(origQuery);
        return buildDefaultQueryBuilder((f, b) -> QueryBuilders.fuzzyQuery(f, origQuery).fuzziness(Fuzziness.fromEdits(fuzzyQuery.getMaxEdits())).boost(b * boost));
    }
}
Also used : Query(org.apache.lucene.search.Query) Constants(org.codelibs.fess.Constants) SortBuilders(org.elasticsearch.search.sort.SortBuilders) OptionalThing(org.dbflute.optional.OptionalThing) Term(org.apache.lucene.index.Term) PhraseQuery(org.apache.lucene.search.PhraseQuery) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ScoreFunctionBuilders(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders) GeoInfo(org.codelibs.fess.entity.GeoInfo) QueryContext(org.codelibs.fess.entity.QueryContext) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Fuzziness(org.elasticsearch.common.unit.Fuzziness) Locale(java.util.Locale) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) Resource(javax.annotation.Resource) Set(java.util.Set) PrefixQuery(org.apache.lucene.search.PrefixQuery) UUID(java.util.UUID) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) WildcardQuery(org.apache.lucene.search.WildcardQuery) List(java.util.List) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) SortOrder(org.elasticsearch.search.sort.SortOrder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ParseException(org.apache.lucene.queryparser.classic.ParseException) HashMap(java.util.HashMap) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FacetInfo(org.codelibs.fess.entity.FacetInfo) SortBuilder(org.elasticsearch.search.sort.SortBuilder) UserMessages(org.lastaflute.core.message.UserMessages) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) StringUtil(org.codelibs.core.lang.StringUtil) BooleanClause(org.apache.lucene.search.BooleanClause) Consumer(java.util.function.Consumer) TermQuery(org.apache.lucene.search.TermQuery) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Term(org.apache.lucene.index.Term)

Aggregations

Fuzziness (org.elasticsearch.common.unit.Fuzziness)6 HashMap (java.util.HashMap)3 ParsingException (org.elasticsearch.common.ParsingException)3 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 MatchQuery (org.elasticsearch.index.search.MatchQuery)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Consumer (java.util.function.Consumer)1 Stream (java.util.stream.Stream)1 PostConstruct (javax.annotation.PostConstruct)1 Resource (javax.annotation.Resource)1 Term (org.apache.lucene.index.Term)1 ExtendedCommonTermsQuery (org.apache.lucene.queries.ExtendedCommonTermsQuery)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)1