0
votes

Currently I'm facing a problem in multi-word synonym in Solr. So I thought up a solution step:

Step:

  1. Solr plugin intercept the search keyword.
  2. Plugin will get the list of acronym, synonym etc from database table
  3. Plugin will compare the search keyword one by one from the synonym list that extract just now at 2
  4. If exist, the search keyword will convert into the synonym word.
  5. Depends on the result, plugin will decide which fieldtype/filter/tokenizer to put into 6 parameter.
  6. Plugin will return (keyword, which field to search into, which analyzer to use) for Solr to search.

The questions:

  1. can plugin intercept the search keyword so that it can be processed in plugin?
  2. can I access and get records directly from DB in Solr plugin?
  3. can plugin tell Solr what to search, search on which field and use what filter/tokenizer to search? Or can plugin straight away do searching within plugin and pop out the result?

Thank you.

2

2 Answers

0
votes

You might want to take a look al Nolan Lawson's multi word synonym solution.

https://github.com/healthonnet/hon-lucene-synonyms

0
votes

Yes. here is an example how to do that by writing your own SearchComponent.

in solrconfig.xml

 <requestHandler name="/myHandler" class="solr.SearchHandler">
     <arr name="first-components">
         <str>myComponent</str>
     </arr>
 </requestHandler>

 <searchComponent name="myComponent" class="com.xyz.MyComponent" />

.

 public class MyConponent extends SearchComponent {
     ....

     @Override
     public void prepare(ResponseBuilder rb) throws IOException {
         String originalQuery = rb.getQueryString(); //get the original query string

         // access to DB and get records here
         // then construct a new query string and set to rb.

         rb.setQueryString(newQueryString);
     }
 }

Use "/myHandler" instead of "/select" for getting the results.