public static IElasticSearchService <T> Filter <T>(this IElasticSearchService <T> service, Expression <Func <T, CategoryList> > fieldSelector, string filterValue) { Tuple <string, MappingType> fieldInfo = ElasticSearchService <T> .GetFieldInfo(fieldSelector); return(service.Filter(fieldInfo.Item1, filterValue, false)); }
/// <summary> /// Adds suggestions for supplied properties of {T}, except those hidden by convention of configuration /// </summary> public Indexing EnableSuggestions <TProperty>(params Expression <Func <T, TProperty> >[] fieldSelectors) { if (fieldSelectors == null || fieldSelectors.Length == 0) { return(_instance); } foreach (var fieldSelector in fieldSelectors) { string fieldName = ElasticSearchService <T> .GetFieldInfo(fieldSelector).Item1; // Update existing registration of type? if (Indexing.Suggestions.Any(s => s.Type == typeof(T))) { Indexing.Suggestions.Single(s => s.Type == typeof(T)).InputFields.Add(fieldName); } else { Suggestion suggestion = new Suggestion(typeof(T)); suggestion.InputFields.Add(fieldName); Indexing.Suggestions.Add(suggestion); } } return(_instance); }
/// <summary> /// Register a property as searchable. /// <para> /// Use this if you can't alter the source code of the object to index, /// thus preventing you from using [Searchable] /// </para> /// </summary> public static Indexing IncludeProperty <T, TProperty>(this CustomPropertyConvention <T> instance, Expression <Func <T, TProperty> > fieldSelector) where T : IContent { string fieldName = ElasticSearchService <T> .GetFieldInfo(fieldSelector).Item1; Type type = typeof(T); if (!Indexing.Instance.SearchableProperties.ContainsKey(type)) { Indexing.Instance.SearchableProperties.TryAdd(type, new[] { fieldName }); } else { if (Indexing.Instance.SearchableProperties.TryGetValue(type, out string[] current))
/// <summary> /// Apply stemming for field <paramref name="fieldSelector"/> /// </summary> /// <param name="fieldSelector">An expression, typically a property or an instance/extension method.</param> public Indexing StemField <TProperty>(Expression <Func <T, TProperty> > fieldSelector) { var fieldName = ElasticSearchService <T> .GetFieldInfo(fieldSelector).Item1; if (WellKnownProperties.Analyze.Contains(fieldName)) { return(_instance); } Logger.Debug("Adding stemming for field: " + fieldName); WellKnownProperties.Analyze.Add(fieldName); return(_instance); }
/// <summary> /// Enables highlighting on the supplied field(s). /// Fields named MainIntro, MainBody and Description are included by default /// </summary> public Indexing EnableHighlighting <TProperty>(params Expression <Func <T, TProperty> >[] fieldSelectors) { if (fieldSelectors == null || fieldSelectors.Length == 0) { return(_instance); } foreach (var fieldSelector in fieldSelectors) { string fieldName = ElasticSearchService <T> .GetFieldInfo(fieldSelector).Item1; if (!Indexing.Highlights.Contains(fieldName)) { Indexing.Highlights.Add(fieldName); } } return(_instance); }
/// <summary> /// Include a custom property when indexing this type. /// The name of the property will be the same as the property/method in the <paramref name="fieldSelector"/> parameter. /// <para> /// If you need more control over the name, and/or the method supplying the data to be indexed has /// no relations to the type, use the overload <c>IncludeField(string, Expression, bool)</c> /// </para> /// </summary> /// <example> /// <para>Extension/instance method: IncludeField(x => x.CustomStuff());</para> /// <para>Property method: IncludeField(x => x.MyCustomProp);</para> /// <para>Custom name: IncludeField("Foobar", x => x.MyCustomProp);</para> /// </example> /// <param name="fieldSelector">An expression, typically a property or an instance/extension method.</param> /// <param name="stem">Should stemming be applied for this property?</param> public Indexing IncludeField <TProperty>(Expression <Func <T, TProperty> > fieldSelector, bool stem = false) { string fieldName = ElasticSearchService <T> .GetFieldInfo(fieldSelector).Item1; return(IncludeField(fieldName, fieldSelector, stem)); }