简体   繁体   中英

Use termfreq(field,term) function for phrase with space in SOLR 4.1

I am using termfreq(field,term) SOLR function . This works:

?fl=product_name,termfreq(product_name,"iphon")&q=iphone 4s     //Found freq

But the problem is to have term like "iphone 4s" with space

?fl=product_name,termfreq(product_name,"iphon 4s")&q=iphone 4s  //Return 0 freq

Return 0 freq although that term(phrase) exist in doc. So, the question is, can I use termfreq() function with full phrase like "iphone 4s", And how?

I am using SOLR 4.1. and analyzer for field is

<fieldType name="text_ws" class="solr.TextField">
    <analyzer>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

Field is

<field name="product_name" type="text_ws" indexed="true" stored="true"/>

As you are using a WhitespaceTokenizerFactory the term iphone 4s would not exist as a term.
You could use KeywordTokenizerFactory for indexing, which doesn't tokenize the words and the phrase should be available.
Else you can check for shingle options which would group words for you.

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