Hi Carl,
If you create a custom catalog index builder, you can add any fields to the Lucene index
public class CustomCatalogIndexBuilder : CatalogIndexBuilder
{
/// <summary>
/// Called when catalog entry is indexed. Override this method to add some extra fields.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="entry">The entry.</param>
/// <param name="language"></param>
protected override void OnCatalogEntryIndex(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language)
{
// add the fields to be indexed
document.Add(new SearchField("isactive", entry.IsActive));
base.OnCatalogEntryIndex(ref document, entry, language);
}
}
Having said that, the "Code" column is in the Lucene search index by default.
Try running Luke and check if it's being properly populated in your index:
Code is in the index. I've verified that with Luke.
Consider the admin UI: http://webhelp.episerver.com/Commerce/1.1.2/Default.htm#CSHID=undefined
If I enter the a code in the "Search by keywords" box: I get no hits.
If I enter a code in "Search by Code" i get the corresponding hit.
I want to have one search box on the user web page, where I can write either keywords or a product code. Of course I could always just get the item by the code from CatalogContext, however the search page is populated from a CatalogIndexSearchDataSource and I would like to have the product code hits added (union) to the same datasource before returning it to the page.
I was hoping I could instruct the search parameters to include the code.
Here's my current solution that I was hoping to obsolete:
//Normal search up to here
dataSource = new CatalogIndexSearchDataSource(); dataSource.TotalResults = count; dataSource.CatalogEntries = entries;
//Add product code hits if (!string.IsNullOrWhiteSpace(keywords)) { //Add product code hits: List<Mediachase.Commerce.Catalog.Objects.Entry> productCodeHits = new List<Mediachase.Commerce.Catalog.Objects.Entry>(); foreach (string keyword in keywords.Split(' ')) { Mediachase.Commerce.Catalog.Objects.Entry entry = CatalogContext.Current.GetCatalogEntry(keyword); if (null != entry) { productCodeHits.Add(entry); } } if (0 == dataSource.TotalResults) { entries.Entry = productCodeHits.ToArray(); } else { entries.Entry = entries.Entry.Union(productCodeHits).ToArray(); } dataSource.TotalResults += productCodeHits.Count; dataSource.CatalogEntries = entries; } }
What version are you using
With the latest version with of solr provider, with solr configuratiion files you can control which fields are copied into the _cotent field to be searched
With lucene by default code is not coped to the _content field. You would need to make a change to the catalogbuildindexer to copy that field to the _content field
Where can I find documentation that explains the solr configuration and search?
Is it possible to add the Code product field to a CatalogSearch? I have only one textbox for searching, and don't want to search for only the code, but adding it to the keyword search.
I would like to get search hits for "code" if i have a product id in the keywords.
var criteria = filter.CreateSearchCriteria(keywords, sortObject);