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 Nicholas Ding <ni...@gmail.com> on 2012/10/17 17:24:37 UTC

How to do exact match?

Hello,

I want to do exact match on Solr. I found two ways on Internet, one is to
put PREFIX and SUFFIX around the text, another is to use KeywordTokenizer.

I was wondering which one is the better approach for doing exact match?

Thanks
Nicholas

Re: How to do exact match?

Posted by Jack Krupansky <ja...@basetechnology.com>.
You can use a "stemmer" to match very similar words, such as plurals.

See:
http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#Stemming

Look at the "text_en" field type in the example schema.

-- Jack Krupansky

-----Original Message----- 
From: Nicholas Ding
Sent: Wednesday, October 17, 2012 1:25 PM
To: solr-user@lucene.apache.org
Subject: Re: How to do exact match?

Hi,

I have several tokens in a field containing more than one keyword, like
"chinese food", "indian food", I want to do exact match.
And even more, if the token is "chinese cuisine", but the query is
""chinese cuisines", I still want the query to match to token.

Thanks
Nicholas

On Wed, Oct 17, 2012 at 11:46 AM, Jack Krupansky 
<ja...@basetechnology.com>wrote:

> The answer is "Yes." Solr and Lucene are quite flexible.
>
> You neglected to offer any details about your specific use case which
> might bias the answer one way or the other. What is some sample data and
> some sample queries?
>
> -- Jack Krupansky
>
> -----Original Message----- From: Nicholas Ding
> Sent: Wednesday, October 17, 2012 11:24 AM
> To: solr-user@lucene.apache.org
> Subject: How to do exact match?
>
>
> Hello,
>
> I want to do exact match on Solr. I found two ways on Internet, one is to
> put PREFIX and SUFFIX around the text, another is to use KeywordTokenizer.
>
> I was wondering which one is the better approach for doing exact match?
>
> Thanks
> Nicholas
> 


Re: How to do exact match?

Posted by Chris Hostetter <ho...@fucit.org>.
: I can put "chinese cuisines" and "chinese cuisine" as two different tokens.
: But I was wondering if there is better way to do it, like tweaking
: different FilterFactory.
: 
: My problem is, if it's not exact match, when I search "cuisine", that would
: match both, I don't want that happen.

this is where lots of specifics matter...

it sounds like what *you* mean by "exact match" is...

 * i want to be able to use analayzers that do stemming (and maybe 
lowercasing, and maybe stopwords, and maybe synonyms)
 * i want queries to match documents only if all of the query words are in 
the doc field in order
 * i only want documents to match if there are no other words in the 
doc field besides the words in the query.

does that sound about right?

If so, then KeywordTokenizer isn't going to help you.

i think the simplest way to do what you want is what you alluded to about 
inserting marker tokens at the begining and end of your field values when 
indexing, and then do "phrase queries" that include those marker tokens.

you could probably use something like PatternReplaceCharFilter to inject 
the start/end tokens fairly easily in both our index & query analyzer -- 
just make sure you don't pick something that would get removed by another 
tokenfilter later.

once you have that in place, using something like the "FieldQParser" may 
be the easiest way to generate the phrase queries...

   q={!field f=name}chinese cuisine&debugQuery=true


-Hoss

Re: How to do exact match?

Posted by Nicholas Ding <ni...@gmail.com>.
I can put "chinese cuisines" and "chinese cuisine" as two different tokens.
But I was wondering if there is better way to do it, like tweaking
different FilterFactory.

My problem is, if it's not exact match, when I search "cuisine", that would
match both, I don't want that happen.

Thanks
Shunjia

On Wed, Oct 17, 2012 at 1:28 PM, Otis Gospodnetic <
otis.gospodnetic@gmail.com> wrote:

> Hi,
>
> Aren't you contradicting yourself a bit here?
> You say you want exact matching, but then you say you want a query for
> "chinese cuisines" to match "chinese cuisine", which is not exact.
>
> Otis
> --
> Search Analytics - http://sematext.com/search-analytics/index.html
> Performance Monitoring - http://sematext.com/spm/index.html
>
>
> On Wed, Oct 17, 2012 at 1:25 PM, Nicholas Ding <ni...@gmail.com>
> wrote:
> > Hi,
> >
> > I have several tokens in a field containing more than one keyword, like
> > "chinese food", "indian food", I want to do exact match.
> > And even more, if the token is "chinese cuisine", but the query is
> > ""chinese cuisines", I still want the query to match to token.
> >
> > Thanks
> > Nicholas
> >
> > On Wed, Oct 17, 2012 at 11:46 AM, Jack Krupansky <
> jack@basetechnology.com>wrote:
> >
> >> The answer is "Yes." Solr and Lucene are quite flexible.
> >>
> >> You neglected to offer any details about your specific use case which
> >> might bias the answer one way or the other. What is some sample data and
> >> some sample queries?
> >>
> >> -- Jack Krupansky
> >>
> >> -----Original Message----- From: Nicholas Ding
> >> Sent: Wednesday, October 17, 2012 11:24 AM
> >> To: solr-user@lucene.apache.org
> >> Subject: How to do exact match?
> >>
> >>
> >> Hello,
> >>
> >> I want to do exact match on Solr. I found two ways on Internet, one is
> to
> >> put PREFIX and SUFFIX around the text, another is to use
> KeywordTokenizer.
> >>
> >> I was wondering which one is the better approach for doing exact match?
> >>
> >> Thanks
> >> Nicholas
> >>
>

Re: How to do exact match?

Posted by Otis Gospodnetic <ot...@gmail.com>.
Hi,

Aren't you contradicting yourself a bit here?
You say you want exact matching, but then you say you want a query for
"chinese cuisines" to match "chinese cuisine", which is not exact.

Otis
--
Search Analytics - http://sematext.com/search-analytics/index.html
Performance Monitoring - http://sematext.com/spm/index.html


On Wed, Oct 17, 2012 at 1:25 PM, Nicholas Ding <ni...@gmail.com> wrote:
> Hi,
>
> I have several tokens in a field containing more than one keyword, like
> "chinese food", "indian food", I want to do exact match.
> And even more, if the token is "chinese cuisine", but the query is
> ""chinese cuisines", I still want the query to match to token.
>
> Thanks
> Nicholas
>
> On Wed, Oct 17, 2012 at 11:46 AM, Jack Krupansky <ja...@basetechnology.com>wrote:
>
>> The answer is "Yes." Solr and Lucene are quite flexible.
>>
>> You neglected to offer any details about your specific use case which
>> might bias the answer one way or the other. What is some sample data and
>> some sample queries?
>>
>> -- Jack Krupansky
>>
>> -----Original Message----- From: Nicholas Ding
>> Sent: Wednesday, October 17, 2012 11:24 AM
>> To: solr-user@lucene.apache.org
>> Subject: How to do exact match?
>>
>>
>> Hello,
>>
>> I want to do exact match on Solr. I found two ways on Internet, one is to
>> put PREFIX and SUFFIX around the text, another is to use KeywordTokenizer.
>>
>> I was wondering which one is the better approach for doing exact match?
>>
>> Thanks
>> Nicholas
>>

Re: How to do exact match?

Posted by Nicholas Ding <ni...@gmail.com>.
Hi,

I have several tokens in a field containing more than one keyword, like
"chinese food", "indian food", I want to do exact match.
And even more, if the token is "chinese cuisine", but the query is
""chinese cuisines", I still want the query to match to token.

Thanks
Nicholas

On Wed, Oct 17, 2012 at 11:46 AM, Jack Krupansky <ja...@basetechnology.com>wrote:

> The answer is "Yes." Solr and Lucene are quite flexible.
>
> You neglected to offer any details about your specific use case which
> might bias the answer one way or the other. What is some sample data and
> some sample queries?
>
> -- Jack Krupansky
>
> -----Original Message----- From: Nicholas Ding
> Sent: Wednesday, October 17, 2012 11:24 AM
> To: solr-user@lucene.apache.org
> Subject: How to do exact match?
>
>
> Hello,
>
> I want to do exact match on Solr. I found two ways on Internet, one is to
> put PREFIX and SUFFIX around the text, another is to use KeywordTokenizer.
>
> I was wondering which one is the better approach for doing exact match?
>
> Thanks
> Nicholas
>

Re: How to do exact match?

Posted by Jack Krupansky <ja...@basetechnology.com>.
The answer is "Yes." Solr and Lucene are quite flexible.

You neglected to offer any details about your specific use case which might 
bias the answer one way or the other. What is some sample data and some 
sample queries?

-- Jack Krupansky

-----Original Message----- 
From: Nicholas Ding
Sent: Wednesday, October 17, 2012 11:24 AM
To: solr-user@lucene.apache.org
Subject: How to do exact match?

Hello,

I want to do exact match on Solr. I found two ways on Internet, one is to
put PREFIX and SUFFIX around the text, another is to use KeywordTokenizer.

I was wondering which one is the better approach for doing exact match?

Thanks
Nicholas