Try our conversational search powered by Generative AI!

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



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
                    .InField(x => x.SearchFieldName)
                    .InField(x => x.SearchFieldSKU)
                    .InField(x => x.Custom1)
                    .InField(x => x.ShortDescription)
                    .InField(x => x.SearchFacet1)

//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)

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)

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.



Mar 26, 2021 13:09

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)
                    .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)

                //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;
Mar 26, 2021 14:26

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.

Mar 26, 2021 14:36

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).

Edited, Mar 29, 2021 11:50

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 :

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



Mar 29, 2021 16:51

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

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

Mar 29, 2021 17:27

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.



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.