0

I am trying to search for a text "car race" in an element in my database. I have the following results returned in my result, I need to order the result such that "car race" comes first since its an exact match, followed by other results in order by ascending. Any way to add a high score to "car race" result entry?

first car race
second car race
third car race
car race
first car race again
second car race again
third car race again

Selva
  • 237
  • 1
  • 7
  • Please provide more details on how you are generating these results. By default `cts:search` will return results in TFIDF order, which would typically result in "car race" being first. That is not the case here, so this information is necessary to determine the problem. – wst Sep 28 '17 at 21:18

1 Answers1

4

If you have elements whose values are as listed, you can use a boost query to increase scores for matches that span the complete element without changing the matching:

cts:boost-query(
  cts:element-word-query(xs:QName("myelement"),"car race"),
  cts:element-value-query(xs:QName("myelement"),"car race"))

The value query says "the match must fill the whole element"; the boost says "match the first query, add in scores from the second, if there is a match to that too".

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
mholstege
  • 4,902
  • 11
  • 7
  • @Mads Hansen If there is no match for "car race", is there a way to get "car race again" ahead of "april car race". If exact match fails then bring the results which starts with the matching term. – Selva Sep 29 '17 at 20:35
  • You could change your word-query to search the words ("car", "race") to find documents that have "car" OR "race", or wrap with `cts:and-query(( cts:element-word-query(xs:QName("myelement"),"car"), cts:element-word-query(xs:QName("myelement"),"race") ))` to find documents that have either of those words, and then boost the phrase "car race" to have those with "car race" to have higher relevance score. – Mads Hansen Sep 30 '17 at 02:00
  • @MadsHansen This works but not when you have a single word search. The scores are same and I am not getting a way to boost the results with starts with the match. – Selva Oct 02 '17 at 13:13