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:

dj308
  • 47
  • 3
  • 6
  • 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`. – MatsLindh Dec 13 '19 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" – dj308 Dec 15 '19 at 03:25
  • You can accept the answer or tell us what is missing for you to go further. – EricLavault Dec 19 '19 at 08:59

1 Answers1

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);
  }
MatsLindh
  • 49,529
  • 4
  • 53
  • 84