// Method that loads the required data
        // Called only if the data doesn't already exist in the cache
        private List <UcommerceProductDto> LoadProducts(CacheSettings cs, Category category)
        {
            // Loads all products from this category from the database
            if (category == null)
            {
                return(ConvertToUcommerceProduct(new List <Product>()));
            }

            GetAllProductsRecursive(category);

            var facetsForQuerying = GetFacets();
            var filterProducts    = SearchLibrary.GetProductsFor(category, facetsForQuerying);
            var listOfProducts    = new List <Product>();

            SetCacheDependency(cs, category);

            if (!filterProducts.Any())
            {
                return(ConvertToUcommerceProduct(_products));
            }

            foreach (var product in filterProducts)
            {
                Product filterProduct = _products.FirstOrDefault(x => x.Sku == product.Sku && x.VariantSku == product.VariantSku);
                if (filterProduct != null)
                {
                    listOfProducts.Add(filterProduct);
                }
            }

            return(ConvertToUcommerceProduct(listOfProducts));
        }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            var category = SiteContext.Current.CatalogContext.CurrentCategory;
            var product  = SiteContext.Current.CatalogContext.CurrentProduct;

            if (category == null && product == null && CurrentDocument.NodeAlias == "Catalog")
            {
                category = ObjectFactory.Instance.Resolve <IDefaultCatalogDataProvider>().GetDefaultCategory();
            }

            if (category == null || product != null)
            {
                return;
            }

            IList <Facet> facetsForQuerying = GetFacets();
            IList <Facet> facets            = SearchLibrary.GetFacetsFor(category, facetsForQuerying);

            rptFacets.DataSource = facets;
            rptFacets.DataBind();
            FindChildControlsRecursive(rptFacets);
            EnsureCheckboxesAreChecked();

            if (!_anyFacetHits)
            {
                facetsDiv.Visible = false;
            }
        }
    }
Пример #3
0
        /// <summary>
        /// Main Indexing process starts here.
        /// Step 1: Create an IndexedSiteID for grouping all the upcoming pages
        /// Step 2: Make Recursive call to DoPageIndexing. This will loop on itself.
        ///
        /// </summary>
        /// <param name="pageName"></param>
        /// <returns></returns>
        public JsonResult startPageIndexProcess(string pageName)
        {
            try
            {
                NUMBER_OF_LEVELS = Int16.Parse(ConfigurationManager.AppSettings["HowManyLevels"]);
                string Folder     = SearchLibrary.GetDirectoryForFile(pageName, -1);
                string actualPage = System.IO.Path.GetFileName(pageName);

                //create a record to serve as a groupID  for the site or group of pages to index.
                int siteIndexID = DBSearchResult.GetNewSiteIndex(Folder, actualPage);

                //now save the first page so that the parallel functions have links to use.
                ContentSearchResult csr = SearchLibrary.LoadPageContent(pageName, -1, siteIndexID);
                SearchLibrary.GetLinksAndKeywords(csr);
                csr.PageID = DBSearchResult.SaveSearchResults(csr);

                //now everything is ready to run in a loop until all pages have been indexed.

                return(doPageIndexing(-1, siteIndexID));
            }
            catch (Exception ex)
            {
                MessageLogger.LogThis(ex);
                //Run query to return results.
            }
            return(null);
        }
        private IList <Facet> GetFacetRecursive(Category category, IList <Facet> facetsQuery)
        {
            List <Facet> facets = new List <Facet>();

            foreach (var subCategory in category.Categories)
            {
                var facetsList = GetFacetRecursive(subCategory, facetsQuery);
                if (facetsList != null)
                {
                    facetsList = facetsList.Where(x => x.FacetValues.Any(y => y.Hits > 0)).ToList();
                    if (facetsList.Any())
                    {
                        facets.AddRange(facetsList);
                    }
                }
            }

            var facetListMain = SearchLibrary.GetFacetsFor(category, facetsQuery);

            if (facetListMain.Any())
            {
                facetListMain = facetListMain.Where(x => x.FacetValues.Any(y => y.Hits > 0)).ToList();
                if (facetListMain.Any())
                {
                    facets.AddRange(facetListMain.ToList());
                }
            }

            return(facets);
        }
Пример #5
0
        public void TestSearchGetAllCategoryNames()
        {
            //Arrange
            IEnumerable <string> allCategoryNames = null;

            //Arrange
            const string nodeName = "TheNoodle";
            const string catName  = "TheCat.CatSon";//This will create a Category and Subcategory
            const string descr    = "TheCat";
            const string path     = @"C:\temp\graphics.dyn";

            var guid1        = Guid.NewGuid();
            var dummyInfo1   = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
            var dummySearch1 = new CustomNodeSearchElementTest(null, dummyInfo1);

            var searchLibrary = new SearchLibrary <NodeSearchElement, NodeModel>();

            searchLibrary.Add(dummySearch1);

            //Act
            var root = SearchCategoryUtil.CategorizeSearchEntries(
                searchLibrary.SearchEntries,
                entry => entry.Categories);

            foreach (var category in root.SubCategories)
            {
                allCategoryNames = SearchCategoryUtil.GetAllCategoryNames(category);
            }

            //Assert
            //Just validate that search entries is not null
            Assert.IsNotNull(root);
            //Validate that the GetAllCategoryNames returned at least one element
            Assert.Greater(allCategoryNames.Count(), 0);
        }
        private IList <FacetViewModel> MapFacetsByManualSelection(string categoryIdsString, string productIdsString)
        {
            var categoryIds = categoryIdsString?.Split(',').Select(x => Convert.ToInt32(x)).ToList() ?? new List <int>();
            var productIds  = productIdsString?.Split(',').Select(x => Convert.ToInt32(x)).ToList() ?? new List <int>();

            var facetsResolver    = new FacetResolver(this.queryStringBlackList);
            var facetsForQuerying = facetsResolver.GetFacetsFromQueryString();

            return(this.MapToFacetsViewModel(SearchLibrary.FacetedQuery()
                                             .Where(x => x.CategoryIds.In(categoryIds) || x.Id.In(productIds)).WithFacets(facetsForQuerying).ToFacets().ToList()));
        }
Пример #7
0
        public override void Execute(object parameter)
        {
            var repository       = RepositoryManager.GetRepository(RepositoryManager.Folders);
            var folderRepository = repository.Entries.FirstOrDefault();

            if (folderRepository == null)
            {
                return;
            }

            var databaseUri = DatabaseUri.Empty;
            var searchText  = string.Empty;
            var name        = "Folder";

            do
            {
                var dialog = new SearchDialog(searchText, databaseUri, name);
                if (AppHost.Shell.ShowDialog(dialog) != true)
                {
                    return;
                }

                name        = dialog.SearchName;
                databaseUri = dialog.DatabaseUri ?? DatabaseUri.Empty;
                searchText  = dialog.SearchText;

                if (LibraryManager.Libraries.Any(w => string.Compare(w.Name, name, StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    AppHost.MessageBox(string.Format("A folder with the name '{0}' already exists.\n\nPlease choose another name.", name), "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    break;
                }
            }while (true);

            var fileName = IO.File.GetSafeFileName(name + ".xml");

            fileName = Path.Combine(folderRepository.Path, fileName);

            var folder = new SearchLibrary(fileName, name)
            {
                DatabaseUri = databaseUri,
                SearchText  = searchText
            };

            folder.Save();
            folder.Initialize();

            LibraryManager.Add(folder);

            folder.IsExpanded = true;
            folder.Refresh();
        }
Пример #8
0
        private IList <ProductViewModel> MapProductsInCategories(Category category)
        {
            IList <Facet> facetsForQuerying  = System.Web.HttpContext.Current.Request.QueryString.ToFacets();
            var           productsInCategory = new List <ProductViewModel>();

            foreach (var subcategory in category.Categories)
            {
                productsInCategory.AddRange(MapProductsInCategories(subcategory));
            }

            productsInCategory.AddRange(MapProducts(SearchLibrary.GetProductsFor(category, facetsForQuerying)));

            return(productsInCategory);
        }
Пример #9
0
        /// <summary>
        /// This is the main workhorse which runs recursively.
        /// It will stop once the GoneFarEnough returns a true value for the LimitReached.
        /// LimitReached is in the webconfig. It controls the # of levels to walk/traverse.
        /// The pageName is the current url to index
        /// The ParentID is the ID of the page which contains the link.
        /// The SiteIndexID is the ID assigned to the site or group of related pages which is being indexed
        /// </summary>
        /// <param name="pageName"></param>
        /// <param name="parentID"></param>
        /// <param name="siteIndexID"></param>
        /// <returns></returns>
        public JsonResult doPageIndexing(int parentID, int siteIndexID)
        {
            SearchTotal finalCount;

            try
            {
                //this method runs recursively until the limit is reached.
                ConcurrentBag <ContentSearchResult> searchResults = new ConcurrentBag <ContentSearchResult>();
                // get the links from the saved links
                bool limitReached = DBSearchResult.GoneFarEnough(NUMBER_OF_LEVELS, siteIndexID);
                if (!limitReached)
                {
                    List <LinkedPageData> pageLinksMain = DBSearchResult.GetLinkDataForSiteIndexID(siteIndexID);

                    //put the links into a list so that they can be run in Parallel.
                    Parallel.ForEach(pageLinksMain, (sr) =>
                    {
                        string fullURL          = string.Join("", sr.PageDirectory, sr.PageName);
                        ContentSearchResult csr = SearchLibrary.LoadPageContent(fullURL, sr.ParentID, siteIndexID);
                        searchResults.Add(csr);
                    });

                    // now that all the links have content, do a regular loop for the parsing and saving .
                    foreach (ContentSearchResult csr in searchResults)
                    {
                        SearchLibrary.GetLinksAndKeywords(csr);
                        csr.PageID = DBSearchResult.SaveSearchResults(csr);
                        doPageIndexing(csr.PageID, siteIndexID);
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                MessageLogger.LogThis(ex);
                Server.ClearError();
            }
            catch (Exception ex)
            {
                MessageLogger.LogThis(ex);
                Server.ClearError();
            }
            finally
            {
                finalCount = DBSearchResult.GetIndexedPageTotals(siteIndexID);
            }

            return(Json(finalCount, JsonRequestBehavior.AllowGet));
        }
Пример #10
0
        // GET: Facets
        public ActionResult Index()
        {
            var           category = SiteContext.Current.CatalogContext.CurrentCategory;
            var           facetValueOutputModel = new FacetsDisplayedViewModel();
            IList <Facet> facetsForQuerying     = System.Web.HttpContext.Current.Request.QueryString.ToFacets();

            if (ShouldDisplayFacets(category))
            {
                IList <Facet> facets = SearchLibrary.GetFacetsFor(category, facetsForQuerying);
                if (facets.Any(x => x.FacetValues.Any(y => y.Hits > 0)))
                {
                    facetValueOutputModel.Facets = MapFacets(facets);
                }
            }

            return(View("/Views/PartialView/Facets.cshtml", facetValueOutputModel));
        }
        private IList <FacetViewModel> GetAllFacets(Category category)
        {
            var facetsResolver    = new FacetResolver(this.queryStringBlackList);
            var facetsForQuerying = facetsResolver.GetFacetsFromQueryString();
            IList <UCommerce.Search.Facets.Facet> allFacets;

            if (category != null)
            {
                allFacets = SearchLibrary.GetFacetsFor(category, facetsForQuerying);
            }
            else
            {
                allFacets = SearchLibrary.FacetedQuery()
                            .WithFacets(facetsForQuerying)
                            .ToFacets()
                            .ToList();
            }

            return(this.MapToFacetsViewModel(allFacets));
        }
Пример #12
0
        private IQueryable <Product> ApplyManualSelection(List <int> productIds, List <int> categoryIds)
        {
            var productsQuery = SearchLibrary.FacetedQuery();

            var products = new List <Product>();

            products.AddRange(this.GetProductsFromSelectedCategoryIds(categoryIds));
            products.AddRange(this.GetProductsFromSelectedProductIds(productIds));

            var facetsResolver = new FacetResolver(this.queryStringBlackList);

            List <UCommerce.Documents.Product> productsFromFacets = SearchLibrary.FacetedQuery()
                                                                    .Where(x => x.CategoryIds.In(categoryIds) || x.Id.In(productIds))
                                                                    .WithFacets(facetsResolver.GetFacetsFromQueryString())
                                                                    .ToList();

            if (!productsFromFacets.Any())
            {
                return(products.AsQueryable());
            }

            return(products.Where(x => productsFromFacets.Any(y => x.Sku == y.Sku)).AsQueryable());
        }
Пример #13
0
        private IQueryable <Product> ApplyAutoSelection(Category currentCategory, string searchTerm)
        {
            IList <UCommerce.Documents.Product> products = null;
            var facetsResolver    = new FacetResolver(this.queryStringBlackList);
            var facetsForQuerying = facetsResolver.GetFacetsFromQueryString();

            if (currentCategory == null)
            {
                if (!string.IsNullOrWhiteSpace(searchTerm))
                {
                    var matchingProducts = Product.Find(p =>
                                                        p.VariantSku == null &&
                                                        p.DisplayOnSite &&
                                                        (p.Sku.Contains(searchTerm) ||
                                                         p.Name.Contains(searchTerm) ||
                                                         p.ProductDescriptions.Any(d => d.DisplayName.Contains(searchTerm) || d.ShortDescription.Contains(searchTerm) || d.LongDescription.Contains(searchTerm))));

                    return(matchingProducts.AsQueryable());
                }
                else
                {
                    var catalog = CatalogLibrary.GetAllCatalogs().FirstOrDefault();
                    if (catalog != null)
                    {
                        currentCategory = CatalogLibrary.GetRootCategories(catalog.Id).FirstOrDefault();
                        products        = SearchLibrary.GetProductsFor(currentCategory, facetsForQuerying);
                        if (currentCategory == null)
                        {
                            throw new InvalidOperationException(NO_CATEGORIES_ERROR_MESSAGE);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException(NO_CATALOG_ERROR_MESSAGE);
                    }
                }
            }
            else
            {
                products = SearchLibrary.GetProductsFor(currentCategory, facetsForQuerying);
            }

            ICollection <Product> productsInCategory = null;

            productsInCategory = CatalogLibrary.GetProducts(currentCategory).ToList();

            if (!products.Any())
            {
                return(productsInCategory.AsQueryable());
            }

            var listOfProducts = new List <Product>();

            foreach (var product in products)
            {
                var filterProduct = productsInCategory.FirstOrDefault(x => x.Sku == product.Sku && x.VariantSku == product.VariantSku);
                if (filterProduct != null)
                {
                    listOfProducts.Add(filterProduct);
                }
            }

            return(listOfProducts.AsQueryable());
        }