Example usage for org.apache.solr.search QueryParsing OP

List of usage examples for org.apache.solr.search QueryParsing OP

Introduction

In this page you can find the example usage for org.apache.solr.search QueryParsing OP.

Prototype

String OP

To view the source code for org.apache.solr.search QueryParsing OP.

Click Source Link

Usage

From source file:com.memonews.solr.search.HighlightQParserPlugin.java

License:Apache License

@Override
public Query parse() throws ParseException {

    String qstr = getString();//from w  w w. j av  a2 s  .  c o m
    if (qstr == null) {
        return null;
    }

    String defaultField = getParam(CommonParams.DF);
    if (defaultField == null) {
        defaultField = getReq().getSchema().getDefaultSearchFieldName();
    }

    HighlightQueryParserNew parser = new HighlightQueryParserNew(this, defaultField, this.fieldNames);

    parser.setDefaultOperator(
            QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP)));

    Query q = parser.parse(qstr);
    return q;
}

From source file:com.sindicetech.siren.solr.qparser.SirenQParser.java

License:Open Source License

protected Operator getDefaultOperator() {
    final String val = params.get(QueryParsing.OP);
    Operator defaultOp = Operator.AND; // default AND operator
    if (val != null) {
        defaultOp = "AND".equals(val) ? Operator.AND : Operator.OR;
    }/*w  w  w. ja v  a  2s.  c  o m*/
    return defaultOp;
}

From source file:com.sindicetech.siren.solr.qparser.TestDefaultOperator.java

License:Open Source License

@Test
public void testQOpParameter() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb ccc\" }");
    this.addJsonString("2", "{ \"aaa\" : \"bbb\" }");
    this.addJsonString("3", "{ \"aaa\" : \"ccc\" }");

    SolrQuery query = new SolrQuery();
    query.setQuery("bbb ccc");
    query.setRequestHandler("keyword");
    query.set(QueryParsing.OP, "OR");
    String[] results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);/*from ww  w .j av a 2  s.  com*/

    query = new SolrQuery();
    query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }");
    query.setRequestHandler("tree");
    query.set(QueryParsing.OP, "OR");
    results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);
}

From source file:elhuyar.bilakit.PayloadQParserPlugin.java

License:Open Source License

@Override
public Query parse() throws SyntaxError {
    String qstr = getString();/*from   www.  ja va  2 s . c  o m*/
    if (qstr == null || qstr.length() == 0)
        return null;
    String defaultField = getParam(CommonParams.DF);
    if (defaultField == null) {
        defaultField = getReq().getSchema().getDefaultSearchFieldName();
    }
    pqParser = new PayloadQueryParser(this, defaultField);
    pqParser.setDefaultOperator(
            QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP)));

    return pqParser.parse(qstr);
}

From source file:org.apache.lucene.payload.dwarf.PayloadQParser.java

License:Apache License

@Override
public Query parse() throws SyntaxError {
    String qstr = getString();//from www. j a  v  a2  s .  com
    if (qstr == null || qstr.length() == 0)
        return null;

    String defaultField = getParam(CommonParams.DF);
    if (defaultField == null) {
        defaultField = getReq().getSchema().getDefaultSearchFieldName();
    }
    pqParser = new PayloadQueryParser(this, defaultField);

    pqParser.setDefaultOperator(
            QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP)));

    return pqParser.parse(qstr);
}

From source file:org.codice.solr.xpath.XpathQParser.java

License:Open Source License

@Override
public Query parse() throws SyntaxError {
    String qstr = getString();// w ww. j  ava  2 s .  c o m

    String defaultField = getParam(CommonParams.DF);
    if (defaultField == null) {
        defaultField = getReq().getSchema().getDefaultSearchFieldName();
    }

    XpathQueryParser queryParser = new XpathQueryParser(this, defaultField);

    queryParser.setDefaultOperator(
            QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP)));

    return queryParser.parse(qstr);
}

From source file:org.sindice.siren.solr.qparser.TestDefaultOperator.java

License:Apache License

@Test
public void testQOpParameter() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb ccc\" }");
    this.addJsonString("2", "{ \"aaa\" : \"bbb\" }");
    this.addJsonString("3", "{ \"aaa\" : \"ccc\" }");

    SolrQuery query = new SolrQuery();
    query.setQuery("bbb ccc");
    query.setRequestHandler("keyword");
    query.set(QueryParsing.OP, "OR");
    String[] results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);/* w  ww.  j  a  va  2s .  c o  m*/

    query = new SolrQuery();
    query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }");
    query.setRequestHandler("json");
    query.set(QueryParsing.OP, "OR");
    results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);
}

From source file:org.tallison.solr.search.SpanQParser.java

License:Apache License

public SpanQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    super(qstr, localParams, params, req);
    IndexSchema schema = req.getSchema();

    //now set the params
    SolrParams comboParams = SolrParams.wrapDefaults(localParams, params);

    //preamble to initializing the parser
    Analyzer analyzer = schema.getQueryAnalyzer(); //default analyzer?

    defaultFieldName = getParam(CommonParams.DF);

    if (defaultFieldName != null) {
        SchemaField sf = schema.getField(defaultFieldName);
        if (sf != null && sf.getType() != null) {
            analyzer = sf.getType().getQueryAnalyzer();
        }/*from w ww .j a va2s .c o  m*/
    }

    //initialize the parser
    parser = new SolrSpanQueryParser(defaultFieldName, analyzer, schema, this);

    parser.setAllowLeadingWildcard(comboParams.getBool(ALLOW_LEADING_WILDCARD, true));

    parser.setAutoGeneratePhraseQueries(comboParams.getBool(AUTO_GENERATE_PHRASE, false));

    org.apache.lucene.queryparser.classic.QueryParser.Operator defaultOp = DEFAULT_OPERATOR;
    String defaultOpString = comboParams.get(QueryParsing.OP);
    if (defaultOpString != null) {
        if (defaultOpString.equalsIgnoreCase("and")) {
            defaultOp = org.apache.lucene.queryparser.classic.QueryParser.Operator.AND;
        }
    }

    parser.setDefaultOperator(defaultOp);

    parser.setFuzzyMaxEdits(comboParams.getInt(MAX_FUZZY_EDITS, 2));
    parser.setFuzzyPrefixLength(comboParams.getInt(PREFIX_LENGTH, 0));
    parser.setPhraseSlop(comboParams.getInt(PHRASE_SLOP, 0));
    parser.setSpanNearMaxDistance(comboParams.getInt(NEAR_MAX, -1));
    parser.setSpanNotNearMaxDistance(comboParams.getInt(NOT_NEAR_MAX, -1));

}