Smart Search Filter for Variants

Suneel Jhangiani asked on October 31, 2017 16:35

I have a work Product List using the SmartSearchResults web part and several filter controls based on page fields connected to it. This is the same way the dancing Goat site is set-up and currently works fine in that I see all products and can filter by a variety of checkboxes.

Where I am stuck is trying to add a color filter that work's with Product Variants. I have started by enhancing the Smart Search Indexer to include a cutom skuoc_color field which contains a space seperated list of colors in hexdecimal format (ie. skuoc_colr: #000000 for black) - this hexdecimal value is actually stored in the SKUDescription of the Product Option allowing for me to easily add this.

Using Luke.Net I can see the field in the index and using the following query gets results:

+_culture:([en-us TO en-us] [invariantifieldivaluei TO invariantifieldivaluei])
+skuoc_color:("#000000 ")

However, no matter what I try setting the filters for I can't seem to getting any results. I have even tried setting the 'SearchFor' during a debug instance at runtime to the above value (escaping the quotations) with no results.

Recent Answers


Peter Mogilnitski answered on October 31, 2017 17:26 (last edited on October 31, 2017 17:50)

I find it easier not use filters and form search condion myself. You can try with out filter controls. Take Smart search results web part and paste your Lucene syntax directly in the search settings\search condition, try something like:

+documentculture: 'en-us' AND skuoc_color: '#000000'.

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on October 31, 2017 17:52

One of the issues that will then arise is the ability to show / hide filters easily based on Page Type and there are several filters that are already configured and working - these filters use ID fields in the Page Type and the filters use a pre-defined list of options.

I should also point out that if I use the search condition you pasted in Luke.Net or in the search condition of the Smart Search Results then I get no results.

The following does however yield results:

+_culture:(en-us AND skuoc_color:"#000000 ")

Perhaps there is an issue in the way I am storing the colors as whilst the above yields results the following does not:

+_culture:(en-us AND skuoc_color:"#000000")

Note: there is a space at the end of the color string in the one with results. Although personally I think it better to have the space since my filter will only be matching one item at a time even if I use the SKUID field for other variants - otherwise I might run into an instance where 31 is matched with 1031 or 231.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 31, 2017 17:57 (last edited on October 31, 2017 18:00)

You my get results but not the correct ones. Ok, in terms of SQL want: DocumentCulture='en-us' AND skuoc_color='#000000' in lucene syntax it should translated as : +(_culture: 'en-us' AND skuoc_color: '#000000')

0 votesVote for this answer Mark as a Correct answer

Dragoljub Ilic answered on November 1, 2017 12:25

Hi Suneel,

'Note: there is a space at the end of the color string in the one with results. Although personally I think it better to have the space since my filter will only be matching one item at a time even if I use the SKUID field for other variants - otherwise I might run into an instance where 31 is matched with 1031 or 231.'

If you want to avoid this, you should use different Analyzer type. For this specific issue, you should use 'White space'. You can check full list of analyzers on this link.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.