/// <summary> /// Adds the Facet in the order it was added /// </summary> /// <param name="property">The property key to facet on</param> /// <returns><see cref="FacetBuilder{T}"/></returns> public virtual FacetBuilder <T> On(string property) { if (String.IsNullOrEmpty(property)) { return(this); } var facet = new FacetOn(property); this.On(facet); return(this); }
/// <summary> /// Adds the Facet by a property of the <see cref="T"/> of <see cref="SearchResultItem"/> /// <para>If the <see cref="IndexFieldAttribute"/> does not exist on the property, /// the default will be a lowercase name of the property</para> /// </summary> /// <param name="expression">The expression of the property</param> /// <exception cref="ArgumentNullException">Expression cannot be null</exception> /// <exception cref="ArgumentException">Expression cannot refer to a method</exception> /// <exception cref="ArgumentException">Expression cannot refer to a field</exception> /// <returns><see cref="FacetBuilder{T}"/></returns> public virtual FacetBuilder <T> On <TProperty>(Expression <Func <T, TProperty> > expression) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } // Extension to convert the expression into the Property needed var propInfo = expression.ToPropertyInfo(); /** * Attempt to get the IndexFieldAttribute on the Property, if it * doesn't exist, just take the name of the property */ var indexField = propInfo.GetCustomAttribute <IndexFieldAttribute>(); var facetKey = indexField != null ? indexField.IndexFieldName : propInfo.Name.ToLower(); var facetOn = new FacetOn(facetKey); return(this.On(facetOn)); }