Exemple #1
0
        /// <summary>
        /// Will indicate that the search results should return facet information for the given field.
        /// </summary>
        /// <param name="fieldName"></param>
        public void AddFieldFacet(string fieldName)
        {
            Verify.ArgumentNotNullOrEmpty(fieldName, nameof(fieldName));

            if (Facets.Any(f => f.Key == fieldName))
            {
                return;
            }

            var field = SearchDocumentBuilder.GetDefaultDocumentFields()
                        .FirstOrDefault(f => f.Name == fieldName);

            if (field == null)
            {
                field = SearchFacade.DocumentSources.SelectMany(f => f.CustomFields)
                        .FirstOrDefault(f => f.Name == fieldName);

                Verify.IsNotNull(field, $"Failed to find a document field by name '{fieldName}'");
            }

            Verify.IsNotNull(field.Facet, $"Faceted search is not enabled for the field '{fieldName}'");

            Facets.Add(new KeyValuePair <string, DocumentFieldFacet>(
                           fieldName,
                           field.Facet));
        }
Exemple #2
0
        internal void AddDefaultFieldFacet(string fieldName)
        {
            if (Facets.Any(f => f.Key == fieldName))
            {
                return;
            }

            Facets.Add(new KeyValuePair <string, DocumentFieldFacet>(
                           fieldName,
                           SearchDocumentBuilder.GetDefaultDocumentFields()
                           .Single(f => f.Name == fieldName)
                           .Facet));
        }
        /// <summary>
        /// Will indicate that the search results should return facet information for the given field.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="values">The array of values that are required to appear in the search documents.</param>
        /// <param name="notValues">The array of values that are required not to appear in the search documents.</param>
        public void AddFieldFacet(string fieldName, string[] values, string[] notValues)
        {
            Verify.ArgumentNotNullOrEmpty(fieldName, nameof(fieldName));

            if (Facets.Any(f => f.Key == fieldName))
            {
                return;
            }

            var field = SearchDocumentBuilder.GetDefaultDocumentFields()
                        .FirstOrDefault(f => f.Name == fieldName);

            if (field == null)
            {
                field = SearchFacade.DocumentSources.SelectMany(f => f.CustomFields)
                        .FirstOrDefault(f => f.Name == fieldName);

                Verify.IsNotNull(field, $"Failed to find a document field by name '{fieldName}'");
            }

            Verify.IsNotNull(field.Facet, $"Faceted search is not enabled for the field '{fieldName}'");

            Facets.Add(new KeyValuePair <string, DocumentFieldFacet>(
                           fieldName,
                           field.Facet));

            if ((values != null && values.Length > 0) ||
                (notValues != null && notValues.Length > 0))
            {
                Selection.Add(new SearchQuerySelection
                {
                    FieldName = fieldName,
                    Values    = values,
                    NotValues = notValues,
                    Operation = field.Facet.FacetType == FacetType.SingleValue
                    ? SearchQuerySelectionOperation.Or
                    : SearchQuerySelectionOperation.And
                });
            }
        }