Example usage for org.apache.lucene.queryparser.flexible.standard CommonQueryParserConfiguration setPhraseSlop

List of usage examples for org.apache.lucene.queryparser.flexible.standard CommonQueryParserConfiguration setPhraseSlop

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.standard CommonQueryParserConfiguration setPhraseSlop.

Prototype

public void setPhraseSlop(int defaultPhraseSlop);

Source Link

Document

Sets the default slop for phrases.

Usage

From source file:org.exist.indexing.lucene.LuceneIndexWorker.java

License:Open Source License

protected void setOptions(Properties options, CommonQueryParserConfiguration parser) throws ParseException {
    if (options == null)
        return;/*w w  w  . j  av  a 2  s. c o  m*/
    String option = options.getProperty(OPTION_DEFAULT_OPERATOR);
    if (option != null && parser instanceof QueryParserBase) {
        if (DEFAULT_OPERATOR_OR.equals(option))
            ((QueryParserBase) parser).setDefaultOperator(QueryParser.OR_OPERATOR);
        else
            ((QueryParserBase) parser).setDefaultOperator(QueryParser.AND_OPERATOR);
    }
    option = options.getProperty(OPTION_LEADING_WILDCARD);
    if (option != null)
        parser.setAllowLeadingWildcard(option.equalsIgnoreCase("yes"));
    option = options.getProperty(OPTION_PHRASE_SLOP);
    if (option != null) {
        try {
            int slop = Integer.parseInt(option);
            parser.setPhraseSlop(slop);
        } catch (NumberFormatException e) {
            throw new ParseException("value for option " + OPTION_PHRASE_SLOP + " needs to be a number");
        }
    }
    option = options.getProperty(OPTION_FILTER_REWRITE);
    if (option != null) {
        if (option.equalsIgnoreCase("yes"))
            parser.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
        else
            parser.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
    }
}