Using .UsingSynonyms in complex Unified Search queries

Vote:
 

Hello,

We have some problems with getting correct search results with the usage of synonyms.
Search for some texts yields 0 aswers when there should be a lot of answers if synonyms are working correct.
I noticed in some post that we did'nt use .InField() in our qyery. I then added it after the .UsingSynonyms() row.

var hitSpec = new HitSpecification
{
    HighlightExcerpt = true,
    EncodeTitle = false,
    EncodeExcerpt = false
};

var results = SearchClient.Instance.UnifiedSearchFor(q)
         .UsingSynonyms()
         .InField(x => x.SearchSection)
         .Track()
         .ApplyBestBets()
         .UsingAutoBoost()
         .TermsFacetFor(x => x.SearchSection)
         .Skip(skipNumber)
         .Take(pageSize)
         .StaticallyCacheFor(TimeSpan.FromMinutes(5))
         .GetResult(hitSpec);

I have try to change the order of the different query methods but this is the only way I got it to actually work. Changing the order of where .UsingSynonyms() is applied I get an error either from the compiler or a runtime error.

After adding the .InField() row I started getting a status 500 response from the search query. The error message as bellow in my local environment:

Exception type: TypeMismatchException
Exception message: Content with id 'xxxx' is of type 'EPiServer.Core.ContentAssetFolder' which does not inherit required type 'EPiServer.Core.IContentMedia'

Note: We are sharing the same Find index between local, development and stage environments.

Error in the development environment:

Exception type: TypeMismatchException
Exception message: Content with id 'xxxx' is of type 'Castle.Proxies.ImageBlockProxy' which does not inherit required type 'EPiServer.Core.IContentMedia'

The new code exists only on my local and our development environment. Both environments got the same error but for different types and different Content.

After indexing Find manually (through Admin) the error is not triggered for my local and development environments. I actually get results returned and the synonyms seem to work properly. If I index Find manually through my stage environment I do get the same error again on local and development environments.
I can't wrap my head arround this one. How come indexing stage breaks the other two and indexing one of the other two make them work?
I know there are some editorial differences between the environments but nothing that makes Find, index data in a different way, only query for results differently.

The little I understand is that the .InField() somehow tries to convert stuff to IContentMedia. Is that right?
If I do not want this conversion to happen, how can I successfully query for synonyms?
Ìt also seems like I don't need .TermsFacetFor() after having .InField(). It seems like I am getting the same results even after removing .TermsFacetFor().

#222477
Edited, May 06, 2020 11:01
Vote:
 

Seems that the .InField(x => x.SearchSection) was not needed.

What matters though is the order of the query parameters. Changing when the .UsingSynonyms() is being used in the query also changes the results.
The old query which was not working for synonyms hade the .UsingSynonyms() after 
.UsingAutoBoost().

As I found out i our query the synonyms method should come first as shown bellow:

var results = SearchClient.Instance.UnifiedSearchFor(q)
.UsingSynonyms()
.Track()
.ApplyBestBets()
.UsingAutoBoost()
.TermsFacetFor(x => x.SearchSection)
.Skip(skipNumber)
.Take(pageSize)
.StaticallyCacheFor(TimeSpan.FromMinutes(5))
.GetResult(hitSpec);
This order of things seem to be working as expected.
#223370
Edited, May 26, 2020 14:35
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.