Example usage for org.apache.lucene.queryparser.classic QueryParserBase OR_OPERATOR

List of usage examples for org.apache.lucene.queryparser.classic QueryParserBase OR_OPERATOR

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.classic QueryParserBase OR_OPERATOR.

Prototype

Operator OR_OPERATOR

To view the source code for org.apache.lucene.queryparser.classic QueryParserBase OR_OPERATOR.

Click Source Link

Document

Alternative form of QueryParser.Operator.OR

Usage

From source file:org.eu.bitzone.Leia.java

License:Apache License

/**
 * Create a Query instance that corresponds to values selected in the UI, such as analyzer class name and arguments,
 * and default field.// ww  w .  j a  va 2 s . co m
 *
 * @return
 */
public Query createQuery(final String queryString) throws Exception {
    final Object srchOpts = find("srchOptTabs");
    final Analyzer analyzer = createAnalyzer(srchOpts);
    if (analyzer == null) {
        return null;
    }
    final String defField = getDefaultField(srchOpts);
    final QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, defField, analyzer);
    final Object ckXmlParser = find(srchOpts, "ckXmlParser");
    final Object ckWild = find(srchOpts, "ckWild");
    final Object ckPosIncr = find(srchOpts, "ckPosIncr");
    final Object ckLoExp = find(srchOpts, "ckLoExp");
    final Object cbDateRes = find(srchOpts, "cbDateRes");
    final DateTools.Resolution resolution = Util.getResolution(getString(cbDateRes, "text"));
    final Object cbOp = find(srchOpts, "cbOp");
    final Object bqMaxCount = find(srchOpts, "bqMaxCount");
    int maxCount = 1024;
    try {
        maxCount = Integer.parseInt(getString(bqMaxCount, "text"));
    } catch (final Exception e) {
        e.printStackTrace();
        showStatus("Invalid BooleanQuery max clause count, using default 1024");
    }
    QueryParser.Operator op;
    BooleanQuery.setMaxClauseCount(maxCount);
    final String opString = getString(cbOp, "text");
    if (opString.equalsIgnoreCase("OR")) {
        op = QueryParserBase.OR_OPERATOR;
    } else {
        op = QueryParserBase.AND_OPERATOR;
    }
    qp.setAllowLeadingWildcard(getBoolean(ckWild, "selected"));
    qp.setEnablePositionIncrements(getBoolean(ckPosIncr, "selected"));
    qp.setLowercaseExpandedTerms(getBoolean(ckLoExp, "selected"));
    qp.setDateResolution(resolution);
    qp.setDefaultOperator(op);
    if (getBoolean(ckXmlParser, "selected")) {

        final CoreParser cp = createParser(defField, analyzer);
        final Query q = cp.parse(new ByteArrayInputStream(queryString.getBytes("UTF-8")));
        return q;
    } else {
        return qp.parse(queryString);
    }
}

From source file:org.tallison.lucene.queryparser.spans.TestQPTestBaseSpanQuery.java

License:Apache License

@Override
public void testDefaultOperator() throws Exception {
    SQPTestingConfig qp = (SQPTestingConfig) getParserConfig(new MockAnalyzer(random()));
    // make sure OR is the default:
    assertEquals(QueryParserBase.OR_OPERATOR, qp.getDefaultOperator());
    setDefaultOperatorAND(qp);// w ww . j a  v  a  2  s  . c o  m
    assertEquals(QueryParserBase.AND_OPERATOR, qp.getDefaultOperator());
    setDefaultOperatorOR(qp);
    assertEquals(QueryParserBase.OR_OPERATOR, qp.getDefaultOperator());

}

From source file:org.tallison.lucene.queryparser.spans.TestQPTestBaseSpanQuery.java

License:Apache License

public CommonQueryParserConfiguration getParserConfig(Analyzer a, Analyzer mtAnalyzer) throws Exception {
    if (a == null) {
        a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
    }//from  w  w w  .j a va  2  s  .com
    if (mtAnalyzer == null) {
        mtAnalyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, true);
    }

    SQPTestingConfig qp = new SQPTestingConfig(getDefaultField(), a, mtAnalyzer);
    qp.setDefaultOperator(QueryParserBase.OR_OPERATOR);
    qp.setAnalyzeRangeTerms(true);
    return qp;
}