【发布时间】:2019-11-21 20:23:15
【问题描述】:
我正在尝试使用 Solr 实现我自己的自定义评分功能 - 我希望 Solr 执行 KNearestNeighbor 并返回得分最高的最接近结果。
我一直在关注external-score-to-solr 和using-custom-score-query 这两个实现。
到目前为止我有什么
在我的架构上,我有以下字段:
<field name="histogram" type="payloads" indexed="true" stored="true" />
具有直方图字段数据的文档示例如下:
"bin1|1.23 bin2|-0.24 bin3|-1.89 bin4|5.21"
按照上面的两个链接,我最终扩展了 CustomScoreProvider 类,我的 customScore 函数是:
@Override
public float customScore(int doc, float subQueryScore, float valSrcScores[]) throws IOException {
Document d = context.reader().document(doc);
String histogram = d.get("histogram");
// Here I have a function that splits the string by space and then parse
// each name and value
Map<<String, Float> histogramMap = getDocumentHistogram(histogram);
// A similar function but for the query terms. Can be done only once
// query is the type of org.apache.lucene.search.Query
Map<<String, Float> queryMap = getQueryHistogram(query.toString());
// Trivial function to compute KNN
float score = computeScore(histogramMap, queryMap);
return 1/score;
}
问题
我所做的工作,但正如您在实现中看到的那样,性能很差,因为对于每个查询,我需要在计算分数之前解析特征。我只能解析一次查询词,但我仍然需要解析每个文档的直方图才能计算分数。
那么,有没有办法获取我的 histogram 功能已经在 customScore 函数中解析的 List / Array / Map / 等?这个字段类型是payload,它使用WhitespaceTokenizerFactory分词器,以管道作为分隔符,所以应该有solr返回每个个体的方式条款。
我可以提供有关我所做工作的更多详细信息,并且我正在使用 Solr 6.0.1。
谢谢, 塞尔吉奥
【问题讨论】:
-
您找到解决方案了吗?
标签: solr