Search in sources :

Example 1 with AnalyzedPrefixSearchQueryParser

use of com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser in project step by STEPBible.

the class EntityIndexReaderImpl method search.

// CHECKSTYLE:OFF
@Override
public EntityDoc[] search(final String[] fieldNames, final String value, final Filter filter, final Sort sort, final boolean analyzePrefix, final String queryRemainder, final Integer maxResults, final boolean useOrOperatorBetweenValues) {
    // CHECKSTYLE:ON
    final AllResultsCollector collector = new AllResultsCollector();
    Query parsed = null;
    QueryParser parser;
    if (analyzePrefix) {
        parser = new AnalyzedPrefixSearchQueryParser(LUCENE_30, fieldNames, this.config.getAnalyzerInstance());
    } else {
        parser = new MultiFieldQueryParser(LUCENE_30, fieldNames, this.config.getAnalyzerInstance());
    }
    parser.setDefaultOperator(useOrOperatorBetweenValues ? Operator.OR : Operator.AND);
    try {
        if (queryRemainder != null) {
            final StringBuilder sb = new StringBuilder(value.length() + queryRemainder.length() + 1);
            sb.append(value);
            sb.append(' ');
            sb.append(queryRemainder);
            parsed = parser.parse(sb.toString());
        } else {
            parsed = parser.parse(value);
        }
        LOGGER.debug("Search query is [{}]", parsed);
        if (sort != null) {
            final TopFieldDocs search = this.searcher.search(parsed, filter, maxResults == null ? Integer.MAX_VALUE : maxResults, sort);
            return extractDocIds(search);
        } else {
            this.searcher.search(parsed, filter, collector);
            return extractDocIds(collector);
        }
    } catch (final ParseException e) {
        throw new StepInternalException("Unable to parse query", e);
    } catch (final IOException e) {
        throw new StepInternalException("Unable to search given query: " + parsed != null ? parsed.toString() : "<unknown>", e);
    }
}
Also used : AnalyzedPrefixSearchQueryParser(com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) QueryParser(org.apache.lucene.queryParser.QueryParser) AnalyzedPrefixSearchQueryParser(com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser) AllResultsCollector(com.tyndalehouse.step.core.data.AllResultsCollector) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 2 with AnalyzedPrefixSearchQueryParser

use of com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser in project step by STEPBible.

the class EntityIndexReaderImpl method getQueryParser.

@Override
public QueryParser getQueryParser(final boolean analyzePrefix, final boolean useOrOperatorBetweenValues, final String... defaultFields) {
    QueryParser parser;
    if (analyzePrefix) {
        parser = new AnalyzedPrefixSearchQueryParser(LUCENE_30, defaultFields, this.config.getAnalyzerInstance());
    } else if (defaultFields.length == 1) {
        parser = new QueryParser(LUCENE_30, defaultFields[0], this.config.getAnalyzerInstance());
    } else {
        parser = new MultiFieldQueryParser(LUCENE_30, defaultFields, this.config.getAnalyzerInstance());
    }
    parser.setDefaultOperator(useOrOperatorBetweenValues ? Operator.OR : Operator.AND);
    return parser;
}
Also used : AnalyzedPrefixSearchQueryParser(com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) QueryParser(org.apache.lucene.queryParser.QueryParser) AnalyzedPrefixSearchQueryParser(com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser)

Aggregations

AnalyzedPrefixSearchQueryParser (com.tyndalehouse.step.core.data.AnalyzedPrefixSearchQueryParser)2 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)2 QueryParser (org.apache.lucene.queryParser.QueryParser)2 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)1 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 IOException (java.io.IOException)1 ParseException (org.apache.lucene.queryParser.ParseException)1