Re: Simple date/range question
On Friday 02 April 2004 17:03, [EMAIL PROTECTED] wrote: date:[20030101 TO 20030202] [java] 11:05:53,735 ERROR [view.SearchAction] org.apache.lucene.queryParser.ParseException: Encountered 20030202 at line 1, column 18. [java] Was expecting: [java] ] ... Why is this? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple date/range question
On Apr 3, 2004, at 4:07 AM, [EMAIL PROTECTED] wrote: On Friday 02 April 2004 17:03, [EMAIL PROTECTED] wrote: date:[20030101 TO 20030202] [java] 11:05:53,735 ERROR [view.SearchAction] org.apache.lucene.queryParser.ParseException: Encountered 20030202 at line 1, column 18. [java] Was expecting: [java] ] ... Why is this? I didn't catch in your first message that it was throwing a ParseException this is odd. Are you certain that date:[20030101 TO 20030202] is the complete string your passing to QueryParser? Did you subclass QueryParser? If so, what is that code? (what is the complete stack trace?) Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple date/range question
On Saturday 03 April 2004 11:53, Erik Hatcher wrote: I didn't catch in your first message that it was throwing a ParseException this is odd. Are you certain that date:[20030101 TO 20030202] is the complete string your passing to QueryParser? Did Yes. you subclass QueryParser? If so, what is that code? (what is the No. I use a MultiFieldQueryParser: Query qQuery = MultiFieldQueryParser.parse(query, new String[] { id, title, summary, contents, date }, GERMAN_ANALYZER); Hits hits = searcher.search(qQuery); complete stack trace?) [java] 12:38:03,109 ERROR [view.SearchAction] org.apache.lucene.queryParser.ParseException: Encountered 20030404 at line 1, column 18. [java] Was expecting: [java] ] ... [java] org.apache.lucene.queryParser.ParseException: Encountered 20030404 at line 1, column 18. [java] Was expecting: [java] ] ... [java] at org.apache.lucene.queryParser.QueryParser.generateParseException(QueryParser.java:994) [java] at org.apache.lucene.queryParser.QueryParser.jj_consume_token(QueryParser.java:874) [java] at org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:657) [java] at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:521) [java] at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:464) [java] at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:108) [java] at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:87) [java] at org.apache.lucene.queryParser.MultiFieldQueryParser.parse(MultiFieldQueryParser.java:115) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple date/range question
MMDD is the format You Timestamp contains HH mm, and ss, that's likely why your second query doesn't match anything. Drop everything other than MMDD from the index, and things should work. Otis --- [EMAIL PROTECTED] wrote: Hi! I do have some problems with date and the QueryParser range syntax. code: java.sql.Timestamp time = row.getTimestamp(timestamp); if (time != null) doc.add(Field.Keyword(date, new Date(time.getTime(; query: date:[20030101 TO 20030202] date:20030101 The first query does throw a ParserException, the second doesn't return any hits. Hmm...there must be something simple I misunderstood :) BTW what about custom date format in QueryParser (...and are the last two digits actually the day or month)? TIA Timo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple date/range question
On Friday 02 April 2004 18:59, Otis Gospodnetic wrote: You Timestamp contains HH mm, and ss, that's likely why your second My timestamp contains date and time. query doesn't match anything. Drop everything other than MMDD from the index, and things should work. What's wrong with new Date(timestamp)? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple date/range question
Let me clarify what Otis meant as well as shed some light on the other questions in this thread. On Apr 2, 2004, at 10:03 AM, [EMAIL PROTECTED] wrote: if (time != null) doc.add(Field.Keyword(date, new Date(time.getTime(; query: date:[20030101 TO 20030202] date:20030101 The first query does throw a ParserException, the second doesn't return any hits. QueryParser uses DateFormat.SHORT to parse dates using the default locale. 20030101 does not parse using that format string. If you are truly only representing dates (not times) then use, what Otis meant, MMDD *Strings* to represent the date. If you need times as well, first be aware of what RangeQuery does (expand all terms in that range!) so that you aren't shocked with performance or a too many clauses exception. When you use Field.Keyword(String, Date), the date is converted into a lexicographically ordered value (the ugly thing you saw in Luke). This is why, if you only care about dates, MMDD is recommended (it must sort properly). Hmm...there must be something simple I misunderstood :) BTW what about custom date format in QueryParser (...and are the last two digits actually the day or month)? Custom date format in QueryParser is quite do-able. Subclass QueryParser and override getRangeQuery and do what you like there. I do something similar in Lucene in Action. I'd like users to search on ranges like lastmodified:[1/1/04 TO 12/31/04], but internally I represent dates as MMDD. To make the conversion, I had to have a custom QueryParser /** * From Lucene in Action (Manning Publications) */ public class SmartDayQueryParser extends QueryParser { public static final DateFormat formatter = new SimpleDateFormat(MMdd); public SmartDayQueryParser(String field, Analyzer analyzer) { super(field, analyzer); } protected Query getRangeQuery(String field, Analyzer analyzer, String part1, String part2, boolean inclusive) throws ParseException { try { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, getLocale()); df.setLenient(true); Date d1 = df.parse(part1); Date d2 = df.parse(part2); part1 = formatter.format(d1); part2 = formatter.format(d2); } catch (Exception ignored) { } return new RangeQuery(new Term(field, part1), new Term(field, part2), inclusive); } } Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]