cts:highlight with overlapping matches
06 December 2016 07:18 PM
|
||||
Problem:When searching for matches using OR'ed word-queries, and in the case where there are overlapping matches, (i.e. one query contains the text of another query), the results of a cts:highlight query are not as desired.
For example:
The desired outcome of this would be: <p>From the <m>memoirs of an accomplished artist</m> </p> Whereas, the actual results are: <p>From the <m>memoirs of an </m> <m>accomplished artist</m></p>
This behavior is by design and the results are expected. It is because cts:highlight breaks up overlapping areas into separate matches. The cts:highlight built-in variables – $cts:queries and $cts:action help in understanding how this works, as well as to work-around this problem. $cts:queries --> returns the matching queries for each of the matched texts. $cts:action --> can be used with xdmp:set to specify what should happen next
For eg., replacing the return statement with the following in the original query:
These results give us a better understanding of how the text is being matched. We can see that " accomplished artist" is matched by both the word-queries 'accomplished artist' and 'memoirs of an accomplished artist'; hence the results of cts:highlight seem different. To work around this problem, we can insert a small piece of code:
Please note that this solution relies on assumptions about what's inside the or-query, but this example could be modified to handle other overlapping situations.
These results giv e us a better understanding of how the text is being matched. We can see that " accomplished artist" is matched by both the word-queries, and hence the results of cts:highlight seem different. | ||||
|