Question

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

Was it helpful?

Solution

you can check for Request handler with edismax and with default configuration qf which would search on the copyfield which holds data from all the fields.

qf query field on which the query would be executed.

You would just need to pass a single param to solr qt=edismax&q=K1 K2 for search.

<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>

If the user wants to search on name or purpose, i would suggest just passing the fields and the query to this request handler.
The parameters passed would override the default parameters.

You would just need to pass a single param to solr qt=edismax&q=K1 K2&qf=name applicant for search.

You can control the OR behaviour using the mm (minimum match) parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top