Movatterモバイル変換


[0]ホーム

URL:


Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog InCross-platform products
Dev guide
All
Pages
Start typing to search…

Facets selection

Select facet by field.

The Optimizely Graph .Net Client supports faceting or aggregating documents using theFacet method. You must specify the field or fields you want to facet.

The following is an example of a simple "facet" that facets the documents based on the value of theFacetProperty field:

var query = queryBuilder.ForType<MyDocumentType>()  .Facets(x=>x.FacetProperty).ToQuery().BuildQueries();

Facet on IEnumerable property

For theIEnumerable<T> property:

  • IfT is a simple type (int, long, float, double, string, bool) or DateTime just use as a normal field.
  • IfT is a complex type object. Use first expression for selectingIEnumerable property then properties ofT.
var query = queryBuilder.ForType<MyDocumentType>()  .Facets(x=>x.MyEnumerableProp, f=> f.FacetProp).BuildQueries();

Alternatively, the most efficient way for dealing withIEnumberable<T> whereT is a complex type is create an extension method for pretending property typeIEnumberable<T> to beT. With that you can use all properties of typeT when select, filter, or facet using a simple block of code. Ensure that the method name equals with property name.

public static class CmsModelsExtension  {        ...       public static ContentLanguageModel ExistingLanguages(this Content myprop)       {           return null;       }  }  //now you want to select properties in ExistingLanguages field, just use method ExistingLanguages() // instead of property ExistingLanguages :  query.Fields(x=> x.ExistingLanguages().Name, x.ExistingLanguages().DisplayName)  //facets  query.Facet(x=> x.ExistingLanguages().Name.FacetLimit(10))

SeeTool tips: Optimizely Graph Client Tool and how to leverage CMS data models to build query blog for more information.

Facet projection

By default, the result of the facet contains aName andCount field. Use theProjection method onIFilterOperator to get your desired field.

var stringFacetFilter = new StringFacetFilterOperator()  .Filters(“value1”,”value2”)  .Limit(10)  .OrderBy(x=>x.Property1, OrderMode.DESC)  .Projection(FacetProperty.Name); //get only facet namevar query = queryBuilder.ForType<NewsPage>()  .Facet(x=>x.Title, stringFacetFilter).ToQuery().BuildQueries();

Updated 23 days ago



[8]ページ先頭

©2009-2025 Movatter.jp