You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Mirko <id...@googlemail.com> on 2013/11/20 18:18:35 UTC

Suggester - how to return exact match?

Hi,
we implemented a Solr suggester (http://wiki.apache.org/solr/Suggester)
that uses a file based dictionary. We use the results of the suggester to
populate a dropdown field of a search field on a webpage.

Our dictionary (autosuggest.txt) contains:

foo
bar

Our suggester has the following behavior:

We can make a request with the search query "fo" and get a response with
the suggestion "foo". This is great.

However, if we make a request with the query "foo" (an exact match) we get
no suggestions. We would expect that the response returns the suggestion
"foo".

How can we configure the suggester to return also the perfect match as a
suggestion?

This is the config for our search component:

<searchComponent class="solr.SpellCheckComponent" name="suggest">
    <str name="queryAnalyzerFieldType">spellCheck</str>
    <lst name="spellchecker">
      <str name="name">default</str>
      <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
     <str name="sourceLocation">autosuggest.txt</str>
    </lst>
  </searchComponent>

Thanks for help!
Mirko

Re: Suggester - how to return exact match?

Posted by Mirko <id...@googlemail.com>.
Thanks! We solved this issue in the front-end now. I.e. we add the exact
match to the list of suggestions there.

Mirko


2013/11/22 Developer <bb...@gmail.com>

> Might not be a perfect solution but you can use edgengram filter and copy
> all
> your field data to that field and use it for suggestion.
>
> <fieldType name="text_autocomplete" class="solr.TextField"
> positionIncrementGap="100">
>   <analyzer type="index">
>     <tokenizer class="solr.WhitespaceTokenizerFactory"/>
>     <filter class="solr.LowerCaseFilterFactory"/>
>     <filter class="solr.EdgeNGramFilterFactory" minGramSize="1"
> maxGramSize="250" />
>   </analyzer>
>   <analyzer type="query">
>     <tokenizer class="solr.WhitespaceTokenizerFactory"/>
>     <filter class="solr.LowerCaseFilterFactory"/>
>   </analyzer>
> </fieldType>
>
> http://localhost:8983/solr/core1/select?q=name:iphone
>
> The above query will return
> iphone
> iphone5c
> iphone4g
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Suggester-how-to-return-exact-match-tp4102203p4102521.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Suggester - how to return exact match?

Posted by Developer <bb...@gmail.com>.
Might not be a perfect solution but you can use edgengram filter and copy all
your field data to that field and use it for suggestion.

<fieldType name="text_autocomplete" class="solr.TextField"
positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1"
maxGramSize="250" />
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

http://localhost:8983/solr/core1/select?q=name:iphone

The above query will return 
iphone
iphone5c
iphone4g



--
View this message in context: http://lucene.472066.n3.nabble.com/Suggester-how-to-return-exact-match-tp4102203p4102521.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Suggester - how to return exact match?

Posted by Mirko <id...@googlemail.com>.
Hi,
I'd like to clarify our use case a bit more.

We want to return the exact search query as a suggestion only if it is
present in the index. So in my example we would expect to get the
suggestion "foo" for the query "foo" but no suggestion "abc" for the query
"abc" (because "abc" is not in the dictionary).

For me this use case seems quite common. Say, we have three products in our
store: "foo", "foo 1", "foo 2". If the user types "foo" in the product
search, we want to suggest all our products in the dropdown.

Is this something we can do with the Solr suggester?
Mirko


2013/11/20 Developer <bb...@gmail.com>

> May be there is a way to do this but it doesn't make sense to return the
> same
> search query as a suggestion (Search query is not a suggestion as it might
> or might not be present in the index).
>
> AFAIK you can use various look up algorithm to get the suggestion list and
> they lookup the terms based on the query value (some alogrithm implements
> fuzzy logic too). so searching Foo will return FooBar, Foo2 but not foo.
>
> You should fetch the suggestion only if the numfound is greater than 0 else
> you don't have any suggestion.
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Suggester-how-to-return-exact-match-tp4102203p4102259.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Suggester - how to return exact match?

Posted by Developer <bb...@gmail.com>.
May be there is a way to do this but it doesn't make sense to return the same
search query as a suggestion (Search query is not a suggestion as it might
or might not be present in the index).

AFAIK you can use various look up algorithm to get the suggestion list and
they lookup the terms based on the query value (some alogrithm implements
fuzzy logic too). so searching Foo will return FooBar, Foo2 but not foo.

You should fetch the suggestion only if the numfound is greater than 0 else
you don't have any suggestion.




--
View this message in context: http://lucene.472066.n3.nabble.com/Suggester-how-to-return-exact-match-tp4102203p4102259.html
Sent from the Solr - User mailing list archive at Nabble.com.