Migration: How to Migrate Facets and Dynamic Aggregation from 3.x
Facets and Dynamic Aggregation have been merged into a single feature and are now a part of RQL.
Facets
Facets are now divided into two types:
Facet
where the whole spectrum of results will generate a single outcomeRangeFacet
gives you the ability to split the whole spectrum of results into smaller ranges
The FacetSetup
document also now splits the facets into two properties. One containing Facets
, the other containing RangeFacets
.
Example
3.x |
---|
List<Facet> facets = new List<Facet>
{
new Facet
{
Name = "Manufacturer"
},
new Facet<Camera>
{
Name = x => x.Cost,
Ranges =
{
x => x.Cost < 200m,
x => x.Cost > 200m && x.Cost < 400m,
x => x.Cost > 400m && x.Cost < 600m,
x => x.Cost > 600m && x.Cost < 800m,
x => x.Cost > 800m
}
},
new Facet<Camera>
{
Name = x => x.Megapixels,
Ranges =
{
x => x.Megapixels < 3.0,
x => x.Megapixels > 3.0 && x.Megapixels < 7.0,
x => x.Megapixels > 7.0 && x.Megapixels < 10.0,
x => x.Megapixels > 10.0
}
}
};
session.Store(new FacetSetup { Id = "facets/CameraFacets", Facets = facets });
|
4.0 |
---|
List<Facet> facets = new List<Facet>
{
new Facet
{
FieldName = "Manufacturer"
}
};
List<RangeFacet> rangeFacets = new List<RangeFacet>
{
new RangeFacet<Camera>
{
Ranges =
{
x => x.Cost < 200m,
x => x.Cost > 200m && x.Cost < 400m,
x => x.Cost > 400m && x.Cost < 600m,
x => x.Cost > 600m && x.Cost < 800m,
x => x.Cost > 800m
}
},
new RangeFacet<Camera>
{
Ranges =
{
x => x.Megapixels < 3.0,
x => x.Megapixels > 3.0 && x.Megapixels < 7.0,
x => x.Megapixels > 7.0 && x.Megapixels < 10.0,
x => x.Megapixels > 10.0
}
}
};
session.Store(new FacetSetup { Id = "facets/CameraFacets", Facets = facets, RangeFacets = rangeFacets });
|
Querying
All of the method were substituted with AggregateBy
and AggregateUsing
.
Example I
3.x |
---|
Dictionary<string, FacetResult> facetResults = session
.Query<Camera, Cameras_ByManufacturerModelCostDateOfListingAndMegapixels>()
.Where(x => x.Cost >= 100 && x.Cost <= 300)
.AggregateBy(facets)
.Execute();
|
4.0 |
---|
Dictionary<string, FacetResult> facetResults = session
.Query<Camera, Cameras_ByManufacturerModelCostDateOfListingAndMegapixels>()
.Where(x => x.Cost >= 100 && x.Cost <= 300)
.AggregateBy(facets)
.Execute();
|
Example II
3.x |
---|
FacetResults facetResults = session
.Query<Camera, Cameras_ByManufacturerModelCostDateOfListingAndMegapixels>()
.Where(x => x.Cost >= 100 && x.Cost <= 300)
.ToFacets("facets/CameraFacets");
|
4.0 |
---|
Dictionary<string, FacetResult> facetResults = session
.Query<Camera, Cameras_ByManufacturerModelCostDateOfListingAndMegapixels>()
.Where(x => x.Cost >= 100 && x.Cost <= 300)
.AggregateUsing("facets/CameraFacets")
.Execute();
|
Remarks
You can read more about Facets in our dedicated Querying article, our Indexing article or Client API article.