问题
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