Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i add wild card to query text in solr search

I want that if someone search for phan then elephant Should match.

Now i have value:*phan* then it works so i tried this

<analyzer type="query">
    <filter class="solr.PatternReplaceFilterFactory" pattern="(.+)" replacement="*$1*" replace="all" />

But then its making the query as "*phan*" as single field not wilcard

how can i do that

like image 470
user3113427 Avatar asked Dec 09 '25 19:12

user3113427


1 Answers

To make Solr find documents for word parts, you need to have a look at the NGramTokenizer or the Edge NGramTokenizer. As you are required to match parts of the word within the middle of it, you should have a look at the NGramTokenizer. If the start and end of the word would do, the EdgeNGram would be favourable, as it is smaller in index terms.

A good sample is found here on SO within the question Apache solr search part of the word.

Why Indexing over query time?

Lucene and as such Solr are not meant to do searches with leading wildcards. So even search for *foo is likely to cause bad performance. Not to mention *foo*. You can read this up in the FAQs 'What wildcard search support is available from Lucene?'

Leading wildcards (e.g. *ook) are not supported by the QueryParser by default. As of Lucene 2.1, they can be enabled by calling QueryParser.setAllowLeadingWildcard( true ). Note that this can be an expensive operation: it requires scanning the list of tokens in the index in its entirety to look for those that match the pattern.

In the SO question Understanding Lucene leading wildcard performance is a more detailed write up on this topic.

like image 182
cheffe Avatar answered Dec 12 '25 09:12

cheffe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!