Database Reference
In-Depth Information
</lucene>
</index>
</collection>
• An extremely simple HTML form that allows you to enter a search expression,
in /db/apps/exist-book/indexing/search-demo.xq
• A script that uses this expression to perform a search, in /db/apps/exist-book/
indexing/search-demo-result.xq
If you look at the code in search-demo-result.xq that actually performs the search and
displays the results, there is surprisingly little there:
{
for $hit in doc($doc-with-indexes)//tei:p[ft:query(., $search-expression)]
let $score as xs:float := ft:score($hit)
order by $score descending
return (
<p>Score: {$score}:</p>,
kwic:summarize($hit, <config width="40"/>)
)
}
First we do a full-text query using the ft:query function on tei:p elements. This
works because we have a Lucene index defined on these elements.
Then we get the score for every search result using ft:score . This returns a
floating-point number. The higher the number, the more relevant Lucene thinks
the match is. We order the results by score, resulting in the most relevant first.
The kwic:summarize function has the ability to summarize the search results
with a bit of text before and after the actual match; the second parameter speci‐
fies that this must be 40 characters. It outputs an HTML fragment with span ele‐
ments with different CSS classes for the trailing part, the match, and the leading
part of the output. You can use this to create pretty layouts for the search results
(as attempted in the example).
If you run the example and search on, for instance, distinguish , the results look like
Figure 12-1 .
Configuring Full-Text Indexes
Configuring a full-text index is done in the same collection.xconf document we used
for the other indexes. For more information on where to locate such a document and
its basic syntax, please refer to “Configuring Indexes” on page 275 .
Search WWH ::




Custom Search