MarkLogic 7 boost relevance

137 views Asked by At

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.

3

There are 3 answers

0
Tyler Replogle On BEST ANSWER

@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 a cts:word-query() a the cts:collection-query() in an cts:and-query(). Then in the cts:word-query() use the weight parameter. the weight parameter allows you to "boots" scoring on parts of the query.

Ex:

let $queryText := "query here"
return 
  cts:search(
     fn:doc(),
     cts:or-query((
      cts:and-query((
       cts:word-query($queryText, (), 6.0),
       cts:collection-query("Content")
     )),
     cts:and-query((
      cts:word-query($queryText, (),4.0),
      cts:collection-query("Techno")
     )),
     cts:and-query((
      cts:word-query($queryText, (),2.0),
      cts:collection-query("Fun")
    )),
    cts:element-value-query(xs:QName("DisplayName"), $queryText, "exact", 16.0)
 )


    ))

The cts:word-query with the cts: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

1
Navin Rawat On

There are two ways to achieve your requirement.

  1. You should insert your document with $quality so that it can boost your relevance score.
  2. You may use fields to boost the weight of sections of documents.
0
Zaifa Xi On

You can create a field contains this three elements and give different weight to them, then do a field-value-query on this field, you will return the result as the sequence you expect.