.net - How to do a Lucene search with Sitecore item with specific date? -
i've content item sitecore date field named 'eventdate'. want search items specific date using lucene.net.
below code i've tried not getting result:
var index = searchmanager.getindex("event_search_index"); var items = new list<eventdetailitem>(); var eventdatestring = eventdate.year.tostring("d4") + eventdate.month.tostring("d2") + eventdate.date.day.tostring("d2"); using (var context = new indexsearchcontext(index)) { var searchterm = new lucene.net.index.term("eventdate", eventdatestring); var query = new lucene.net.search.termquery(searchterm); var topfielddocs = context.searcher.search(query, 1); if (topfielddocs != null) { var scoredocs = topfielddocs.scoredocs; foreach (var scoredoc in scoredocs) { var doc = context.searcher.doc(scoredoc.doc); var urifield = doc.getfield("_url"); var itemuri = new sitecore.data.itemuri(urifield.stringvalue()); var item = sitecore.context.database.getitem(itemuri.todatauri()); if (item == null) continue; var eventitem = new eventdetailitem(item); items.add(eventitem); } } }
you're using standard sitecore date field (switch raw values view) date stored yyyymmddthhmmss
string, e.g.:
20130418t140122
and use termquery
first part of query only, e.g.:
20130418
so don't see result termquery
matches exact field value.
you should either try wildcardquery
20130418*
or use rangequery
starting 20130418t000000
including value , ending on 20130819t000000
excluding value.
here can find more information troubleshooting sitecore , lucene problems.
Comments
Post a Comment