Example: Index specific XML tags
You can use the xmltags parameter to index-specific fields so that you can restrict your searches by XML tag names.
Given the table:
EXECUTE PROCEDURE IFX_ALLOW_NEWLINE('t');
CREATE TABLE boats(docid integer, xml_data lvarchar(4096));
INSERT INTO boats values(1, '
<boat>
<skipper>Captain Jack</skipper>
<boatname>Black Pearl</boatname>
</boat> ');
INSERT INTO boats values(2, '
<boat>
<skipper>Captain Black</skipper>
<boatname>The Queen Anne's Revenge</boatname>
</boat> ');
To create a bts index for the
skipper
and boatname
tags: CREATE INDEX boats_bts ON boats(xml_data bts_lvarchar_ops)
USING bts(xmltags="(skipper,boatname)") IN bts_sbspace;
The index will contain the following fields:
For the row where docid
= 1, the fields are:
skipper:Captain Jack
boatname:Black Pearl
For the row where docid = 2,
the fields are:
skipper:Captain Black
boatname:The Queen Anne's Revenge
To search for the skipper with the name " Black", the
SELECT statement is:
SELECT xml_data FROM boats WHERE bts_contains(xml_data, 'skipper:black');
The
search will return docid 2 because the skipper
field
for that row contains the word "black." For docid = 1, the boatname
field
also contains the word "black," but it is not returned because the
search was only for the skipper
field.