You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by chaiguy1337 <lo...@electricstorm.com> on 2008/12/06 04:14:36 UTC

Problem with spaces in untokenized field using QueryParser

Hi group. I'm having a small problem and couldn't find an obvious explanation
for it anywhere. I'm indexing some textual notes (think sticky notes) via a
standard analyzer. For the most part it's working great, but I'm trying to
implement a tagging feature that allows a note to be tagged with additional
keywords.

Naturally I do this by adding "tag" fields to the document, one field per
tag, each of which is unique. These are stored, untokenized.

I then use the query parser's colon notation to search for notes based on
tags, e.g. tag:"mytag", and that, too, works great except when there is a
space involved in the tag (it returns zero hits in such cases).
Interestingly the tags are still being indexed because I can search for them
normall

So I'm curious as to why a space is having any effect on the query when I'm
storing the field as untokenized? By the way I'm using syntax like this for
all tags, specifically to allow for spaces in the query:

tag:"my tag"

My QueryParser looks like so:
QueryParser qp = new MultiFieldQueryParser( new string[] { "body", "tag",
"title" }, analyzer );

and 'analyzer' is just a StandardAnalyzer. I'm using a MultiFieldQueryParser
so that by default all three of the mentioned fields are searched when no
field is explicitly indicated. I also experimentally tried replacing spaces
with underscores, but with the same results.

I'd be happy to post more source code if that might help identify the
problem.

Thanks in advance for any insights.

Logan
-- 
View this message in context: http://www.nabble.com/Problem-with-spaces-in-untokenized-field-using-QueryParser-tp20866331p20866331.html
Sent from the Lucene - General mailing list archive at Nabble.com.


Re: Problem with spaces in untokenized field using QueryParser

Posted by chaiguy1337 <lo...@electricstorm.com>.
Hi Daniel. Thanks for the tip. I've decided to simply intercept query strings
starting with "tag:" (since I still want to allow users to type the query
strings) and treat them as a TermQuery, as per your suggestion, rather than
passing it to QueryParser at all, and it seems to have done the trick!
Luckily I only need to do this in one case, otherwise I'd probably have to
write a custom QueryParser.

Thanks for clearing that up for me.

-Logan



Daniel Naber-10 wrote:
> 
> On Samstag, 6. Dezember 2008, chaiguy1337 wrote:
> 
>> tag:"my tag"
> 
> The QueryParser will create a phrase query from this, but for untokenized 
> fields you can only search with a TermQuery, i.e. something like this: 
> new TermQuery(new Term("tag", "my tag"))
> 
> Regards
>  Daniel
> 
> -- 
> http://www.danielnaber.de
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-with-spaces-in-untokenized-field-using-QueryParser-tp20866331p20872875.html
Sent from the Lucene - General mailing list archive at Nabble.com.


Re: Problem with spaces in untokenized field using QueryParser

Posted by Daniel Naber <lu...@danielnaber.de>.
On Samstag, 6. Dezember 2008, chaiguy1337 wrote:

> tag:"my tag"

The QueryParser will create a phrase query from this, but for untokenized 
fields you can only search with a TermQuery, i.e. something like this: 
new TermQuery(new Term("tag", "my tag"))

Regards
 Daniel

-- 
http://www.danielnaber.de