I am using Episerver version 7 and Find version compatible with that.
I have a property defined in each pagetypes called boostFactor,Ideally I would like to pass this property in boost matching function, so that not to hard-code the value.I would like to use that property in
.BoostMatching(x => x.MatchType(typeof(ProductPage)), x.BoosFactor).?
It gives me an error as boost double value is not connected to filter at all.How do I dynamically pass the boost factor from the current page in the above example or if I need to extend it.
Can any one please write up a snippet how to achieve this?
It is not possible to specify boost parameter directly from a document property, but you can probably configure some descrete levels like this:
.BoostMatching(x => x.BoostFactor.Match(2), 2)
.BoostMatching(x => x.BoostFactor.Match(3), 3)
.BoostMatching(x => x.BoostFactor.Match(4), 4)
.BoostMatching(x => x.BoostFactor.Match(5), 5)
Thanks very much for your reply.
The way you mentioned above, it will still be hard-coded as I can see, the second parameter takes 2, 3, 4 and 5 which is hard-coded.Correct me if i am wrong.
Yes, the possible boosting factor values are predefined, but boosting is controlled by the BoostFactor property value. This is not the same as you wanted, but somewhat close. Basically the expressions above mean:
For pages having BoostFactor property value equal 2, boost with factor 2For pages having BoostFactor property value equal 3, boost with factor 3etc...
Thanks for your prompt response. I understood it now.
One more question, I am using UnifiedSearch here, as it is generalised and will contain documents with pages. Do you think I still need to use matchTypeHierarchy in here to be specific about type?Hence my search query look like this as below. I needed to typecast it to SitePageData to get the Boost factor property enabled.Can you see any problem with the code below?
ITypeSearch<ISearchContent> query = SearchClient.Instance.UnifiedSearch(Language.English).For(this.Query).BoostMatching(x => ((SitePageData)x).BoostFactor.Match(0.1), 0.1).Track().Skip((PagingPage - 1) * PageSize).ApplyBestBets().Take(PageSize);
Many thanks once again,Naz
Typecasting is fine, this expression is only used to build a boosting filter. Actual search results will never go through this expression.
Thanks, yes I have tested it, and found no issues.