0

我正在尝试将 java 字符串传递给 Apache StandardQueryparser 以获取 Querynode。

输入 -"fq=section:1"

我只需要 QueryNode 的 FILTER 子句中的 section:1。这看起来很简单,但它抛出

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

4

1 回答 1

1

使用ConstantScoreQuery。它不会影响它的分数,并且与Solr 中实现的参数相同fq

  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);
  }
于 2019-12-15T13:06:26.320 回答