Example usage for org.apache.lucene.queryparser.xml CoreParser parse

List of usage examples for org.apache.lucene.queryparser.xml CoreParser parse

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.xml CoreParser parse.

Prototype

public Query parse(InputStream xmlStream) throws ParserException 

Source Link

Document

Parses the given stream as XML file and returns a Query .

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./* w ww.  j  ava  2s  . c o  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.getopt.luke.Luke.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.
 * @return//from   w  w  w .  j  a  v  a 2s  .co m
 */
public Query createQuery(String queryString) throws Exception {
    Object srchOpts = find("srchOptTabs");
    Analyzer analyzer = createAnalyzer(srchOpts);
    if (analyzer == null) {
        return null;
    }
    String defField = getDefaultField(srchOpts);
    QueryParser qp = new QueryParser(LV, defField, analyzer);
    Object ckXmlParser = find(srchOpts, "ckXmlParser");
    Object ckWild = find(srchOpts, "ckWild");
    Object ckPosIncr = find(srchOpts, "ckPosIncr");
    Object ckLoExp = find(srchOpts, "ckLoExp");
    Object cbDateRes = find(srchOpts, "cbDateRes");
    DateTools.Resolution resolution = Util.getResolution(getString(cbDateRes, "text"));
    Object cbOp = find(srchOpts, "cbOp");
    Object bqMaxCount = find(srchOpts, "bqMaxCount");
    int maxCount = 1024;
    try {
        maxCount = Integer.parseInt(getString(bqMaxCount, "text"));
    } catch (Exception e) {
        e.printStackTrace();
        showStatus("Invalid BooleanQuery max clause count, using default 1024");
    }
    QueryParser.Operator op;
    BooleanQuery.setMaxClauseCount(maxCount);
    String opString = getString(cbOp, "text");
    if (opString.equalsIgnoreCase("OR")) {
        op = QueryParser.OR_OPERATOR;
    } else {
        op = QueryParser.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")) {

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