Database Reference
In-Depth Information
Scoring Searches
Lucene tries to attach a relevance score to the search results. This is always a positive
floating-point number. The higher the number, the more relevant Lucene thinks the
result is. You can retrieve the score for a search result by calling the ft:score func‐
tion. Here is an example:
for $ hit in doc ( '/db/myapp/doc.xml' )// p [ ft:query (., 'exist database' )]
let $ score as xs:float := ft:score ( $ hit )
order by $ score descending
return
(: results code here :)
How exactly Lucene computes these scores is a complex topic in its own right; you
can read more about the specifics of Lucene's approach here: http://
lucene.apache.org/core/3_6_1/scoring.html . In many cases, the specifics are not
important; it is enough to trust that the Lucene score is a good approximation of
what we, mere humans, consider relevant.
Locating Matches
When you perform a full-text search like //p[ft:query(. 'database')] , the results
you get are the matching p elements. Some applications, however, need to know
where in the text of the resulting elements the actual matches were. For example, if
you offer a documentation search, it would be nice to show in the results which
pieces of text matched the query.
Although used mostly for full-text search results, locating matches
also works for NGram search results.
To enable this, eXist not only returns the results of the query, but also invisibly
remembers where the matches were. Nothing happens if you don't use this informa‐
tion, but if you need it, it's there.
As an example, let's assume we've done a full-text query on the word database that
resulted in a single p element:
<p> eXist is a native XML database. </p>
To find out where the matches were, you can call the extension function util:expand
on the search result. This will wrap the matches in exist:match elements (the exist
namespace prefix is bound to http://exist.sourceforge.net/NS/exist ). A call to
util:expand on this search result would therefore return:
Search WWH ::




Custom Search