Hi!
You're quite close... use the ISO date format, e.g.
search created:[20070701 TO 20070730]
Here's a code snipet that may be helpful for indexing dates:
def date2index(doc, key, timestamp):
"""store date as string YYYYMMDD in index for given key"""
if timestamp is None:
return doc
from time import gmtime, strftime
ts_gmt = gmtime(timestamp)
ts_str = strftime('%Y%m%d',ts_gmt)
doc.add(Field(key, ts_str, Field.Store.NO,
Field.Index.UN_TOKENIZED))
return doc
Regards
Thomas
--
Thomas Koch
OrbiTeam Software GmbH & Co. KG
http://www.orbiteam.de
________________________________
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Im Auftrag von Saikrishna
Budamgunta
Gesendet: Montag, 30. Juli 2007 11:58
An: [email protected]
Betreff: [pylucene-dev] How to index and search dates?
I am new to PyLucene. I am trying to use PyLucene to index Articles
with created time stored as a datetime object.
After looking at Lucene documentation i tried to use this piece of
code to solve the issue but it doesn't solve the problem.
>>import PyLucene
>>lucenedt = PyLucene.Date()
>>lucenedt.setTime(long(time.mktime(created_on.utctimetuple()))*1000)
>>field = PyLucene.Field("pubdate", lucenedt
,PyLucene.Field.Store.YES ,PyLucene.Field.Index.UN_TOKENIZED)
>>doc.add(field)
I get PyLucene.InvalidArgsError exception.
I read on "Lucene in Action" Book by Otis Gospodnetic & Erik Hatcher
in section2.4(indexing dates) that storing date as string objects of type
'yyyymmdd' will solve the problem easliy. Though indexing completes with out
any problems. I am not able to search for the results based on time.
datestring = '%s%s%s' %
(created_on.year,created_on.month,created_on.day)
field = PyLucene.Field("pubdate", datestring
,PyLucene.Field.Store.YES,PyLucene.Field.Index.UN_TOKENIZED)
My Search string is like this.
searcher.search('Mike and pubdate:[21/7/2007 TO 31/7/2007]')
The result set doesnot contain results from this range. Any amount
of help is deeply appreciated.
Thanks in advance,
Saikrishna.
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev