Search in sources :

Example 1 with ZuliaQuery

use of io.zulia.message.ZuliaQuery in project zuliasearch by zuliaio.

the class ZuliaIndex method parseQueryToLucene.

private Query parseQueryToLucene(ZuliaQuery.Query zuliaQuery) throws Exception {
    try {
        ZuliaQuery.Query.Operator defaultOperator = zuliaQuery.getDefaultOp();
        String queryText = zuliaQuery.getQ();
        int minimumShouldMatchNumber = zuliaQuery.getMm();
        List<String> queryFields = zuliaQuery.getQfList();
        if (queryText.isEmpty()) {
            if (queryFields.isEmpty()) {
                return new MatchAllDocsQuery();
            } else {
                queryText = "*";
            }
        }
        Collection<String> defaultSearchFieldList;
        if (queryFields.isEmpty()) {
            defaultSearchFieldList = indexConfig.getIndexSettings().getDefaultSearchFieldList();
        } else {
            defaultSearchFieldList = queryFields;
        }
        Query query;
        boolean dismax = zuliaQuery.getDismax();
        float dismaxTie = zuliaQuery.getDismaxTie();
        if (zuliaQuery.getLegacy()) {
            query = parseWithLegacyQueryParser(queryText, minimumShouldMatchNumber, defaultOperator, defaultSearchFieldList, dismax, dismaxTie);
        } else {
            query = parseWithQueryParser(queryText, minimumShouldMatchNumber, defaultOperator, defaultSearchFieldList, dismax, dismaxTie);
        }
        boolean negative = QueryUtil.isNegative(query);
        if (negative) {
            query = QueryUtil.fixNegativeQuery(query);
        }
        return query;
    } catch (ParseException e) {
        throw new IllegalArgumentException("Invalid Query: " + zuliaQuery.getQ());
    }
}
Also used : Query(org.apache.lucene.search.Query) FunctionScoreQuery(org.apache.lucene.queries.function.FunctionScoreQuery) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ZuliaQuery(io.zulia.message.ZuliaQuery) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ParseException(org.apache.lucene.queryparser.classic.ParseException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

ZuliaQuery (io.zulia.message.ZuliaQuery)1 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)1 FunctionScoreQuery (org.apache.lucene.queries.function.FunctionScoreQuery)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1