Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Migrating SearchLibrary

In favor of the old SearchLibrary powered by RavenDB we've introduced a new and updated API that serves for everything - including search.

This means that there's no corresponding SearchLibrary introduced in V9 even though the old is removed. Fear not. There's a way forward that help you achieve even more awesome search capabilities.

This article covers how you can port your code 1-1 with the new search index.

Previously you'd have the ability to use SearchLibrary and associated methods with it's static API like so:

    
    
        UCommerce.Api.SearchLibrary.GetFacetsFor(category, facets);
    
    

The new Search API does not come with a static accessor in favor of utilizing the IOC container more explicitly. The code below highlights how to get an instance of the new Index.

To make it easier We've also introduced a new CatalogLibrary that help you find facets for your product listings.

    Ucommerce.Search.IIndex<Ucommerce.Search.Models.Product> productIndex = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndex<Ucommerce.Search.Models.Product>>();
    
    Ucommerce.Api.ICatalogLibrary catalogLibrary = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.Api.ICatalogLibrary>();
    
    

Facets

    
    
        IList<Facet> facets = UCommerce.Api.SearchLibrary.GetFacetsFor(category, userSelectedFacets);
        IList<UCommerce.Documents.Product> products = UCommerce.Api.SearchLibrary.GetProductsFor(category, facets);
    
    

Previously the code above allowed you to get a combination of the products and the facets. This has been replaced with a single call that gives you both things in one go.

    Ucommerce.Search.Models.Category category = catalogLibrary.GetCategory();
    
    FacetDictionary facetDictionary = new Ucommerce.Search.Facets.FacetDictionary();
    facetDictionary["color"] = new[] {"red", "blue"};
    
    FacetResultSet<Product> products = productIndex
        .Find<Ucommerce.Search.Models.Product>()
        .Where(x => x.Categories.Contains(category.Guid))
        .Where(facetDictionary).ToFacets();
    
    

Products by name

    
    
        IList<Product> products = UCommerce.Api.SearchLibrary.GetProductsByName(productName)
    
    

If you want to search products by name you can either search with literals or with fuzzy search:

    ResultSet<Product> productsByLiteral = productIndex
        .Find<Ucommerce.Search.Models.Product>()
        .Where(x => x.Name == "lietral").ToList();
    
    ResultSet<Product> productsByFuzzy = productIndex
        .Find<Ucommerce.Search.Models.Product>()
        .Where(x => x.Name == Match.Fuzzy("name", 1))
        .ToList();
    
    

Suggestions

Unfortunately Suggestions have been removed in v 9.0 in favor of a faster release date. This is on the road map and will arrive in a later version.

FacetedQueryable

The most generic part of the SearchLibrary was IFacetedQueryable which gave you the ability to narrow down products by your own criteria. The equivalent of this is to simply use the Find method on the index giving you the ISearch interface which offers the same power and flexibility.

Please visit The new Search API for a complete list of things you can achieve.