Exemplo n.º 1
0
            public void AddsPropertyAsRefinement()
            {
                var property = SearchContentProperty.Title;
                var criteria = new KeywordSearchCriteria()
                               .RefineBy(SearchContentProperty.Title);
                var firstRefinement = criteria.Refinement.Items.FirstOrDefault();

                Assert.IsNotNull(firstRefinement);
                Assert.AreEqual(
                    firstRefinement.Property,
                    property);
            }
    private List <ContentType <Attraction> > populateMerchandise(string title, int paging)
    {
        //  IntegerPropertyExpression sfid = new IntegerPropertyExpression(smartFormID);
        //  id = current page id to exclude from query results
        //  parameters = current page query string
        //  title = title of current page
        //  contentBlockId = id of content block on current page to exclude from query results

        IEnumerable <QueryResult> results  = new List <QueryResult>();
        KeywordSearchCriteria     criteria = new KeywordSearchCriteria();

        criteria.QueryText   = title;
        criteria.ImplicitAnd = false;
        criteria.OrderBy     = new List <OrderData>()
        {
            new OrderData(SearchContentProperty.Rank, OrderDirection.Descending)
        };

        criteria.ExpressionTree =
            QueryProperties.Id > 0 &
            QueryProperties.SFID.EqualTo(9);
        criteria.PagingInfo             = new PagingInfo(paging);
        criteria.PagingInfo.CurrentPage = 1;
        criteria.ReturnProperties       = new HashSet <PropertyExpression>()
        {
            SearchContentProperty.Id,
            SearchContentProperty.Title,
            SearchContentProperty.QuickLink,
            SearchContentProperty.Description
        };

        ISearchManager manager = ObjectFactory.GetSearchManager();

        SearchResponseData response = manager.Search(criteria);
        List <ContentType <Attraction> > merchandiseList = new List <ContentType <Attraction> >();

        if (response.Results.Count > 0)
        {
            results = GetResults(response);
            foreach (Content.QueryResult merchandise in results)
            {
                ContentTypeManager <Attraction> contentTypeManagerAttraction = new ContentTypeManager <Attraction>();
                ContentType <Attraction>        cd = contentTypeManagerAttraction.GetItem(merchandise.Id);
                merchandiseList.Add(cd);
            }
        }
        return(merchandiseList);
    }
    private IEnumerable <QueryResult> populateRelatedContent(long id, QueryParams parameters, string title, long contentBlockId, int paging)
    {
        //  IntegerPropertyExpression sfid = new IntegerPropertyExpression(smartFormID);
        //  id = current page id to exclude from query results
        //  parameters = current page query string
        //  title = title of current page
        //  contentBlockId = id of content block on current page to exclude from query results

        IEnumerable <QueryResult> results  = new List <QueryResult>();
        KeywordSearchCriteria     criteria = new KeywordSearchCriteria();

        criteria.QueryText = title;
        criteria.OrderBy   = new List <OrderData>()
        {
            new OrderData(SearchContentProperty.Rank, OrderDirection.Descending)
        };

        criteria.ExpressionTree =
            QueryProperties.Id > 0 &
            QueryProperties.Id != contentBlockId &
            QueryProperties.Id != id&
            QueryProperties.SFID.NotEqualTo(10) &
            QueryProperties.SFID.NotEqualTo(9);

        criteria.PagingInfo             = new PagingInfo(paging);
        criteria.PagingInfo.CurrentPage = 1;
        criteria.ReturnProperties       = new HashSet <PropertyExpression>()
        {
            SearchContentProperty.Id,
            SearchContentProperty.Title,
            SearchContentProperty.QuickLink,
            SearchContentProperty.Description
        };

        ISearchManager manager = ObjectFactory.GetSearchManager();

        SearchResponseData response = manager.Search(criteria);

        if (response.Results.Count > 0)
        {
            results = GetResults(response);
        }
        return(results);
    }
        private void Search()
        {
            string query         = this.txtQuery.Text;
            var    searchManager = new SearchManager();
            var    criteria      = new KeywordSearchCriteria();

            criteria.QueryText = query;
            criteria.OrderBy.Add(new OrderData(SearchContentProperty.Title, OrderDirection.Ascending));
            criteria.ReturnsWith(
                SearchContentProperty.HighlightedSummary,
                SearchContentProperty.Id,
                SearchContentProperty.QuickLink,
                SearchContentProperty.Title);
            var searchResult = searchManager.Search(criteria);

            this.lvResults.DataSource = searchResult.Results;
            this.lvResults.DataBind();
            this.txtQuery.Focus();
        }
Exemplo n.º 5
0
            public void SetsEnableRefinementPropertyToTrue()
            {
                var sut = new KeywordSearchCriteria().EnableRefinement();

                Assert.IsTrue(sut.Refinement.IsEnabled);
            }
Exemplo n.º 6
0
        public void Can_index_product_demo_data_and_search(string providerType)
        {
            var scope    = "test";
            var provider = GetSearchProvider(providerType, scope);

            //if (provider is ElasticSearchProvider)
            //    (provider as ElasticSearchProvider).AutoCommitCount = 1; // commit every one document

            provider.RemoveAll(scope, "");
            var controller = GetSearchIndexController(provider);

            controller.RemoveIndex(scope, CatalogItemSearchCriteria.DocType);
            controller.BuildIndex(scope, CatalogItemSearchCriteria.DocType, x => { return; });


            // sleep for index to be commited
            Thread.Sleep(5000);

            // get catalog id by name
            var catalogRepo = GetCatalogRepository();
            var catalog     = catalogRepo.Catalogs.SingleOrDefault(x => x.Name.Equals("electronics", StringComparison.OrdinalIgnoreCase));

            // find all prodducts in the category
            var catalogCriteria = new CatalogItemSearchCriteria()
            {
                Catalog  = catalog.Id,
                Currency = "USD"
            };

            // Add all filters
            var brandFilter = new AttributeFilter {
                Key = "brand"
            };
            var filter = new AttributeFilter {
                Key = "color", IsLocalized = true
            };

            filter.Values = new[]
            {
                new AttributeFilterValue {
                    Id = "Red", Value = "Red"
                },
                new AttributeFilterValue {
                    Id = "Gray", Value = "Gray"
                },
                new AttributeFilterValue {
                    Id = "Black", Value = "Black"
                }
            };

            var rangefilter = new RangeFilter {
                Key = "size"
            };

            rangefilter.Values = new[]
            {
                new RangeFilterValue {
                    Id = "0_to_5", Lower = "0", Upper = "5"
                },
                new RangeFilterValue {
                    Id = "5_to_10", Lower = "5", Upper = "10"
                }
            };

            var priceRangefilter = new PriceRangeFilter {
                Currency = "USD"
            };

            priceRangefilter.Values = new[]
            {
                new RangeFilterValue {
                    Id = "under-100", Upper = "100"
                },
                new RangeFilterValue {
                    Id = "200-600", Lower = "200", Upper = "600"
                }
            };

            catalogCriteria.Add(filter);
            catalogCriteria.Add(rangefilter);
            catalogCriteria.Add(priceRangefilter);
            catalogCriteria.Add(brandFilter);

            var ibs           = GetItemBrowsingService(provider);
            var searchResults = ibs.SearchItems(scope, catalogCriteria, Domain.Catalog.Model.ItemResponseGroup.ItemLarge);

            Assert.True(searchResults.TotalCount > 0, string.Format("Didn't find any products using {0} search", providerType));
            Assert.True(searchResults.Aggregations.Count() > 0, string.Format("Didn't find any aggregations using {0} search", providerType));

            var colorAggregation = searchResults.Aggregations.SingleOrDefault(a => a.Field.Equals("color", StringComparison.OrdinalIgnoreCase));

            Assert.True(colorAggregation.Items.Where(x => x.Value.ToString().Equals("Red", StringComparison.OrdinalIgnoreCase)).SingleOrDefault().Count == 6);
            Assert.True(colorAggregation.Items.Where(x => x.Value.ToString().Equals("Gray", StringComparison.OrdinalIgnoreCase)).SingleOrDefault().Count == 3);
            Assert.True(colorAggregation.Items.Where(x => x.Value.ToString().Equals("Black", StringComparison.OrdinalIgnoreCase)).SingleOrDefault().Count == 13);

            var brandAggregation = searchResults.Aggregations.SingleOrDefault(a => a.Field.Equals("brand", StringComparison.OrdinalIgnoreCase));

            Assert.True(brandAggregation.Items.Where(x => x.Value.ToString().Equals("Beats By Dr Dre", StringComparison.OrdinalIgnoreCase)).SingleOrDefault().Count == 3);

            var keywordSearchCriteria = new KeywordSearchCriteria(CatalogItemSearchCriteria.DocType)
            {
                Currency = "USD", Locale = "en-us", SearchPhrase = "sony"
            };

            searchResults = ibs.SearchItems(scope, keywordSearchCriteria, Domain.Catalog.Model.ItemResponseGroup.ItemLarge);
            Assert.True(searchResults.TotalCount > 0);
        }