lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Searching for "keyword" fields using QueryParser
Date Thu, 24 Nov 2005 14:51:14 GMT
Tim,

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.

	<http://svn.apache.org/repos/asf/lucene/java/trunk/src/java/org/ 
apache/lucene/analysis/KeywordAnalyzer.java>

It was developed for Lucene in Action also, so it is in that codebase  
which you can download from http://www.lucenebook.com

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.

	Erik



On 24 Nov 2005, at 09:09, <Tim.Wright@informa.com>  
<Tim.Wright@informa.com> 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 postmaster@informa.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


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


Mime
View raw message