我试图将Java字符串传递给Apache StandardQueryparser以获取Querynode。
输入-"fq=section:1"
我需要的只是QueryNode的FILTER子句中的section:1。这看起来很简单,但是会抛出INVALID_SYNTAX_CANNOT_PARSE: Syntax Error, cannot parse fq=section:1:
最佳答案
使用a ConstantScoreQuery。它不会影响它的得分,而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);
}
关于apache - 语法错误,使用fq(过滤查询)时无法从lucene StandardQueryparser进行解析,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59328945/