The METAMORPH and METAMORPH INVERTED indexes in Texis are used to improve the performance of text searches using full-text queries with LIKE, LIKEP, and the rest of the LIKE family. Often the query involves other values, which are used to either sort the results, or further restrict the results returned.
One example is in the Webinator application, which provides the option to sort the results by date. Historically, the way to improve the performance of the ORDER BY was to use an INVERTED INDEX. If you also wanted to do date range restriction, then you could add a regular INDEX as well.
The Metamorph compound index will provide better performance than the three indexes since all the data is available from a single index, and also requires less maintenance. For the query:
SELECT Url FROM html
WHERE
Title\Description\Keywords\Meta\Body LIKE $query
AND Visited BETWEEN $first AND $last
ORDER BY Visited DESC;
You could create the index as:
CREATE METAMORPH INVERTED INDEX
xhtmlbodv ON HTML(Title\Description\Keywords\Meta\Body, Visited);
Which is the CREATE INDEX statement you will find in the
Webinator dowalk
script.
If there are several fields that you might use in the query or ORDER BY, then you can specify all of them as additional fields. The order of the fields does not matter, and the engine may use any combination of them. If in Webinator you also wanted to allow searches and sorts based on the Depth field, you could add Depth to the index:
CREATE METAMORPH INVERTED INDEX
xhtmlbodvd ON HTML(Title\Description\Keywords\Meta\Body, Visited, Depth);
Then, with the ability of Vortex to ignore parts of the query you could write a query:
<switch $o>
<case
d><$orderby="ORDER BY Depth">
<case
v><$orderby="ORDER BY Visited DESC">
</switch>
<SQL ROW "SELECT Url FROM html
WHERE Title\Description\Keywords\Meta\Body
LIKE $query
AND (Visited BETWEEN $first AND $last
AND Depth BETWEEN $low and $high) "
$orderby>
That will allow efficient searching and ordering on any combination of Visited and Depth, as long as a query is specified for the LIKE.
The compound index can also be used for GROUP BY or other queries that can fully rely on the index data, e.g.:
SELECT Depth, count(*) from html
WHERE
Title\Description\Keywords\Meta\Body LIKE $query
GROUP BY Depth;