예제 #1
0
        public List <FacetCategoryLv2Info> GetListCategoryProductByKeyword(List <string> keywords, List <string> keywordsBlock, List <string> listIdBlock,
                                                                           long minPrice, long maxPrice, int offset, int numRows, out int numFound)
        {
            var solr = GetSolrOperations();
            var normalizedKeyword =
                keywords.Select(SolrUtils.NormalizeToExactQuery).Where(x => !string.IsNullOrEmpty(x)).ToArray();

            if (normalizedKeyword.Length == 0)
            {
                numFound = 0;
                return(new List <FacetCategoryLv2Info>());
            }
            var queryString = "name:(" + string.Join(") OR (", normalizedKeyword) + ")";

            var    normalizedKeywordsBlock = keywordsBlock.Select(SolrUtils.NormalizeToExactQuery).Where(x => !string.IsNullOrEmpty(x)).ToArray();
            string queryString2            = string.Empty;

            if (normalizedKeywordsBlock.Length > 0)
            {
                queryString2 = "-name:((*" + string.Join("*)*OR*(*", normalizedKeywordsBlock) + "*))";
            }
            string queryString3 = string.Empty;

            if (minPrice > 0 && maxPrice > 0)
            {
                queryString3 = "price:[" + minPrice + " TO " + maxPrice + "]";
            }
            else if (minPrice > 0 && maxPrice == 0)
            {
                queryString3 = "price:[" + minPrice + " TO *]";
            }
            else if (minPrice > 0 && maxPrice == 0)
            {
                queryString3 = "price:[* TO " + maxPrice + "]";
            }


            SolrQueryResults <SolrProductItem> queryResult;

            if (listIdBlock.Count > 0)
            {
                queryResult = solr.Query(
                    new SolrQuery(queryString) && new SolrQuery("product_type:2") && new SolrQuery(queryString2) && new SolrQuery(queryString3) &&
                    new SolrNotQuery(new SolrQueryInList("id", listIdBlock)), new QueryOptions
                {
                    Start = offset,
                    Rows  = numRows,
                    Facet = new FacetParameters
                    {
                        Queries = new[]
                        {
                            new SolrFacetFieldQuery("category_level_2_id")
                            {
                                Limit    = 100,
                                MinCount = 1
                            }
                        }
                    }
                });
            }
            else
            {
                queryResult = solr.Query(
                    new SolrQuery(queryString) && new SolrQuery("product_type:2") && new SolrQuery(queryString2) && new SolrQuery(queryString3),
                    new QueryOptions
                {
                    Start = offset,
                    Rows  = numRows,
                    Facet = new FacetParameters
                    {
                        Queries = new[]
                        {
                            new SolrFacetFieldQuery("category_level_2_id")
                            {
                                Limit    = 100,
                                MinCount = 1
                            }
                        }
                    }
                });
            }
            numFound = queryResult.NumFound;
            var facetResult1 = new List <FacetCategoryLv2Info>();

            foreach (var facet in queryResult.FacetFields["category_level_2_id"])
            {
                if (facet.Key == "0")
                {
                    continue;
                }
                else
                {
                    facetResult1.Add(new FacetCategoryLv2Info()
                    {
                        CategoryId        = Common.Obj2Int(facet.Key),
                        CategoryName      = WssCommon.GetNameCategoryById(Common.Obj2Int(facet.Key)),
                        CountProductInCat = facet.Value
                    });
                }
            }
            return(facetResult1);
        }
예제 #2
0
        //Tool đội data
        public List <FacetCategoryLv2Info> GetListCategoryProductNotRootByCompanyAndKeyword(List <string> listIdCompany, string keyword, int offset, int numRows, out int numFound)
        {
            var solr = GetSolrOperations();

            if (listIdCompany.Count == 0)
            {
                numFound = 0;
                return(new List <FacetCategoryLv2Info>());
            }
            //
            var blackListProductDataAccess = new BlackListProductDataAccess();
            //24.1.2017 cmt de ra tet fix
            //var listIdBlock = blackListProductDataAccess.GetBlackListProducts();
            //var listIdBlockString = listIdBlock.Select(id => id.ToString()).ToList();
            var listIdBlockString = new List <string>();
            //
            SolrQueryResults <SolrProductItem> queryResult = new SolrQueryResults <SolrProductItem>();

            if (string.IsNullOrEmpty(keyword))
            {
                AbstractSolrQuery query = new SolrQuery("root_id:0") && new SolrQuery("product_type:2") && new SolrQueryInList("merchant_id", listIdCompany);
                if (listIdBlockString.Count > 0)
                {
                    query = query && new SolrNotQuery(new SolrQueryInList("id", listIdBlockString));
                }
                queryResult = solr.Query(query, new QueryOptions
                {
                    Start = offset,
                    Rows  = numRows,
                    Facet = new FacetParameters
                    {
                        Queries = new[]
                        {
                            new SolrFacetFieldQuery("category_level_2_id")
                            {
                                Limit    = 100,
                                MinCount = 1
                            }
                        }
                    },
                    OrderBy = new List <SortOrder>()
                    {
                        new SortOrder("view_count", Order.DESC)
                    }
                });
            }
            else
            {
                var keywords          = keyword.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var normalizedKeyword =
                    keywords.Select(SolrUtils.NormalizeToExactQuery).Where(x => !string.IsNullOrEmpty(x)).ToArray();
                var queryString = "name:(" + string.Join(") OR (", normalizedKeyword) + ")";

                AbstractSolrQuery query = new SolrQuery("root_id:0") && new SolrQuery(queryString) && new SolrQuery("product_type:2") && new SolrQueryInList("merchant_id", listIdCompany);
                if (listIdBlockString.Count > 0)
                {
                    query = query && new SolrNotQuery(new SolrQueryInList("id", listIdBlockString));
                }
                queryResult = solr.Query(query, new QueryOptions
                {
                    Start = offset,
                    Rows  = numRows,
                    Facet = new FacetParameters
                    {
                        Queries = new[]
                        {
                            new SolrFacetFieldQuery("category_level_2_id")
                            {
                                Limit    = 100,
                                MinCount = 1
                            }
                        }
                    },
                    OrderBy = new List <SortOrder>()
                    {
                        new SortOrder("view_count", Order.DESC)
                    }
                });
            }
            numFound = queryResult.NumFound;
            var facetResult1 = new List <FacetCategoryLv2Info>();

            foreach (var facet in queryResult.FacetFields["category_level_2_id"])
            {
                if (facet.Key == "0")
                {
                    continue;
                }
                //facetResult1.Add(new FacetCategoryLv2Info()
                //{
                //    CategoryId = Common.Obj2Int(facet.Key),
                //    CategoryName = "Khác",
                //    CountProductInCat = facet.Value
                //});
                else
                {
                    facetResult1.Add(new FacetCategoryLv2Info()
                    {
                        CategoryId        = Common.Obj2Int(facet.Key),
                        CategoryName      = WssCommon.GetNameCategoryById(Common.Obj2Int(facet.Key)),
                        CountProductInCat = facet.Value
                    });
                }
            }
            return(facetResult1);
        }