Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search in Solr with EdgeNGramFilterFactory and min length of the search query

Tags:

search

solr

in my solr schema file i have a default search field which uses EdgeNGramFilterFactory

<filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" side="front" />

assumed that my search query is

tes

so I get results like that:

tess
test
tesla
...

if I search for

test

I get results like

test
tess
tesla
...

Its ok because I use EdgeNGramFilterFactory with minGramSize=3 but I want the following:

When I search for a string which length is more than 3 characters (for example test) I want that solr ignore all the terms which consists of 3 characters (EdgeNGramFilterFactory). When I search for "test" i don't want to get results like "tess" or "tesla". I wont get Results which begin with test (4 characters) like

test
test for
test-drive
...

Is it possible to configure that in solr?

like image 763
user180627 Avatar asked Mar 05 '12 16:03

user180627


1 Answers

You may configure the EdgeNGram filter in the field's index analyzer only; for query analyzer, still do regular tokenization w/o any EdgeNGram. So that when you search "test", only results prefixed with exact "test" will be returned.

config e.g. (don't define EdgeNGram for query analyzer)

<fieldType name=...>
    <analyzer type="index">
        ...
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="4" maxGramSize="15" side="front" />
    </analyzer>
    <analyzer type="query">
        ...
        <!-- <filter class="solr.EdgeNGramFilterFactory" minGramSize="4" maxGramSize="15" side="front" /> -->
    </analyzer>
</fieldType>
like image 91
Yinan Avatar answered Oct 10 '22 00:10

Yinan