【发布时间】: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
}
【问题讨论】: