Hi, I would also use NumericField + NumericRangeQuery for date fields. There are several possibilities to incorporate those, the easiest is to use a LONG numeric field and encode Date.getTime() [milliseconds since 1970-01-01T00:00:00.000] into it. The flexible QueryParser in contrib can directly use those encoded fields and parser the entered query string to dates (with the corresponding configuration). See the testcase for a usage example.
Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: [email protected] > -----Original Message----- > From: Michael Remijan [mailto:[email protected]] > Sent: Wednesday, September 21, 2011 7:34 PM > To: [email protected] > 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 <[email protected]> > To: [email protected]; 'Michael Remijan' <[email protected]> > 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: [email protected] > > > -----Original Message----- > > From: Michael Remijan [mailto:[email protected]] > > Sent: Wednesday, September 21, 2011 6:20 PM > > To: [email protected] > > 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.
