Introduction
The Catalog Search API provides the functionality needed for finding products in the ECF using a variety of methods.
There are two distinct APIs that provide search functionality and each one of them offers unique capabilities. One is based on SQL Server Full Text Search (FTS) feature and the other one is based on the Lucene .NET Engine (LS - Lucene Search). The FTS API should be familiar to our early adopters and somewhat familiar to users of previous generations of the ECF.
The Catalog Search API as a whole is used to accomplish the following functionality:
- Browsing catalog/categories
- Performing site-wide searches by keywords
- Guided search
- Browsing by brand, price and any other meta fields
Lucene Search
Lucene.NET is a powerful search engine that is used by a number of popular sites with large amounts of data to index. Some examples are Wikipedia, CNet, Monster, Apple, and FedEx. Lucene.NET was originally created using Java. However, the Lucene engine was later built from the ground up using .NET. Here are some of the capabilities of the search engine:
- Supports full text search indexing
- Ranked search results
- Different query types available – e.g. phrase queries
- Supports searching by field
- Supports numeric value range searches
- Supports date range searches
- "Did you mean" functionality to provide user with corrected search terms
Lucene.NET is a framework library, not a stand-alone application. It is integrated into ECF, which provides an API wrapper around the Lucene.NET search engine and several controls that are examples of how to use that API.
Advantages:
- Very fast search with capability to do counts and filters
- Allows controlling indexing and searching process
- Open Source architecture
Drawbacks:
- Have to manually update indexes
- Have to come up with workarounds for multi server environments
- Uses it's own query language
Primary Use: This API is used mostly on the frontend to provide more advanced functionality for the user.
Examples
Simple Catalog Entry Search
The SearchPhrase property can contain full Lucene Syntax like: title:"The Right Way" AND text:go. Please consult lucene documentation for more details on Query Parser Syntax.
Catalog Entry Fuzzy Search
In this example the results will be returned using fuzzy search, where approximate results will be returned. In this case it will be very similar to the previous example where we searched for "canon".
Catalog Entry Search with paging
This example shows how to return real Catalog Entries from the search API which can be used to bind directly to the Web Controls like grid.
Full Text Search
Advantages:
- Provides up to date data queries that are directly integrated with a SQL Server
- Data is automatically repopulated and managed by SQL Server
- There are native TSQL commands to manipulate the FTS catalogs
Drawbacks:
- Slow and does not provide ways to optimize indexing
- Does not include functionality like fuzzy or proximity search or makes it hard to use such functionality
Primary Use: This API is used mostly on the backend where performance is not that critical.
Optimization
Catalog Search uses SQL Server Full Text Search capability out of the box to optimize search requests. Other Search products can be used to compliment this default out of the box functionality and will be beneficial for large scale commerce sites.
Caching
The search API has a very flexible caching mechanism which allows developer to control how caching is handled by the search. A developer can specify whether or not results should be cached and the specific amount of time they should be cached. The properties are CacheResults (bool) and CacheTimeout (TimeSpan). You would generally want to cache simple search requests like browsing major categories. Since these requests will be the same for a large audience, it will benefit the performance of the site. On the other hand, you might not want to cache specific keyword searches, since those will be unique to a user and have a smaller chance of benefiting through caching.
You can change caching on the public site by going to the ecf.catalog.config file in your \PublicLayer\SDKs\B2CSampleSite\Configs folder and changing appropriate values in the <Cache/> element.
Response Groups
Response groups are another way to make sure the site is performing to the maximum. When searching for entries/products in ECF you can specify the response groups that should be returned. The search will be perfrom the best with a smallest number of response groups returned.
Examples
Browsing Catalogs
The following is an example of browsing catalogs and categories.
Searching by Keyword
The following example shows how to search catalogs using the specified keyword.
Advanced Keyword Search
This example shows how to search catalogs using more advanced queries. You can specify additional parameters like "near". The tables are searched using the Full Text Search "ContainsTable" function. For more information refer to CONTAINSTABLE (Transact-SQL).
Join Table Search
The Catalog API allows joining additional tables, queries or views to the search query. This allows further customizations to the search without any modifications to the core framework. For example if you want to sort by meta fields you can join the specific meta table and you will be able to specify fields from meta table in your order by statements. The example below orders entries by DisplayName.
Searching on Metafield Values with Results Displaying via the API
Note: Make sure all of your meta fields are searchable when you create them.
Here is a code sample: