lucene - Sorting on date field with Sitecore 7 ContentSearch -
i'm trying add together field sort date field in contentsearch query. i'm able filter on index field i'm assuming field getting populated values properly, however, results not beingness sorted properly. thoughts? here's code i'm using query:
public static ienumerable<episode> getpastepisodes(show show, bool includemostrecent = false, int count = 0) { ienumerable<episode> pastepisodes; using (var context = _index.createsearchcontext()) { // querying against lucene index pastepisodes = context.getqueryable<episode>().where(getpastairdatepredicate(show)); if(!includemostrecent) { pastepisodes = pastepisodes.where(item => item.id != getmostrecentepisode(show).id); } pastepisodes = pastepisodes.orderbydescending(ep => ep.latest_air_date); if (count > 0) { pastepisodes = pastepisodes.take(count); } pastepisodes = pastepisodes.tolist(); // map lucene documents sitecore items using database foreach (var episode in pastepisodes) { _database.map(episode); } } homecoming pastepisodes; } private static expression<func<episode,bool>> getpastairdatepredicate(show show) { var templatepredicate = predicatebuilder.create<episode>(item => item.templateid == iepisodeconstants.templateid); var showpathpredicate = predicatebuilder.create<episode>(item => item.fullpath.startswith(show.fullpath)); var airdatepredicate = predicatebuilder.create<episode>(item => item.latest_air_date < datetime.now.date.adddays(1)); var fullpredicate = predicatebuilder.create<episode>(templatepredicate).and(showpathpredicate).and(airdatepredicate); homecoming fullpredicate; } the field stored , untokenized , using lowercasekeywordanalyzer.
<field fieldname="latest_air_date" storagetype="yes" indextype="un_tokenized" vectortype="no" boost="1f" type="system.datetime" settingtype="sitecore.contentsearch.luceneprovider.lucenesearchfieldconfiguration, sitecore.contentsearch.luceneprovider"> <analyzer type="sitecore.contentsearch.luceneprovider.analyzers.lowercasekeywordanalyzer, sitecore.contentsearch.luceneprovider"/> </field> episode class has indexfield attribute set:
[indexfield("latest_air_date")] public virtual datetime latest_air_date {get; set; }
kyle,
as far can tell looks right configuration , code. mocked out similar in vanilla sitecore 7.2 instance , dates sorted without issue.
one thing note though, , might giving issues, sitecore's fieldreader datetime store date portion of datetime. if expecting able sort true datetime need add together custom fieldreader or computed fields.
see blog discusses issue , explains process swap out custom field reader: http://reasoncodeexample.com/2014/01/30/indexing-datetime-fields-sitecore-7-content-search/
i suggest looking @ index luke verify info in index. https://code.google.com/p/luke/
and may want enable search debugging in sitecore see how sitecore executing query in lucene.
sitecore.contentsearch.config:
<setting name="contentsearch.enablesearchdebug" value="true" /> lucene sitecore sitecore7
No comments:
Post a Comment