Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Did you mean?
Peter Leleulya
Peter Leleulya
Reply

Is there a code sample available of the 'did you mean: ...' functionality on search as shown in the DW9.8 webinar yesterday?
I liked this feature a lot and would like to play around with it to see if it is easy to implement in our projects ...

And of cause I'd rather steel it well than create it poorly myself ;)


Replies

   
Peter Leleulya
Peter Leleulya
Reply

How would you implement such feature in the Rapido Searchbar.cshtml?
Selecting a noproducts template in the search results product catalogue doesnt seem to render anything at all other than the rapido ResultsTemplate value ...
Not for the search bar nor for the paragraph output ...

@helper RenderSearchBar(SearchConfiguration options)
{
    <div class="typeahead typeahead--centered u-color-inherit js-typeahead dw-mod" id="ProductSearchBar"
         data-page-size="7" 
         data-search-feed-id="@options.searchFeedId" 
         data-search-second-feed-id="@options.searchSecondFeedId" 
         data-result-page-id="@options.resultPageLink" 
         data-groups-page-id="@options.groupsFeedId" 
         data-search-type="@options.searchType">
        @if (options.showGroups)
        {
            <button type="button" class="btn btn--condensed u-color-light-gray--bg typeahead-group-btn dw-mod js-typeahead-groups-btn" data-group-id="all">@Translate("All")</button>
            <ul class="dropdown dropdown--absolute-position u-min-w220px js-handlebars-root js-typeahead-groups-content dw-mod" id="ProductSearchBarGroupsContent" data-template="SearchGroupsTemplate" data-json-feed="/Default.aspx?ID=@options.groupsFeedId&feedType=productGroups" data-init-onload="false" data-preloader="minimal"></ul>
        }
        <div class="typeahead-search-field">
            <input type="text" class="u-no-margin u-full-width u-full-height js-typeahead-search-field" placeholder="@options.searchPlaceholder" value="@options.searchValue">
            @if (string.IsNullOrEmpty(options.searchSecondFeedId))
            {
                <ul class="dropdown dropdown--absolute-position u-min-w220px u-full-width js-handlebars-root js-typeahead-search-content dw-mod" id="ProductSearchBarContent" data-template="@options.searchTemplate" data-json-feed="/Default.aspx?ID=@options.searchFeedId&feedType=productsOnly" data-init-onload="false"></ul>
            }
            else
            {
                <div class="dropdown dropdown--absolute-position dropdown--combined grid">
                    <div class="js-typeahead-search-content grid__col-sm-7 grid__col--bleed-y" id="ProductSearchBarContent" data-template="@options.searchTemplate" data-init-onload="false"></div>
                    <div class="js-typeahead-additional-search-content grid__col-sm-5 grid__col--bleed-y" id="ContentSearchBarContent" data-template="@options.searchContentTemplate" data-init-onload="false"></div>
                </div>
            }
        </div>
        <button type="button" class="btn btn--condensed btn--primary u-no-margin dw-mod js-typeahead-enter-btn"><i class="@Pageview.AreaSettings.GetItem("Layout").GetItem("Icons").GetList("SearchIcon").SelectedValue"></i></button>
    </div>
}
 
Nicolai Pedersen
Reply

Hi Peter

You first have to add the did you mean data to the ProductListFeed.cshtml template you have on the product page - use the QueryResult.SpellCheck tag for that.

Then in the MasterBlocks/SearchTemplates.cshtml you need to modify the SearchProductsTemplate handlebars template to render the data from the feed...

BR Nicolai

 
Peter Leleulya
Peter Leleulya
Reply

Hi Nicolai,

I was able to get suggestions in my Rapido website.

There is just one issue ...

The ProductListFeed.cshtml retuns Language filtered products based on the Products.query filter on Dynamicweb.Ecommerce.Context:LanguageID

But when it does not find any products it now returns my model of GetLoop("SpellCheckerSuggestions") as JSon, which I handle in the search.cshtml handlebars templating ...

This all results in a nice suggestion list, but this list of suggestions is NOT filtered on language.

In my case I get English and German suggestions on an English page.
Clicking an English term results in a list of products.
Clicking a German term results in a 'nothing found' page.

I can't seem to find a way to properly filter the GetLoop("SpellCheckerSuggestions") values to the current Language context ...

 

Request: /Default.aspx?ID=2215&feed=true&pagesize=7&Search=ligt&feedType=productsOnly&redirect=false&DoNotShowVariantsAsSingleProducts=True&searchType=combined&Template=SearchProductsTemplateWrap

Response: {"template":"SuggestionsTemplate","firstSuggestion":"light","suggestions":["light","mit","ist","link","zeigt","right","line","löst","gift","long"]}

 

PageID 2215 is an English page. I tried to put the AreaID in the request URL, that didn't help.
GetLoop("SpellCheckerSuggestions") doesn't contain area/language values to filter on myself (would be too late anyway).

What can I do?

SpellCheck.PNG
 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Peter

The feature uses the SpellChecker.Net.Search.Spell.SpellChecker that will look into the index of a given field and return suggestions from that field as close to the input as possible. So it will not take a search (i.e. LanguageID=lang1+shopid=shop2+color=blue) and look inside that search result for matching words. It is looking at the entire index for a given field. 

You can see how it works here: https://lucenenet.apache.org/docs/3.0.3/d2/dc5/class_spell_checker_1_1_net_1_1_search_1_1_spell_1_1_spell_checker.html As you can see, the spellchecker only takes an indexreader which is the 'raw' index...

If you want what you suggest, we would have to do the search again (after you have no results) without the search term you specify for the spell checked field, iterate all the resulting documents, collect all terms from that field in those documents, and find the closest match. It would be slow on indexes of a surden size...

A solution to the issue would be to have an index for each language (you can set that up in the indexer) or you can have language specific spellchecking indexes which only indexes one field (the free text) and setup the suggest on a seperate page using the querypublisher.

BR Nicolai

Votes for this answer: 1
 
Peter Leleulya
Peter Leleulya
Reply

Thanks for your input.

 

You must be logged in to post in the forum