Umbraco Lucene or search on multiple date ranges

徘徊边缘 提交于 2019-12-12 14:26:35

问题


We are using the following code:

var searcher = ExamineManager.Instance
                             .SearchProviderCollection[SearchProviderName];

var criteria = searcher.CreateSearchCriteria();

q = q.And()
     .Range("dateRangeStart", 
       startRange.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), 
       endRange.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), 
        true, true)
          );

criteria = q.Compile();
var searchResult = searcher.Search(criteria).AsEnumerable();

which works fine when searching based on a single date within a single date range. What we need however is a search with 2 dates that returns results if either of the dates are within the given date range.


回答1:


Presumably you could just do a further AND on the same range but a different field:

q = q.And()
 .Range("dateRangeStart", 
   startRange.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), 
   endRange.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), 
   true, true)
 .And().Range("dateRangeEnd", 
   startRange.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), 
   endRange.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), 
   true, true);

This is assuming that the other field is called dateRangeEnd.



来源:https://stackoverflow.com/questions/18819690/umbraco-lucene-or-search-on-multiple-date-ranges

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!