In MarkLogic, I can boost relevance score for certain documents.
For example if I have a document stored in content
collection such as the below:
<Content xmlns="http://test.ww/common/content/v1.0">
<DisplayName>Testing DisplayName</DisplayName>
</Content>
And I also have another document stored in techno
collection such as the below
<Techno xmlns="http://test.ww/common/content/v1.0">
<DisplayName>Testing DisplayName</DisplayName>
</Techno>
And I have another document in the fun
collection with XML as below
<Fun xmlns="http://test.ww/common/content/v1.0">
<DisplayName>Testing DisplayName</DisplayName>
</Fun>
If I do a search for the term testing displayname
, I expect that documents in the content collection should have a higher relevance than documents in the techno
collection. Ranking should be from Content->Techno->Fun. Basically if it is an exact match on the displayname I want MarkLogic to rank relevance with the content
collection having the top relevance.
How can I do this? I am using the search library.
@navin rawat's answer is doing it on "write" and I wanted to point out that you can also do this on "read". which from your comment/question to him might be the way you want to go.
When you say "search library" do you mean the search:search library or cts:search?
If it's search:search you could do this with an additional query.
What you'll want to do is use
cts:collection-query()
and then boost its score by wrapping acts:word-query()
a thects:collection-query()
in ancts:and-query()
. Then in thects:word-query()
use the weight parameter. the weight parameter allows you to "boots" scoring on parts of the query.Ex:
The
cts:word-query
with thects:collection-query
is allowing you to boot the "hit" based on the collection its in.The
cts:element-value-query()
is boosting the score based on the element its in and the exact option telling marklogic to look for that exact text.You'll have to play around with the numbers in the weight parameter