Пример #1
0
        public void FacetOptions_ParseSuperDeepNestedWithSize()
        {
            var options = FacetOptions.Parse("test1:1(test1-1:11(test1-1-1:111,test1-1-2:112),test1-2:12),test2:2");

            Assert.NotNull(options);
            Assert.Equal(2, options.Fields.Count);
            var firstField  = options.Fields[0];
            var secondField = options.Fields[1];

            Assert.Equal("test1", firstField.Field);
            Assert.Equal(1, firstField.Size);
            Assert.Equal("test2", secondField.Field);
            Assert.Equal(2, secondField.Size);

            var level1 = firstField.Nested;

            Assert.NotNull(level1);
            Assert.Equal(2, level1.Fields.Count);

            Assert.Equal("test1-1", level1.Fields[0].Field);
            Assert.Equal(11, level1.Fields[0].Size);
            Assert.Equal("test1-2", level1.Fields[1].Field);
            Assert.Equal(12, level1.Fields[1].Size);

            var level2 = level1.Fields[0].Nested;

            Assert.NotNull(level2);
            Assert.Equal(2, level2.Fields.Count);

            Assert.Equal("test1-1-1", level2.Fields[0].Field);
            Assert.Equal(111, level2.Fields[0].Size);
            Assert.Equal("test1-1-2", level2.Fields[1].Field);
            Assert.Equal(112, level2.Fields[1].Size);
        }
 public static T WithFacets <T>(this T query, FacetOptions facets) where T : IFacetQuery
 {
     if (facets != null)
     {
         query.FacetFields?.AddRange(facets.Fields);
     }
     return(query);
 }
Пример #3
0
        public void FacetOptions_ParseSimple()
        {
            var options = FacetOptions.Parse("test");

            Assert.NotNull(options);
            Assert.Equal(1, options.Fields.Count);
            Assert.Equal("test", options.Fields[0].Field);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="facetOptions"></param>
        /// <returns></returns>
        public virtual IQueryable <T> ApplyFacets <T>(IQueryable <T> queryable, FacetOptions facetOptions) where T : SearchResultItem
        {
            if (facetOptions != null && facetOptions.Facets.Any())
            {
                queryable = facetOptions.Facets.Aggregate(queryable, (current, facet) => facet.AddFacet(current));
            }

            return(queryable);
        }
Пример #5
0
        public void FacetOptions_ShouldTrim()
        {
            var options = FacetOptions.Parse("  test ,       test2 ");

            Assert.NotNull(options);
            Assert.Equal(2, options.Fields.Count);
            Assert.Equal("test", options.Fields[0].Field);
            Assert.Equal("test2", options.Fields[1].Field);
        }
        public Task <ICollection <FacetResult> > GetFacetsAsync(string systemFilter, FacetOptions facets, string userFilter = null, string query = null)
        {
            var search = new ElasticQuery()
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithSearchQuery(query, false)
                         .WithFacets(facets);

            return(GetFacetsAsync(search));
        }
Пример #7
0
        public void FacetOptions_ParseSimple2FieldsWithSize()
        {
            var options = FacetOptions.Parse("test:1,test2:2");

            Assert.NotNull(options);
            Assert.Equal(2, options.Fields.Count);
            Assert.Equal("test", options.Fields[0].Field);
            Assert.Equal(1, options.Fields[0].Size);
            Assert.Equal("test2", options.Fields[1].Field);
            Assert.Equal(2, options.Fields[1].Size);
        }
Пример #8
0
        public void FacetOptions_ParseSingleNested()
        {
            var options = FacetOptions.Parse("test(test2)");

            Assert.NotNull(options);
            Assert.Equal(1, options.Fields.Count);
            Assert.Equal("test", options.Fields[0].Field);
            Assert.NotNull(options.Fields[0].Nested);
            Assert.Equal(1, options.Fields[0].Nested.Fields.Count);
            Assert.Equal("test2", options.Fields[0].Nested.Fields[0].Field);
        }
Пример #9
0
        public void FacetBuilder_ForAddingByNullFacetOn_ShouldThrowException()
        {
            // Arrange
            var options      = new FacetOptions();
            var facetBuilder = new FacetBuilder <TestSearchResultItem>(options);

            // Act
            facetBuilder.On((FacetOn)null);

            // Assert
        }
Пример #10
0
        public void FacetBuilder_ForAddingByEmptyString_ShouldNotAdd()
        {
            // Arrange
            var options      = new FacetOptions();
            var facetBuilder = new FacetBuilder <TestSearchResultItem>(options);

            // Act
            facetBuilder.On(String.Empty);

            // Assert
            Assert.IsTrue(options.Facets.Count == 0);
        }
Пример #11
0
        public void FacetBuilder_ForAddingByExpression_ShouldAddByIndexField()
        {
            // Arrange
            var options      = new FacetOptions();
            var facetBuilder = new FacetBuilder <TestSearchResultItem>(options);

            // Act
            facetBuilder.On(result => result.Content);

            // Assert
            Assert.IsTrue(options.Facets.Any(f => f.Key == "_content"));
        }
Пример #12
0
        public void FacetBuilder_ForAddingByString_ShouldAddByString()
        {
            // Arrange
            var options      = new FacetOptions();
            var facetBuilder = new FacetBuilder <TestSearchResultItem>(options);

            // Act
            facetBuilder.On("_content");

            // Assert
            Assert.IsTrue(options.Facets.Any(f => f.Key == "_content"));
        }
Пример #13
0
        public void FacetBuilder_ForAddingByListOfExpressionsWithNull_ShouldThrowException()
        {
            // Arrange
            var options      = new FacetOptions();
            var facetBuilder = new FacetBuilder <TestSearchResultItem>(options);

            // Act
            facetBuilder.On(result => result.Content,
                            result => null, // Throw Exception
                            result => result.TestingFacetKey);

            // Assert
        }
Пример #14
0
        public FacetOptions GetOptions(JsonOperationContext context, BlittableJsonReaderObject parameters)
        {
            if (_options != null)
            {
                return(_options);
            }

            if (_optionsAsStringOrParameterName == null)
            {
                return(null);
            }

            BlittableJsonReaderObject optionsJson;

            if (_optionsType == AST.ValueTokenType.Parameter)
            {
                if (parameters == null)
                {
                    throw new ArgumentNullException(nameof(parameters));
                }

                if (parameters.TryGetMember(_optionsAsStringOrParameterName, out var optionsObject) == false)
                {
                    throw new InvalidOperationException($"Parameter '{_optionsAsStringOrParameterName}' containing '{nameof(FacetOptions)}' was not present in the list of parameters.");
                }

                optionsJson = optionsObject as BlittableJsonReaderObject;

                if (optionsJson == null)
                {
                    throw new InvalidOperationException($"Parameter '{_optionsAsStringOrParameterName}' should contain JSON object.");
                }
            }
            else if (_optionsType == AST.ValueTokenType.String)
            {
                optionsJson = IndexReadOperation.ParseJsonStringIntoBlittable(_optionsAsStringOrParameterName, context);
            }
            else
            {
                throw new InvalidOperationException($"Unknown options type '{_optionsType}'.");
            }

            var options = (FacetOptions)EntityToBlittable.ConvertToEntity(typeof(FacetOptions), "facet/options", optionsJson, DocumentConventions.Default);

            if (_optionsType == AST.ValueTokenType.String)
            {
                _options = options;
            }

            return(options);
        }
Пример #15
0
        public void FacetBuilder_ForAddingByListOfExpressions_ShouldAddByIndexField()
        {
            // Arrange
            var options      = new FacetOptions();
            var facetBuilder = new FacetBuilder <TestSearchResultItem>(options);

            // Act
            facetBuilder.On(result => result.Content, result => result.TemplateName, result => result.TestingFacetKey);

            // Assert
            Assert.IsTrue(options.Facets.Any(f => f.Key == "_content"));
            Assert.IsTrue(options.Facets.Any(f => f.Key == "_templatename"));
            Assert.IsTrue(options.Facets.Any(f => f.Key == "testingfacetkey"));
        }
Пример #16
0
        public void FacetOptions_ParseSingleNested2()
        {
            var options = FacetOptions.Parse("geo_country(geo_level1,test2),test3");

            Assert.NotNull(options);
            Assert.Equal(2, options.Fields.Count);
            var firstField  = options.Fields[0];
            var secondField = options.Fields[1];

            Assert.Equal("geo_country", firstField.Field);
            Assert.Equal("test3", secondField.Field);

            var nestedOptions = firstField.Nested;

            Assert.NotNull(nestedOptions);
            Assert.Equal(2, nestedOptions.Fields.Count);

            Assert.Equal("geo_level1", nestedOptions.Fields[0].Field);
            Assert.Equal("test2", nestedOptions.Fields[1].Field);
        }
Пример #17
0
        public FacetOptions GetOptions(JsonOperationContext context, BlittableJsonReaderObject parameters)
        {
            if (_options != null)
            {
                return(_options);
            }

            if (_optionsAsStringOrParameterName == null)
            {
                return(null);
            }

            var options = FieldOptionsHelper.GetOptions <FacetOptions>(_optionsAsStringOrParameterName, _optionsType, parameters, context);

            if (_optionsType == AST.ValueTokenType.String)
            {
                _options = options;
            }

            return(options);
        }
        public Task <FindResults <T> > GetBySearchAsync(string systemFilter, string userFilter = null, string query = null, SortingOptions sorting = null, PagingOptions paging = null, FacetOptions facets = null)
        {
            var search = new ElasticQuery()
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithSearchQuery(query, false)
                         .WithFacets(facets)
                         .WithSort(sorting)
                         .WithPaging(paging);

            return(FindAsync(search));
        }
 public FacetBuilder(FacetOptions facetOptions)
 {
     this.FacetOptions = facetOptions;
 }
Пример #20
0
 /// <summary>
 /// Creates a new instance of the <see cref="FacetsOptionsBuilder"/> class.
 /// </summary>
 /// <param name="options">The options to be built.</param>
 internal FacetsOptionsBuilder(FacetOptions options)
 {
     _options = options;
 }