1
votes

I'm attempting to use Sitecore Search with a custom index to filter and search items.

The items are product reviews and are all stored in a single folder with a ProductReview template.

+ Reviews
    - Sample Review 1
    - Sample Review 2
    - Sample Review 3

The users will be able to filter items by category, subcategory and search by product name. So the form will look similar to this:

Category:     [ Drop Down ]
Sub Category: [ Drop Down ]
Product name: [ Single line of Text ]

[ Search Button ]

I'm finding the documentation for defining indexes very thin. I'm trying to setup the index with the following properties.

  • The index web database
  • It should include only those three fields as they're all I'll need
  • Only items based on the review template will be indexed
  • The two category fields don't need to be tokenised
  • You can filter on the category fields

I'm not sure if I need a custom Analyzer or DatabaseCrawler and I haven't looked into making one at all.

This is what I have so far, however I haven't produced a working index yet:

<index id="reviews" type="Sitecore.Search.Index, Sitecore.Kernel">

    <param desc="name">$(id)</param>
    <param desc="folder">reviews</param>
    <Analyzer ref="search/analyzer" />

    <include hint="list:IncludeField">
        <!-- Category -->
        <fieldId>Category</fieldId>

        <!-- Sub Category -->
        <fieldId>Sub Category</fieldId>

        <!-- Product Name -->
        <fieldId>Product Name</fieldId>

    </include>

    <locations hint="list:AddCrawler">
        <web type="Sitecore.Search.Crawlers.DatabaseCrawler, Sitecore.Kernel">
            <Database>web</Database>

            <!-- {GUID} -->
            <Root>{GUID}</Root>

            <Tags>web reviews</Tags>
            <IndexAllFields>false</IndexAllFields>

            <templates hint="list:AddTemplate">

                < !-- Product Review -- >
                <reviews>Product Review</reviews>

            </templates>
        </web>
    </locations>

</index>    

Any pointers would be greatly appreciated.

Edit

The two main things I'm looking for is:

  • How to index the category field without tokenizing it.
  • How to filter using that with the Lucine.net API.
1
For starters you're going to want Sitecore Index Viewer application to inspect and rebuild your indexes. marketplace.sitecore.net/en/Modules/Index_Viewer.aspx Additionally, it might help for getting things started to leave the "IndexAllFields" node set to true, and then of course to populate the <Root>{GUID}</Root> with the ID of the Reviews folder. - Patrick Jones
@patrickmjones but that wouldn't allow filtering? - Daniel Little
Can you describe further what exactly you mean by filtering? Are you just looking for how to query on those fields? Are you looking to do this directly with Lucene APIs, with the Sitecore.Search API, or with the SitecoreSearchContrib API? - nickwesselman

1 Answers

4
votes

Using the SitecoreSearchContrib (aka Advanced Database Crawler) library will make this much easier for you, both in indexing and searching. The library includes example configs that will make it more obvious to you how you should set things up.

Some initial pointers, even if you don't use SitecoreSearchContrib:

  • You'll want to index master as well, so that this functionality works in Preview mode. The above library will automatically search the correct database, based on the context the code is running in.
  • Your template inclusion in the index should be a template GUID.
  • Your field inclusions should be GUIDs as well.