在Solr索引记录中,假设我有这个示例记录(例如,JSON):
{
"title":"Innovation Life and Strategy",
"author":"Sarah Howard",
},
{
"title":"Simple Life", <--- This will be ignored
"author":"W. David",
},
{
"title":"Today's Innovations",
"author":"Michael Wayne", <--- This Author will be listed at the top
},
{
"title":"The Innovation Records",
"author":"Tommy Wright",
},
etc ..如何进行Solr查询:
innovation在title字段中过滤
(所以我们在那里有3张唱片)Wayne作者:放在顶部,对结果进行排序。因此,最终的结果应该是:
{
"title":"Today's Innovations",
"author":"Michael Wayne",
},
{
"title":"Innovation Life and Strategy",
"author":"Sarah Howard",
},
{
"title":"The Innovation Records",
"author":"Tommy Chen",
},我只有第一步了,fq=title:*Innovation*
但是我不知道第二步的查询(自定义排序)。
请问怎样才能买到?
发布于 2012-08-10 10:01:26
您可以使用字段增强而不是排序。有关详细信息,请查看http://wiki.apache.org/solr/SolrRelevancyFAQ。
你可能需要这样的东西:
q=title:*&bq=author:Wayne^10&fq=title:*Innovation*这产生了所有在标题中有“创新”的文档,得分与“韦恩”匹配的更高。
确保使用WhitespaceTokenizer (而不是KeywordTokenizer)对"author“进行索引,否则您将无法使用分隔的单词进行搜索(参见http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters)。
发布于 2012-08-10 08:56:14
在这种情况下,我认为这是不可能的,因为作者是一个多值字段,因为有两个值:名和姓。因此,如果您想按姓订购,则必须将该字段分为两个字段: author_first_name、author_surname
您可以在索引时间拆分名称,例如使用数据导入处理程序。
另一个解决方案是用java编写自己的排序算法。
关键是要找出姓氏是什么,因为并不是每个名字都只有两个名字,比如Docotor Tommy Chen或kim jong il --也有两个姓氏组成(尤其是在亚洲)。
我想这才是真正的问题。
https://stackoverflow.com/questions/11897919
复制相似问题