lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: Having trouble getting QueryParser to work...
Date Wed, 21 Sep 2011 16:24:57 GMT
Lucene 3.4 has NumericField support in it's flexible QueryParser
(contrib/queryparser). The core Queryparser has no idea about numeric fields
and always produces TermQuery/TermRangeQuery.

To your code: In general you should use NumericRangeQuery always and not
TermQuery with NumericUtils (which is internal expert class) on numeric
fields. Just use upper=lower, speed is same and it does not wrongly rank the
results.

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de

> -----Original Message-----
> From: Michael Remijan [mailto:mjremijan@yahoo.com]
> Sent: Wednesday, September 21, 2011 6:20 PM
> To: general@lucene.apache.org
> Subject: Having trouble getting QueryParser to work...
> 
> Sorry if this is an obvious question.
> 
> I have the following BooleanQuery set up which works fine, and when I say
> "fine" I mean if I change the search values to values which I know are not
in the
> index then the search returns no results. So this works OK.
> 
>         Query
>              dinnerQuery     = new TermQuery(new Term("entry", "dinner"))
>                ,accountIdQuery = new TermQuery(new Term("accountid",
> NumericUtils.intToPrefixCoded(1)))
>         ;
>         BooleanQuery
>             query = new BooleanQuery();
>               query.add(accountIdQuery, Occur.MUST);
>               query.add(dinnerQuery, Occur.MUST);
> 
> When I run the above code I get 1 result I am expecting:
> 
> Found 1 hits
> HIT #1
>   accountid = 1
>   journalid = 1
>   id = 306
> 
> 
> 
> Now I've been trying to convert this to use a QueryParser expression but I
have
> not had any luck.  Here is my first attempt.
> 
>         String str =
>             "accountid:1 AND entry:dinner"
>         ;
>         Query query
>             = parser.parse(str);
> 
> When I execute this, I get no results:
> 
> Found 0 hits
> 
> So I changed the query to use NumericUtils thinking that might be the
> problem...
> 
>         String str =
>             "accountid:" +NumericUtils.intToPrefixCoded(1)+ " AND
> entry:dinner"
>         ;
>         Query query
>             = parser.parse(str);
> 
> When I execute this, I thought I got the results I was looking for because
the
> query found the 1 hit it was suppose to, however, during testing I found I
could
> put any value i want in for accountid and the search will always return
the 1
> hit.
> 
> So I'm not sure what I'm doing wrong and why QueryParser is giving the
results
> it is.


Mime
View raw message