Umbraco Lucene or search on multiple date ranges

2019-07-07 07:45发布

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条回答
再贱就再见
2楼-- · 2019-07-07 08:21

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.

查看更多
登录 后发表回答