更复杂的想法是更新 solr 索引,不仅跟踪用户选择,还跟踪用于获取列表的搜索词。
首先,我们必须定义一个历史字段来存储所使用的搜索词:
<field name="searchHistory" type="text_general" stored="true" indexed="true" multiValued="true"/>
然后我们假设用户搜索了“某物”并从结果列表中选择了 id 为1234的文档。webapp 将在 url 调用 solr 实例
http://mysolrappserver/solr/update?commit=true
向字段 searchHistory 添加新值
<add>
<doc>
<field name="id">**1234**</field>
<field name="searchHistory" update="add">**something**</field>
</doc>
</add>
最后,在每个后续查询中使用 solr termfreq 函数,我们将获得一个 'score',结合 'boost' 字段可以生成基于点击计数流行度(和搜索词历史)的排序列表。