简体   繁体   中英

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

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?

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 eg (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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM