Try our conversational search powered by Generative AI!

Filtering on nested objects/properties

Vote:
 

Hi,

I have problem where I need to be able to filter on properties on subpages but return the parent page from FIND. I thought that I could use nested queries for this but i does not seem to work.

Page structure is as follows:

Education page 1 (info)

      -Event page 1 (Event)

      -Event page 2 (Event)

      -Event page 3 (Event)

Education page 2 (info)

      -Event page 1 (Event)

      -Event page 2 (Event)

etc

and the page types look like this (generalised):

public class Education
{
 public Education(string name)
 {
  Events = getChildren(this.contentID);
 }

 public string Name { get; set; }
 public string SokSemesters { get; set; }
 public string SokLocations { get; set; }
 public string SokTerms { get; set; }
 public List Event { get; set; } //Nested object
}

public class Event
{
  public string Semester { get; set; }
  public string Location { get; set; }
  public string Term { get; set; }
}


I index both Education and Event pages and have access to them from FIND. I search over the Education type because I want to present educations in the search result (with events) and in filter options with count over how many educations each filter options result in (using facetts). The SokSemesters, SokLocations and SokTerms are a actually just collections(comma separated string) of corresponding properties on all the events that belong to a certain education. I use SokSemesters, SokLocations and SokTerms to generate the facetts.

Now to the tricky part. I want to be able filter on semester, location and term on the events and only returning matching educations. Between different types of filters AND should be used and within the same type of filter OR should be used (you can have multiple filters of the same type). I have tried something like this:

.Filter (X => x.Events, x => x.Location.MatchCaseInsensitive (Location);

But it does not seem to work, it does not filter educations correctly. So I am wondering if I am missing something about nested queries? Or is there any other way of doing this, for example by using a content area and putting the events there?

Thanks

Magnus

#145313
Mar 01, 2016 21:04
Vote:
 

Have you added a convention for events property to indicate that you want to enable nested queries?

client.Conventions.NestedConventions.ForType<Education>().Add(e=> e.Events);

#145321
Mar 01, 2016 23:47
Vote:
 

Yes I have! No difference

Magnus

#145391
Mar 02, 2016 21:14
Vote:
 

Checked index and see that the Events are there (on the education object...)?

#145394
Mar 03, 2016 7:44
Vote:
 

Yes. Do you think nested queries should work for this use case?

#145443
Mar 03, 2016 19:36
Vote:
 

Should work yes

#145445
Mar 03, 2016 22:20
Vote:
 

Will changes (publishing) on the nested objects (in this case event pages) automatically triggered reindexing of the nested objects "List<Event> Events" on the parent "Education page"?

#194939
Jul 09, 2018 18:10
Vote:
 

Bojan S. did you get an answer for your question about automatically triggering reindexing or doeas anyone else know if this is supposed to work? I have a case where I want to index the ancestors of a product in commerce as nested conventions but I can't seem to trigger any reindexing for the related items when updating a parent, wich makes using nested conventions more or less useless for my case.

#208144
Oct 15, 2019 6:45
Vote:
 

In this case, you should try catching the published event in the content repository, and then base on page type (or other logic to identify it is the parent that you are inteested) use the API to find the related items and then perform the actions you need there

#208163
Oct 16, 2019 0:08
Vote:
 

You should configure the nested configuration on startup in a initialization module. Then you should be able to filter and search on the nested index object. Also as other mention when you have you data indexed correctly then you should be able to see the data as a nested structure in the Find interface. 

[InitializableModule]
    [ModuleDependency(typeof(EPiServer.Find.Cms.Module.IndexingModule))]
    public class FindInitialization : IInitializableModule
    {

        public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
        {
            SearchClient.Instance.Conventions.NestedConventions.ForInstancesOf<Education>().Add(p => p.Events);
        }

        public void Preload(string[] parameters)
        {

        }

        public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
        {

        }
    }
#208195
Edited, Oct 17, 2019 12:55
* 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.