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