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;
}
Hi Naveed
I wanted to highlight a few points here :
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.
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).
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
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 :)
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
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