Adds nested filtering to EPiServer Find's .NET API
Switch branches/tags
Clone or download
lindstromhenrik Version 1.2.0
- Updated nuget dependency to support EPiServer.Find 9.x
Latest commit 4c4a811 Jun 4, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget Updated nuget.exe to version 2.8.3 (to support schema model in Machin… Mar 2, 2015
Nested2Find.Tests NestedDateHistogramFacet Jun 4, 2015
Nested2Find Version 1.2.0 Jun 4, 2015
.gitignore Initial commit Nov 13, 2012
Nested2Find.sln Initial commit Nov 13, 2012
Readme.md Update Readme.md Jun 4, 2015

Readme.md

Nested2Find

Adds nested filtering to EPiServer Find's .NET API

Build

In order to build Nested2Find the NuGet packages that it depends on must be restored. See http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

Usage

Add the nested conventions to the conventions:

client.Conventions.AddNestedConventions();

Create an object containing a NestedList of objects

public class Team
{
    public Team(string name)
    {
        TeamName = name;
        Players = new NestedList<Player>();
    }
    public string TeamName { get; set; }
    public NestedList<Player> Players { get; set; }
}

public class Player
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Salary { get; set; }
}

Index and start filtering:

result = client.Search<Team>()
             .Filter(x => x.Players, p => p.FirstName.Match("Cristiano") & p.LastName.Match("Ronaldo"))
             .GetResult();

or:

result = client.Search<Team>()
            .Filter(x => x.Players.MatchItem(p => p.FirstName.Match("Cristiano") & p.LastName.Match("Ronaldo")))
            .GetResult();

Sorting

In order to sort on nested properties the OrderBy-extensions takes a filter argument that specifies on which nested object the sort value should be calculated:

result = client.Search<Team>()
            .Filter(x => x.Players, p => p.FirstName.Match("Cristiano"))
            .OrderBy(x => x.Players, p => p.LastName, p => p.FirstName.Match("Cristiano"))
            .GetResult();

or:

result = client.Search<Team>()
            .Filter(x => x.Players, p => p.FirstName.Match("Cristiano"))
            .OrderByDescending(x => x.Players, p => p.LastName, p => p.FirstName.Match("Cristiano"))
            .GetResult();

As for int/DateTime a SortMode (Min/Max/Avg/Sum) can be specified to decide how to treat multiple sort values. To sort by the mamimum player salary in a team use:

result = client.Search<Team>()
            .OrderByDescending(x => x.Players, p => p.Salary, SortMode.Max)
            .GetResult();

Facets

In order to facet on nested properties TermsFacetFor/HistogramFacetFor/DateHistogramFacetFor-extensions takes a NestedList expression along with an item expression and an optional filter:

result = client.Search<Team>()
            .TermsFacetFor(x => x.Players, x => x.FirstName)
            .GetResult();

or (to filter):

result = client.Search<Team>()
            .TermsFacetFor(x => x.Players, x => x.FirstName, x => x.LastName.Match("Ronaldo"))
            .GetResult();

and to fetch the result:

facet = result.TermsFacetFor(x => x.Players, x => x.FirstName);