lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Remijan <mjremi...@yahoo.com>
Subject Re: Having trouble getting QueryParser to work...
Date Tue, 27 Sep 2011 17:55:39 GMT
I'm still having problems getting QueryParser to correctly search and find a field which holds
integer values.

I can use the NumericField to store the values, but I can't figure out how to integrate the
contrib project to be able to search numeric fields.

Instead of using numeric fields, is it an acceptable practice to simply pre pend an integer
value with leading zero's and treat it as a string?




________________________________
From: Michael Remijan <mjremijan@yahoo.com>
To: "general@lucene.apache.org" <general@lucene.apache.org>
Sent: Wednesday, September 21, 2011 12:33 PM
Subject: Re: Having trouble getting QueryParser to work...


OK, that worked great.

Now, when I am indexing a date, I see that DateField is deprecated so I am using just a Field
for this...


                new Field(
                    "day"                               
            // The name of the field
                    ,DateTools.dateToString(day, Resolution.DAY)    // The
string to
 process
                    ,Field.Store.NO                       
        // Whether value should be stored in the index
                    ,Field.Index.ANALYZED                   
        // Whether the field should be indexed, and if so, if it should be tokenized
before indexing 
                )

so when I'm searching a date field range, I would use a TermRangeQuery correct?



________________________________
From: Uwe Schindler <uwe@thetaphi.de>
To: general@lucene.apache.org; 'Michael Remijan' <mjremijan@yahoo.com>
Sent: Wednesday, September 21, 2011 11:24 AM
Subject: RE: Having trouble getting QueryParser to work...

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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message