【问题标题】:Solr with no text search没有文本搜索的 Solr
【发布时间】:2018-02-24 13:01:41
【问题描述】:

我已经通过扩展 CustomScoreProvider 在 solr 中成功实现了自定义搜索。但问题是我需要在自定义排序中传递一些用户信息,例如 31,1。

q={!mycustomparser}31+1+*:*

它充当文本搜索。有什么方法可以让我跳过这个文本搜索,只传递用户信息。

一些代码。

public class MyCustomParserPlugin extends QParserPlugin {

    @Override
    public QParser createParser(String querystring, SolrParams slocParams, SolrParams params, SolrQueryRequest req) {
        return new MyCustomParser(querystring, slocParams, params, req);        
    }

    private static class MyCustomParser extends QParser{

        private Query inQuery;

        public MyCustomParser(String querystring, SolrParams slocParams, SolrParams params, SolrQueryRequest req) {
            super(querystring, slocParams, params, req);
            try {
                QParser parser = getParser(querystring, getReq());
                this.inQuery = parser.parse();
            }catch(SyntaxError ex) {
                throw new RuntimeException("error parsing query", ex);
            }
        }

        @Override
        public Query parse() throws SyntaxError {
            return new MatchingQuery(inQuery);
        }

    }

}

==========================================

public class MatchingQuery extends CustomScoreQuery {

    private Query subQuery;

    public MatchingQuery(Query subQuery) {
        super(subQuery);
        this.subQuery = subQuery;
    }

    @Override
    protected CustomScoreProvider getCustomScoreProvider(LeafReaderContext context) {
        return new MyCustomSortClz(subQuery, context);
    }
}

==========================================

public class MyCustomSortClz extends CustomScoreProvider {

  // ---> my sort
}

【问题讨论】:

    标签: solr solr6


    【解决方案1】:

    您可以使用本地参数来实现 - 在本地参数中传递用户数据并将查询设置为 *:*

    来自 Solr 文档:“本地参数提供了一种将元数据添加到某些参数类型(例如查询字符串)的方法。”

    在您的自定义解析器构造函数中,您可以从 SolrParams slocParams 变量访问这些参数。

    https://lucene.apache.org/solr/guide/6_6/local-parameters-in-queries.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多