lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject RE: Searching for "keyword" fields using QueryParser
Date Thu, 24 Nov 2005 14:55:51 GMT
Excellent, that's exactly what I needed. Many thanks!



-----Original Message-----
From: Erik Hatcher [] 
Sent: 24 November 2005 14:51
Subject: Re: Searching for "keyword" fields using QueryParser


The trick is to use PerFieldAnalyzerWrapper with QueryParser, using  
StandardAnalyzer as the default, and using KeywordAnalyzer for each  
of the fields that should not be analyzed.  KeywordAnalyzer is in the  
trunk of Subversion right now, not in a released version.



It was developed for Lucene in Action also, so it is in that codebase  
which you can download from

Keep in mind that QueryParser may still interfere with keyword fields  
if there are characters in them that are special to the parser, such  
as parenthesis.


On 24 Nov 2005, at 09:09, <>  
<> wrote:

> Hi,
> Our index has a large text field, and a number of "keyword" fields  
> with
> things such as the publication code, article reference and so on.
> We're analysing using the StandardAnalyzer, which works well.  
> Obviously
> the fields which are defined as Field.Keyword don't run through the
> analyzer.
> The problem comes when we search using a QueryParser. If we've  
> inserted
> a field using:
> Field.Keyword("pubcode"."PUB123");
> We then search using
> Query q = QueryParser.parse(query, "text", new StandardAnalyzer());
> When we try to search on something like:
> "pubcode:PUB123" - the analyzer promptly lowercases the search  
> term, and
> we get no hits back.
> Is there any way to explain that where a search term is being applied
> against a field of type Keyword, that it shouldn't be run through the
> analyzer?
> We can get around this by creating separate Query objects and joining
> them with a BooleanQuery, but we were hoping to be able to handle  
> all of
> our queries using QueryParser so that we could easily store queries as
> String objects.
> Cheers,
> Tim.
> **********************************************************************

> **********
> The information contained in this email message may be  
> confidential. If you are not the intended recipient, any use,  
> interference with, disclosure or copying of this material is  
> unauthorised and prohibited. Although this message and any  
> attachments are believed to be free of viruses, no responsibility  
> is accepted by Informa for any loss or damage arising in any way  
> from receipt or use thereof.  Messages to and from the company are  
> monitored for operational reasons and in accordance with lawful  
> business practices.
> If you have received this message in error, please notify us by  
> return and delete the message and any attachments.  Further  
> enquiries/returns can be sent to
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message