lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason St. Louis" <jason.stlo...@gravitybound.net>
Subject Re: Question on how to build a query
Date Sun, 20 Jun 2004 00:42:26 GMT


Erik Hatcher wrote:

> On Jun 19, 2004, at 1:51 AM, Jason St. Louis wrote:
> 
>> I wrote my indexer so that it added each field without tokenizing it:
>>
>> Field fnameField = new Field("fname", fname.toLowerCase(), true, true, 
>> false);
>> Field lnameField = new Field("lname", lname.toLowerCase(), true, true, 
>> false);
>> Field cityField = new Field("city", position.toLowerCase(), true, 
>> true, false);
>>
>> By the way, if this is the case, is the indexer even using the 
>> analyzer that I pass to it?
> 
> 
> No.  Tokenized fields are analyzed.  Non-tokenized fields are left 
> as-is.  It might be clearer if you used Field.Keyword instead, which is 
> identical to what you have here.

That's what I figured.  I suppose if I don't want to store the field 
values in the index, I can't use Field.Keyword, though. I just realized 
that I'm storing those 3 fields when I don't need to.  The only field I 
need to store is the primary key of the person in the database (not 
pictured in the above code) which I use to retrieve the full record from 
the database later.

> 
>> Then in my search code I create the firstname query as a WildcardQuery 
>> if the first name is provided (adding a * to the end if it's not 
>> already there):
>>
>> Term fnameTerm = null;
>> Query fnameQuery = null;
>> if( fnameIn.length() > 0)
>> {
>>     if( !fnameIn.endsWith("*") )
>>     {
>>         fnameIn += "*";
>>     }
>>     fnameTerm = new Term("fname", fnameIn);
>>     fnameQuery = new WildcardQuery(fnameTerm);
>> }
> 
> 
> I recommend PrefixQuery in this case.

Excellent.  That actually works much better than the WildcardQuery for 
what I'm trying to do here.

> 
> I presume you lowercased fnameIn?  You should to get it to match what 
> was indexed.

Yes, I did.

> 
>>
>> Does this seem like a reasonable way to approach this problem, or am I 
>> missing something that's going to bite me in the you-know-what?
> 
> 
> Seems reasonable to me as long as you are lowercasing the strings at 
> query time also.
> 
>     Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
> 
> 

Thanks for your response.  I really appreciate it.

Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message