London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

To Search a collection of dates

Vote:
 

Hi,

I am using Episerver Find and the version is 6R2.

It is an event that can be occured on multiple dates.

I have two filters DateFrom and DateEnd.

I have list of date collection on which the event can happen.

I need to create a find filter which can look into DateCollection and filter the result. I need to apply in range as well as match here.

The following query gives me an error:-

query = query.Filter(x => x.EventDatesCollection.Match(DateFrom));

"Cannot resolve method Match(system.datetime). It does not seem to match datetime field."

Can anyone share the idea, how can I implement this?

Many thanks

Naz

#88799
Jul 30, 2014 18:41
Vote:
 

Hi Nazim,

There was a similar question on the forums not too long ago. But that used Nested2Find which I don't think is available for Find 1 (CMS 6 R2). But maybe you can use the source code to make it Find 1 compatible?

http://world.episerver.com/Forum/Developer-forum/EPiServer-Search/Thread-Container/2014/6/Searching-a-list-of-complex-objects/

#88801
Jul 30, 2014 23:53
Vote:
 

Hi,

Thanks Toni very much for your reply, Here is the code where I am defining the Nested object.

//Custom class for EventOccurances defined

 public class EventOccurances
    {
        public PageReference EventId{ get; set; }
        public DateTime EventDate { get; set; }

        public string Location
        {
            get; set;
            
        }
    }

 // PageType defined where I am filling the nested collection

 public class EventPageType : BaseTypedPageData
    {

        public virtual NestedList EventOccuranceCollection
         {
            get
            {
 
                var eventOccuranceList = new NestedList();
                IEnumerable children = DataFactory.Instance.GetChildren(this.PageLink).Cast();
                foreach (var pd in children)
                {
                    EventOccurances eventOcc = new EventOccurances();

                    if (pd.LocationName != null)
                    {
                        // eventOcc.EventId = pd.PageLink;
                        eventOcc.Location = pd.LocationName;

                    }
                    if (pd.EventDateTime != DateTime.MinValue)
                    {
                        eventOcc.EventDate = pd.EventDateTime;
                    }

                    if (eventOcc.Location != null || eventOcc.EventDate != DateTime.MinValue)
                    {
                        eventOccuranceList.Add(eventOcc);
                    }
                }

                return eventOccuranceList;  //Fill the nested list from the child pages only locations and dates
            }
            
        }

}

Now on the Search Results page:-

  SearchClient.Instance.Conventions.AddNestedConventions();  //Added the nested convention
  var query = SearchClient.Instance.Search();

if (!string.IsNullOrEmpty(Location))
            {

                query = query.Filter(x => x.EventOccurances.MatchItem(p => p.Location.Match(Location)));
            }

           var result = query.Select(x => new BaseSearchResult.SearchHit
            {
                Title = x.PageName,
                Url = x.LinkURL(),
                Text = x.Description,
                PageList = x.PageaHierarchyList,
                PublishedDate = x.SearchPublishDate(),
                EventType = x.EventType,
                EventSubject = x.MastercourseSubject,
                PageDataForSearch = x.PageLink
             

            }).GetResult();

It is throwing the same exception which is mentioned in the post you mentioned

The remote server returned an error: (400) Bad Request.

[nested] failed to find nested object under path [EventOccuranceCollection$$nested]]

On the Find Index parser:- it does not give me the value of collection as EventOccuranceCollection$$nested but as EventOccuranceCollection

property.PropertyName = property.PropertyName + "$$nested";  //this code is already definied in ModifyContract

Do you spot any problem in the code.
Did I miss anything? Why it is not adding nested keyword around it. Please if anyone can reply.

Many thanks,
Nazim

#88821
Jul 31, 2014 13:46
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.