0

I am trying to pass a java String to Apache StandardQueryparser to get the Querynode.

Input - "fq=section:1"

All I need is section:1 in FILTER clause in QueryNode. This looks pretty straightforward but it throws

INVALID_SYNTAX_CANNOT_PARSE: Syntax Error, cannot parse fq=section:1:

3
  • 1
    Are you trying to send fq=section:1 as the input to a query parser directly in Lucene? fq is Solr syntax, it's not directly related to Lucene. Add your actual code and what you're trying to do - if you just want to add an extra condition for section:1, you can add ` AND section:1` to your query, To replicate the fq behavior to not affect score, use a ConstantScoreQuery. Commented Dec 13, 2019 at 22:07
  • I have a condition like (name: abc OR name: xyz) AND id:(1 2 3 ). I pass this to StandardQueryParser and it parses to 2 bool queries. Bool query 1 is a "should" clause for the OR condition above. The second bool query also gets translated to a "should" clause for id part of it. But what I want to do is "filter" for id query not "should" as "filter" performs better than "should" Commented Dec 15, 2019 at 3:25
  • You can accept the answer or tell us what is missing for you to go further. Commented Dec 19, 2019 at 8:59

1 Answer 1

1

Use a ConstantScoreQuery. It won't affect it score, and is the same was as the fq parameter is implemented in Solr:

  public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
    // SolrRequestInfo reqInfo = SolrRequestInfo.getRequestInfo();

    if (!(searcher instanceof SolrIndexSearcher)) {
      // delete-by-query won't have SolrIndexSearcher
      return new BoostQuery(new ConstantScoreQuery(q), 0).createWeight(searcher, scoreMode, 1f);
    }

    SolrIndexSearcher solrSearcher = (SolrIndexSearcher)searcher;
    DocSet docs = solrSearcher.getDocSet(q);
    // reqInfo.addCloseHook(docs);  // needed for off-heap refcounting

    return new BoostQuery(new SolrConstantScoreQuery(docs.getTopFilter()), 0).createWeight(searcher, scoreMode, 1f);
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.