0
  • Events are running from one date to another.
  • User can search for all active Events from one date to another.
  • If Event is active between user selected date range, it should return event(s).

I am using Lucene (Umbraco)

Example

 Sample DB Table with one record in it. 
    ---------------------------------------
    eventStartDate  eventEndDate   EventName
    "23-Nov-2015"  "31-Dec-2015"   "test Event"

User Criteria

var fromDate = "01-Dec-2015"
var toDate = "31-Dec-2015"

//Scenario one with eventStartDate

var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["Searcher"];
var searchCriteria = searcher.CreateSearchCriteria();
.......
var query = searchCriteria.RawQuery(luceneString).OrderBy("eventStartDate");
query.And().Range("eventStartDate", fromDate, toDate, true, true);

Output Result
{Return nothing}

//Scenario two with eventEndDate

var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["Searcher"];
var searchCriteria = searcher.CreateSearchCriteria();
.......
var query = searchCriteria.RawQuery(luceneString).OrderBy("eventStartDate");
query.And().Range("eventEndDate", fromDate, toDate, true, true); // change is here

Output Result
-------------
"23-Nov-2015"  "31-Dec-2015"   "test Event"

I need to combine both above Scenarios if either of them is matched. Something like this but not sure exact Lucene code.

query.And().(Range("eventStartDate", fromDate, toDate, true, true) OR Range("eventEndDate", fromDate, toDate, true, true))


var result = searcher.Search(query.Compile());
Developer
  • 25,073
  • 20
  • 81
  • 128
  • This one did not work. http://stackoverflow.com/questions/18819690/umbraco-lucene-or-search-on-multiple-date-ranges – Developer Dec 06 '15 at 22:02
  • Other similar kind of question is https://our.umbraco.org/forum/developers/api-questions/22799-Using-GroupedOr-to-search-one-field-for-multiple-terms – Developer Dec 06 '15 at 22:02
  • Have you used `Execute()` method on the query? From the first glance at your code, this seems to be missing. – Marko Jovanov Dec 07 '15 at 08:26
  • It is working with each scenario. but I need to group both together. i.e. user select date between x to y. if start event date or end event date, either is between x to y. it should display that record. In SQL it can be done easily by using () brackets but Not sure how it works in lucene examine. I tried to combine using Or but did not work. – Developer Dec 08 '15 at 02:32
  • Have you tried `GroupedOr`? Search for this keyword in the [following article](http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine/) to understand the syntax. – Marko Jovanov Dec 08 '15 at 08:24
  • Yes, I did, but did not work. Do any of you know good documentation of all these funcs in query, Range, Or, And, GroupedOr etc. – Developer Dec 08 '15 at 23:30
  • For Umbraco you have the provided link and Examine GitHub page. Other than that, it's trial and error, there is no detailed documentation unfortunately. – Marko Jovanov Dec 08 '15 at 23:33
  • I can run above whole whole code two times and save results in two different variables. var result = searcher.Search(query.Compile()); and var result2 = searcher2.Search(query2.Compile()); do you know how to merge both variables result and result2 together? – Developer Dec 08 '15 at 23:36
  • No, I'm sorry, haven't done that yet. Try to search for merging, I am sure somebody has tried it. – Marko Jovanov Dec 08 '15 at 23:38
  • This is pretty straightforward with native lucene The umbraco DSL is obscuring what's going on. Suggestion: put the "query.Compile()" into another var, put a break point after it. The look at the "ToString()" of the var. This should be the textual representation of the lucene Query object. If should give us some clues as to what's going on – AndyPook Mar 23 '16 at 11:39

0 Answers0