Esempio n. 1
0
        public List<int> Get(Query searchQuery)
        {
            var indexSearcher = _productSearcher.IndexSearcher;
            var name = FieldDefinition.GetFieldName<ProductSearchCategoriesDefinition>();
            var valueCollector = new ValueCollector(indexSearcher, name);
            indexSearcher.Search(searchQuery, valueCollector);
            var categoryIds = valueCollector.Values[name].Select(s => Convert.ToInt32(s)).Distinct().ToList();

            if (!categoryIds.Any())
                return categoryIds;

            var mainQuery = new BooleanQuery();
            var idsQuery = new BooleanQuery();
            const string idFieldName = "id";
            foreach (var categoryId in categoryIds)
            {
                idsQuery.Add(new TermQuery(new Term(idFieldName, categoryId.ToString())), Occur.SHOULD);
            }
            mainQuery.Add(idsQuery, Occur.MUST);

            var publishedOn = FieldDefinition.GetFieldName<PublishedOnFieldDefinition>();
            mainQuery.Add(new TermRangeQuery(
                                           publishedOn, null,
                                           DateTools.DateToString(CurrentRequestData.Now, DateTools.Resolution.SECOND), false, true), Occur.MUST);
            var webpageSearcher = _indexSearcher.IndexSearcher;
            var webpageValueCollector = new ValueCollector(webpageSearcher, idFieldName);
            webpageSearcher.Search(mainQuery, null, webpageValueCollector);

            return webpageValueCollector.Values[idFieldName].Select(s => Convert.ToInt32(s))
                .Intersect(categoryIds)
                .ToList();
        }
 public List<OptionInfo> GetOptions(ProductSearchQuery query)
 {
     var clone = query.Clone() as ProductSearchQuery;
     IndexSearcher indexSearcher = _productSearcher.IndexSearcher;
     var valueCollector = new ValueCollector(indexSearcher,
         FieldDefinition.GetFieldName<ProductSearchOptionsDefinition>());
     indexSearcher.Search(GetQuery(clone), valueCollector);
     return GetOptionInfo(valueCollector);
 }
 private List <OptionInfo> GetOptionInfo(ValueCollector valueCollector)
 {
     return
         (valueCollector.Values[FieldDefinition.GetFieldName <ProductSearchOptionsDefinition>()].Select(
              GetOptionInfo)
          .Where(info => !info.Equals(default(OptionInfo)))
          .Distinct()
          .ToList());
 }
        public OptionSearchData GetOptionSearchData(ProductSearchQuery query)
        {
            ValueCollector optionValueCollector = GetOptionValueCollector(query);

            return(new OptionSearchData
            {
                Options = GetOptionInfo(optionValueCollector),
                Specifications = GetSpecifications(optionValueCollector)
            });
        }
        public List <OptionInfo> GetOptions(ProductSearchQuery query)
        {
            var           clone          = query.Clone() as ProductSearchQuery;
            IndexSearcher indexSearcher  = _productSearcher.IndexSearcher;
            var           valueCollector = new ValueCollector(indexSearcher,
                                                              FieldDefinition.GetFieldName <ProductSearchOptionsDefinition>());

            indexSearcher.Search(GetQuery(clone), valueCollector);
            return(GetOptionInfo(valueCollector));
        }
        private ValueCollector GetOptionValueCollector(ProductSearchQuery query)
        {
            var clone = query.Clone() as ProductSearchQuery;
            //clone.Options = new List<string>();
            IndexSearcher indexSearcher  = _productSearcher.IndexSearcher;
            var           valueCollector = new ValueCollector(indexSearcher,
                                                              FieldDefinition.GetFieldName <ProductSearchSpecificationsDefinition>(),
                                                              FieldDefinition.GetFieldName <ProductSearchOptionsDefinition>());

            indexSearcher.Search(GetQuery(clone), valueCollector);
            return(valueCollector);
        }
        public List <int> GetBrands(ProductSearchQuery query)
        {
            var clone = query.Clone() as ProductSearchQuery;

            clone.BrandId = null;
            IndexSearcher indexSearcher  = _productSearcher.IndexSearcher;
            string        name           = FieldDefinition.GetFieldName <ProductSearchBrandDefinition>();
            var           valueCollector = new ValueCollector(indexSearcher, name);

            indexSearcher.Search(GetQuery(clone), valueCollector);
            return
                (valueCollector.Values[name].Where(x => !string.IsNullOrEmpty(x))
                 .Select(s => Convert.ToInt32(s))
                 .Distinct()
                 .ToList());
        }
        public List <int> Get(Query searchQuery)
        {
            var indexSearcher  = _productSearcher.IndexSearcher;
            var name           = FieldDefinition.GetFieldName <ProductSearchCategoriesDefinition>();
            var valueCollector = new ValueCollector(indexSearcher, name);

            indexSearcher.Search(searchQuery, valueCollector);
            var categoryIds = valueCollector.Values[name].Select(s => Convert.ToInt32(s)).Distinct().ToList();

            if (!categoryIds.Any())
            {
                return(categoryIds);
            }

            var          mainQuery   = new BooleanQuery();
            var          idsQuery    = new BooleanQuery();
            const string idFieldName = "id";

            foreach (var categoryId in categoryIds)
            {
                idsQuery.Add(new TermQuery(new Term(idFieldName, categoryId.ToString())), Occur.SHOULD);
            }
            mainQuery.Add(idsQuery, Occur.MUST);

            var publishedOn = FieldDefinition.GetFieldName <PublishedOnFieldDefinition>();

            mainQuery.Add(new TermRangeQuery(
                              publishedOn, null,
                              DateTools.DateToString(CurrentRequestData.Now, DateTools.Resolution.SECOND), false, true), Occur.MUST);
            var webpageSearcher       = _indexSearcher.IndexSearcher;
            var webpageValueCollector = new ValueCollector(webpageSearcher, idFieldName);

            webpageSearcher.Search(mainQuery, null, webpageValueCollector);

            return(webpageValueCollector.Values[idFieldName].Select(s => Convert.ToInt32(s))
                   .Intersect(categoryIds)
                   .ToList());
        }
 public List<int> GetBrands(ProductSearchQuery query)
 {
     var clone = query.Clone() as ProductSearchQuery;
     clone.BrandId = null;
     IndexSearcher indexSearcher = _productSearcher.IndexSearcher;
     string name = FieldDefinition.GetFieldName<ProductSearchBrandDefinition>();
     var valueCollector = new ValueCollector(indexSearcher, name);
     indexSearcher.Search(GetQuery(clone), valueCollector);
     return
         valueCollector.Values[name].Where(x => !string.IsNullOrEmpty(x))
             .Select(s => Convert.ToInt32(s))
             .Distinct()
             .ToList();
 }
 private ValueCollector GetOptionValueCollector(ProductSearchQuery query)
 {
     var clone = query.Clone() as ProductSearchQuery;
     //clone.Options = new List<string>();
     IndexSearcher indexSearcher = _productSearcher.IndexSearcher;
     var valueCollector = new ValueCollector(indexSearcher,
         FieldDefinition.GetFieldName<ProductSearchSpecificationsDefinition>(),
         FieldDefinition.GetFieldName<ProductSearchOptionsDefinition>());
     indexSearcher.Search(GetQuery(clone), valueCollector);
     return valueCollector;
 }
 private List<OptionInfo> GetOptionInfo(ValueCollector valueCollector)
 {
     return
         valueCollector.Values[FieldDefinition.GetFieldName<ProductSearchOptionsDefinition>()].Select(
             GetOptionInfo)
             .Where(info => !info.Equals(default(OptionInfo)))
             .Distinct()
             .ToList();
 }
 private static List<int> GetSpecifications(ValueCollector valueCollector)
 {
     return
         valueCollector.Values[FieldDefinition.GetFieldName<ProductSearchSpecificationsDefinition>()].Select(
             s => Convert.ToInt32(s)).Distinct().ToList();
 }
 private static List <int> GetSpecifications(ValueCollector valueCollector)
 {
     return
         (valueCollector.Values[FieldDefinition.GetFieldName <ProductSearchSpecificationsDefinition>()].Select(
              s => Convert.ToInt32(s)).Distinct().ToList());
 }