Db2 Text Search SCORE function
The score of a document is dynamic and calculated independently for each query.
Updates to a document as well as adding or removing documents from a text index can cause a change of the score of a document for a query term.
Assume there is a set of documents discussing
transportation and pollution. If you want to locate documents containing
references to both terms, but only if the term
pollution
scores
higher than the term transportation
, you can use
the following command: SELECT document_id
FROM document_library
WHERE SCORE(document_content, 'pollution') >
SCORE(document_content, 'transportation')
and CONTAINS(document_content, 'transportation pollution') = 1
To enhance performance, you can format your query to
use the boost (^) modifier so that the search function is run only
once, as follows:
SELECT document_id
FROM document_library
WHERE SCORE(document_content, 'pollution^10 transportation') > 0
ORDER BY SCORE(document_content, 'pollution^10 transportation') DESC
The
first query does not return any results if pollution
scores
low. The second query gives higher importance to pollution
but
still returns documents if pollution
scores low in
all documents.