How to partially search a word in solr

Posted By : Shiv Kumar | 30-Dec-2015

I have faced an issue while implementing searching using solr.

I have to search for partial word and its working fine for single word or multiple words but creates an issue in a specific scenario :

When I seached for

"shiv" ---- working fine
"shiv kumar" --- working fine
"shiv kum" --- working fine
"shiv k"  -- failed here

 

The issue is not with my code but with tokenizer(StandardTokenizerFactory) solr configuration in schema.xml.

In schema.xml, StandardTokenizerFactory has a filter EdgeNGramFilterFactory configured in different way like :

<filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="30" side="front" luceneMatchVersion="4.3"/>

 

It means it will create n-gram for the input starting from front edge and grouping element in pair of two and more and upto 30.

minGramSize plays an importatnt role here and specifies the minimum numbers of characters for grouping. You can understand this by example :

The above configuration will give the following output for the word "higher" :
 higher ---> "hi", "hig", "high", highe", "higher"

By putting minGramSize ="1" solved my problem as it gives the following output:
 higher ---> "h", "hi", "hig", "high", highe", "higher"

 

In earlier configuration there was grouping of 2 that is why "shiv k" case was failing because no combination was there for single "k".

Setting minGramSize to 1, search for single "k" also works and solved the issue.

Hope this will surely help you.

Thanks

About Author

Author Image
Shiv Kumar

Shiv is an experienced Java Developer with a strong background in multiple technologies. He specializes in defining system architectures to ensure reliable and resilient solutions. He possesses a comprehensive understanding of the latest technologies and has hands-on experience in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases like MySQL and PostgreSQL, and non-relational databases like MongoDB. He excels in API implementations, Microservices, Web Services development, testing, and deployments. Shiv actively contributes to code enhancements and consistently delivers valuable contributions to various client projects, including Fabtrack, Pando, Pandojo, Digikam, WhatsApp Integration, Croniz, Punchin Application, Script TV, Bhaasha, and more. He demonstrates strong analytical skills and a creative mindset. In addition, he has a passion for reading books and exploring new technologies and innovations.

Request for Proposal

Name is required

Comment is required

Sending message..