//Tool đội data public List <SolrProductItem> GetListProductNotRootByCompanyAndKeyword(List <string> listIdCompany, string keyword, int categoryId, int offset, int numRows, out int numFound) { var solr = GetSolrOperations(); if (listIdCompany.Count == 0) { numFound = 0; return(new List <SolrProductItem>()); } // var blackListProductDataAccess = new BlackListProductDataAccess(); //cmt 24.1.2017 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) && categoryId == 0) { 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, OrderBy = new List <SortOrder>() { new SortOrder("view_count") } }); } else if (!string.IsNullOrEmpty(keyword) && categoryId == 0) { 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, OrderBy = new List <SortOrder>() { new SortOrder("view_count", Order.DESC) } }); } else if (string.IsNullOrEmpty(keyword) && categoryId != 0) { AbstractSolrQuery query = new SolrQuery("root_id:0") && new SolrQuery("product_type:2") && new SolrQueryInList("merchant_id", listIdCompany) && new SolrQueryByField("category_level_2_id", categoryId.ToString()); if (listIdBlockString.Count > 0) { query = query && new SolrNotQuery(new SolrQueryInList("id", listIdBlockString)); } queryResult = solr.Query(query, new QueryOptions { Start = offset, Rows = numRows, OrderBy = new List <SortOrder>() { new SortOrder("view_count", Order.DESC) } }); } else if (!string.IsNullOrEmpty(keyword) && categoryId != 0) { 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(queryString) && new SolrQuery("root_id:0") && new SolrQuery("product_type:2") && new SolrQueryInList("merchant_id", listIdCompany) && new SolrQueryByField("category_level_2_id", categoryId.ToString()); if (listIdBlockString.Count > 0) { query = query && new SolrNotQuery(new SolrQueryInList("id", listIdBlockString)); } queryResult = solr.Query(query, new QueryOptions { Start = offset, Rows = numRows, OrderBy = new List <SortOrder>() { new SortOrder("view_count", Order.DESC) } }); } numFound = queryResult.NumFound; var result = queryResult.ToList(); return(result); }
//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); }