0

We are implementing a search function using Solr as the backend engine. The data is extracted from the database using DIH. Key information of the document including:

- product number  (number) 
- product name    (name) 
- applicant name (applicant) 
- product purpose (purpose)

All fields are stored and indexed.

We provide a single search box for the users to type any number of keywords and the system will search across all fields and try to match all of them. To do that, we create additional field that combine all information above using "copyField".

However, another requirement is that the user would be able to limit their search in selected target fields. For example, the user could select only name and purpose fields. In this case, the keywords search will only search from these two fields.

Currently, we use the following query approach to achieve the function:

For example, given that

- the user provide keywords: K1 and K2, 
- and the user want to search on name, applicant and purpose only, 

the following search string will be dynamically generated and sent to Solr:

(name:K1 OR applicant:K1 OR purpose:K1) AND (name:K2 OR applicant:K2 OR purpose:K2)

Are there any other way to implement the function? It would be much appreciated if you could share your expertise.

Thanks, Fan

4

1 回答 1

0

您可以使用edismax和默认配置检查请求处理程序,该配置qf将搜索包含所有字段数据的复制字段。

qf 将在其上执行查询的查询字段。

您只需将一个参数传递给 solrqt=edismax&q=K1 K2进行搜索。

<requestHandler name="edismax" class="solr.SearchHandler" >
    <lst name="defaults">
        <str name="defType">edismax</str>
        <str name="qf">
            all_fields
        </str>
        <str name="fl">
            *,score
        </str>
        <str name="q.alt">*:*</str>
    </lst>   
</requestHandler>

如果用户想要搜索名称或目的,我建议只将字段和查询传递给这个请求处理程序。
传递的参数将覆盖默认参数。

您只需将一个参数传递给 solrqt=edismax&q=K1 K2&qf=name applicant 进行搜索。

您可以使用 mm(最小匹配)参数控制 OR 行为。

于 2013-07-08T13:13:02.970 回答