lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Rochkind <>
Subject Re: Exact match
Date Tue, 17 May 2011 15:27:32 GMT
You've got to change the fields to do it.

If you use a String field, then only exact matches will match, but 
they'll be REALLY exact matches -- spacing, punctuation, etc.

Also, if you are using the lucene or dismax query parsers, you'll need 
to phrase quote your query if it has any spaces in it, to avoid query 
parser pre-tokenization.  (I call it 'pre-tokenization', not sure what 
Solr calls it).

So you could use a textfield with the keyword tokenizer (does not split 
on word boundaries), and apply some punctuation/spacing normalization, 
to make your match a little bit less 'exact' if desired. You'd still 
need to issue your query as phrase quoted if it contains any spaces, to 
the lucene or dismax query parsers. Or use a different query parser, 
like "field" or "raw" or that new one I can't remember the name of.

Another idea I've had for exact matching, but haven't tried out myself 
yet:  Use a text/analyzed field, WITH tokenization, but manually add a 
token such as "THE_START" to the start of the field before indexing, and 
"THE_END" to the end of the field before indexing. Then when you do a 
query, phrase quote it AND manually add those tokens before issuing the 
query. So if the user entered "quick brown fix", you'd actually send a 
search for (phrase quoted) "THE_START quick brown fox THE_END".  That 
would hypothetically be another way of getting an 'exact' match (with 
whatever normalization the field's analysis does), in a field that could 
also be used for 'ordinary' searching.  Haven't tried it myself yet.  
Those extra tokens might (or might not) alter Solr's relevancy scores 


On 5/17/2011 9:51 AM, Alex Grilo wrote:
> Hi,
> Can I make a query that returns only exact match or do I have to change the
> fields to achieve that?
> Thanks in advance
> Alex Grilo

View raw message