Post by JCHi,
I'm trying to do some fulltext query with Exist
I need to know how to actually retrieve only the 'context' of a word
when I find it, and not a bigger structure....
Actually, you mean you want to know how to use XQuery. This is a pretty
general issue, not specifically eXist related, and I suggest you look at
some tutorial materials on XQuery itself.
Post by JC<TEI.2>
<text id=2>
<bof>something else</bof>
<group>word</group>
</text>
<text id=5>
<rebof>something else</rebof>
<group>
<div>word</div>
</group>
</text>
</TEI.2>
and I'm looking for the word 'word'
I usually do
for $entries in //TEI.2[contains(lower-case(string()),'word')] return
$entries
but then I get one response, which is all the document... because TEI.2
contains this word...
No, you get that response because it's exactly what you asked for. No
matter what you put into that predicate, if the predicate evaluates to true,
then that XPath will always return the entire document. If you want to
return only elements deeper into the document structure, then you have to
shift the predicate along the XPath. To make this a bit more
realistically-TEI like, you need something like
//TEI.2//text/body//div//p[contains(.,'word')]
That will return only the <p>s for which the predicate evaluates to true.
You could get the enclosing divs instead by shifting the appropriate part of
the XPath into the predicate expression.
//TEI.2//text/body//div[contains(.//p,'word')]
You can also embed a predicate to filter the divs, thus
//TEI.2//text/body//div[@type='chapter']//p[contains(.,'word')]
which still returns only <p>s, but now only those that are descendants of
divs of the specified type. You can use the union operator to join into the
returned node sequence instances of 'word' found in other contexts of your
choice.
[In all these examples, I am leaving aside eXist-specific things that it
would be advisable to do in order to get the results returned with maximum
speed: those can come later].
The bottom line here is that you can't do the sort of query you have in mind
without some (possibly quite detailed) knowledge of the structure of the
documents you are querying. Just as you can't compose useful SQL queries
without knowledge of the schema that governs the target data. One
understanding of the somewhat fuzzy-edged concept "fulltext query" is that
no knowledge of internal document structure is necessary. But then that sort
of query is usually in the service of Information Retrieval, which seeks to
supply a ranked list of documents where the sought information is to be
found, rather than returning the targetted information itself in its
immediate context, which is what you are hoping to see.
Post by JCAnd worst : I need to get the id attribute of the text element that
include this result (2 and 5 here)
Is that possible ?
Yes easily. Once you've looked at those tutorials, you'll see how....
Michael Beddow