UsingSynonyms() not working if results are not fetched right away

Vote:
 

Hi

I have the following code logic for search, where i'm trying to use UsingSynonyms(), but if I set it on query, add additional filtering afterwards, and then use query to GetResults later, it doesn't return the correct/ matching no. of results for bidirectional comma separated synonym phrases. If I call GetResult directly after UsingSynonyms(), it does give me matching results for all synonyms, but then I'm unable to apply the complex conditional filtering on this.

 var query = _findClient.Search<SearchProduct>(Language.English);

            if (!String.IsNullOrEmpty(findCriteria.SearchPhrase))
            {
                query = query
                    .For(findCriteria.SearchPhrase)
                    .InField(x => x.SearchFieldName)
                    .InField(x => x.SearchFieldSKU)
                    .InField(x => x.Custom1)
                    .InField(x => x.ShortDescription)
                    .InField(x => x.SearchFacet1)
                    .UsingSynonyms();
            }

//Check if product exists in the current market
            query = query.FilterMarket(currentMarket);

            //Check if the product is published
            query = query.Filter(x => x.Published.Match(true));

.... more conditional filtering on query

finally, this is called :

searchResult = query.OrderByFieldName(findCriteria)
                    .StaticallyCacheFor(TimeSpan.FromMinutes(cacheTimeOut))
                    .GetResult();

This doesn't give matching synonym results.

But if I do the below, I get matching synonyms, but don't know how to apply all the various conditional filtering I had on query above here :

searchResult = _findClient.Instance.For(findCriteria.SearchPhrase)
                    .InField(x => x.SearchFieldName)
                    .InField(x => x.SearchFieldSKU)
                    .InField(x => x.Custom1)
                    .InField(x => x.ShortDescription)
                    .InField(x => x.SearchFacet1)
                    .UsingSynonyms().GetResult();

Please advice on what we may be doing wrong or how best to apply conditional filtering with UsingSynonyms.

We're using Find 13.2.5.

Regards

Ritu

#251670
Mar 26, 2021 13:09
Vote:
 

Can you check if any of your filters are creating an issue?  I don't think Applying a filter after using UsingSynonyms on query should create a problem. I have tested on my project & on the Foundation website. 

See foundation code below

public ContentSearchViewModel SearchContent(FilterOptionViewModel filterOptions)
        {
            var model = new ContentSearchViewModel
            {
                FilterOption = filterOptions
            };

            if (!filterOptions.Q.IsNullOrEmpty())
            {
                var siteId = SiteDefinition.Current.Id;
                var query = _findClient.UnifiedSearchFor(filterOptions.Q, _findClient.Settings.Languages.GetSupportedLanguage(ContentLanguage.PreferredCulture) ?? Language.None)
                    .UsingSynonyms()
                    .TermsFacetFor(x => x.SearchSection)
                    .FilterFacet("AllSections", x => x.SearchSection.Exists())
                    .Filter(x => (x.MatchTypeHierarchy(typeof(FoundationPageData)) & (((FoundationPageData)x).SiteId().Match(siteId.ToString())) | (x.MatchTypeHierarchy(typeof(PageData)) & x.MatchTypeHierarchy(typeof(MediaData)))))
                    .Skip((filterOptions.Page - 1) * filterOptions.PageSize)
                    .Take(filterOptions.PageSize)
                    .ApplyBestBets();

//Filters
                //Include images in search results
                if (!filterOptions.IncludeImagesContent)
                {
                    query = query.Filter(x => !x.MatchType(typeof(ImageMediaData)));
                }

                //Exclude content from search
                query = query.Filter(x => !(x as FoundationPageData).ExcludeFromSearch.Exists() | (x as FoundationPageData).ExcludeFromSearch.Match(false));

                // obey DNT
                var doNotTrackHeader = System.Web.HttpContext.Current.Request.Headers.Get("DNT");
                if ((doNotTrackHeader == null || doNotTrackHeader.Equals("0")) && filterOptions.TrackData)
                {
                    query = query.Track();
                }

                if (!string.IsNullOrWhiteSpace(filterOptions.SectionFilter))
                {
                    query = query.FilterHits(x => x.SearchSection.Match(filterOptions.SectionFilter));
                }

                var hitSpec = new HitSpecification
                {
                    HighlightTitle = true,
                    HighlightExcerpt = true
                };

// Get Results
                model.Hits = query.GetResult(hitSpec);
                filterOptions.TotalCount = model.Hits.TotalMatching;
            }

            return model;
        }
#251676
Mar 26, 2021 14:26
Vote:
 

Hi Naveed

I wanted to highlight a few points here :

  1. Our site is not on Foundation.
  2. The search works fine without the matching synonyms, so i'm guessing all filters are correct, no errors thrown.
  3. And this is commerce catalog search, so our filters include facet filtering and more.

We do have the same logic implemented on a Foundation site and it works flawlessly. Not sure why it doesn't work on this one.

#251677
Mar 26, 2021 14:36
Vote:
 

Hi Ritu

The quickest approach to troubleshoot this is to capture the JSON rendered for such a search. I suggest using Fiddler and capture the request sent to the API _search endpoint. It would be good to have one using .UsingSynonyms() and one without. 

If it's not a local dev environment or you don't know your way around Fiddler I could capture the JSON in our backend if I get the index name (don't share any keys).

#251797
Edited, Mar 29, 2021 11:50
Vote:
 

Hey dada

I'm troubleshooting this from local, but connecting to DXP INTE Find Index, becasue I read at a couple of places that UsingSynonyms() doesn't work with dev index.

I setup Fiddler per the instructions here :

https://support.episerver.com/hc/en-us/articles/360021035391-Using-Fiddler-to-capture-Find-requests

But when I run search and check Fiddler, I don't see any calls to _search endpoint. Is it because this is from local? Or something else? I see you did mention "If its not a local dev environemnt" above. Does it mean this troubleshooting won't work locally at all?

If you can check this on your backend, the index name is : ivgrivystonegroup_ivgr01mstr9ft03inte

Regards

Ritu

#251988
Mar 29, 2021 16:51
Vote:
 

Thanks Ritu.

If you could perform at least two searches against that search index. One with synonyms enabled (with all filters) and one without synonyms (with all filters) and give me the timestamps and the query so I can easily find them.

With local dev environment I meant if the web app is running on your local machine - as the request is sent from the web app Fiddler has to be on the same machine.
It's also possible that you have do some configuration. It could something like this

https://www.telerik.com/blogs/capturing-traffic-from-.net-services-with-fiddler

Synonyms is enabled for demo indexes as well but I have seen those discussions as well :)

#251989
Mar 29, 2021 17:27
Vote:
 

Hi dada

We got this working! Had a similar Epi support ticket open for this, where they suggested reviewing/commenting filters and adding one by one to see if this works. When I went in to review my code, I came across a piece of logic that was initially there for stemming, but with the new logic we had for UsingSynonyms() and InFields(), that felt redundant, so I ended up commenting that bit first and it seems like that's all it took to resolve this. Synonyms atrted working and so is stemming.

We don't need to troubleshoot this any further. So thank you for all the help you offered.

Regards

Ritu

#251992
Mar 29, 2021 19:43
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.