简体   繁体   English

Apache SOLR按类别搜索

[英]Apache SOLR search by category

I am using apache-solr-1.4.1 and jdk1.6.0_14. 我正在使用apache-solr-1.4.1和jdk1.6.0_14。

I have the following scenario. 我有以下场景。 I have 3 categories of data indexed in SOLR ie CITIES, STATES, COUNTRIES. 我在SOLR中有三类索引数据,即CITIES,STATES,COUNTRIES。 When I query data from SOLR I need the search result from SOLR based on the following criteria: 当我从SOLR查询数据时,我需要基于以下标准的SOLR搜索结果:

In a single query to SOLR I need data fetched from SOLR grouped by each category with a predefined results count for each category. 在对SOLR的单个查询中,我需要从SOLR获取的数据按每个类别分组,并为每个类别指定预定义的结果计数。

How can I specify this condition in SOLR? 如何在SOLR中指定此条件?

I have tried to use SOLR Field Collapsing feature, but I am not able to get the desired output from SOLR. 我曾尝试使用SOLR Field Collapsing功能,但我无法从SOLR获得所需的输出。

Please suggest. 请建议。

My solution is not exactly what you have asked but is my take on what SOLR does best, which is full text search. 我的解决方案并不完全是你所要求的,但我对SOLR最擅长的是全文搜索。 Instead of grouping the results by "category", I'd suggest you order the results by relevance score but also provide a facet count for the category values. 我不建议按“类别”对结果进行分组,而是建议您按相关性分数对结果进行排序,同时还提供类别值的方面计数。 In my experience users expect a "search" to behave like Google, with the best matches at the top. 根据我的经验,用户希望“搜索”的行为与Google一样,最佳匹配位于顶部。 Deviating form this norm confuses the user in most cases. 在大多数情况下,这种规范的偏差形式会使用户感到困惑。

If you want exactly as you have asked (actual results grouped by category) then you could use a relational database and do a group_by or write a custom function query with SOLR (I cannot advise on this as I've never done it). 如果您想要完全按照您的要求(实际结果按类别分组),那么您可以使用关系数据库并执行group_by或使用SOLR编写自定义函数查询 (我无法就此做出建议,因为我从未这样做过)。

More info: index the data with the appropriate fields, eg name, population, etc. But also add a field called "category", which would have a value of either CITIES, STATES or COUNTRIES. 更多信息:使用适当的字段索引数据,例如名称,人口等。但是还要添加一个名为“category”的字段,其值为CITIES,STATES或COUNTRIES。 Then perform a standard SOLR search, which will return results in order of relevance - ie best matches at the top. 然后执行标准的SOLR搜索,它将按照相关性的顺序返回结果 - 即顶部的最佳匹配。 As part of the request, you can specify a facet.field=category , which will return counts for the search results for each of the given categories (in the "facet" results section). 作为请求的一部分,您可以指定facet.field=category ,它将返回每个给定类别的搜索结果的计数(在“facet”结果部分中)。 In the UI you can then create links for each category facet which performs the original search plus &fq=category:CITIES , etc., thus restricting results to just that category. 然后,您可以在UI中为每个类别构面创建链接,这些链接执行原始搜索以及&fq=category:CITIES等,从而将结果限制为该类别。 See the facetting overview on the SOLR wiki for more info. 有关详细信息,请参阅SOLR wiki上的facetting概述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM