This is an old revision of the document!
Proximity searches can qualify rows with large blocks of text using Phrase Searches, BEFORE Searches and NEAR Searches. Once the rows are qualified, the obvious next step is to display the results. This can be more difficult if the text is as long as an entire book, or some other large block of text.
Omnidex allows excerpts to be retrieved from large blocks of text to make viewing easier. These excerpts show the portions of the text that qualified the row, with the search terms highlighted.
Excerpts are retrieved using the $CONTEXT function. The $CONTEXT function works hand-in-hand with the $CONTAINS function. The $CONTAINS function is used to label a particular proximity search, and the $CONTEXT function retrieves excerpts for that same label. This is needed before there may be other criteria in the SQL statement, and even multiple Proximity Searches against multiple columns and tables. Only one Proximity Search can feed these excerpts, necessitating the pairing of the $CONTAINS function and the $CONTEXT function.
The $CONTAINS function allows a specific WHERE clause predicate to be labelled, and also allows options that control the search. In its simplest form, the following two statements are identical:
> SELECT title FROM books WHERE LANGUAGE = 'English'; TITLE ----------------------------------------------------------------------------- Alice's Adventures in Wonderland Around the World in Eighty Days Hamlet The Adventures of Tom Sawyer The Wonderful Wizard of Oz 5 rows returned > > select title from books where $contains(language, 'English'); TITLE ----------------------------------------------------------------------------- Alice's Adventures IN Wonderland Around the World IN Eighty Days Hamlet The Adventures OF Tom Sawyer The Wonderful Wizard OF Oz 5 ROWS returned >
The $CONTAINS function also allows options that manually engage the PowerSearch features, such as misspellings, synonyms, etc.
> select title from books where $contains(content, 'missisipi','misspellings'); TITLE ----------------------------------------------------------------------------- Around the World in Eighty Days The Adventures of Tom Sawyer 2 rows returned
The $CONTAINS function allows criteria to be labelled for eventual pairing with excerpts using the $CONTEXT function or relevancy scoring using the $SCORE function:
> select TITLE >> from BOOKS >> where $contains(LANGUAGE, 'English',, 'LANGUAGE') and >> $contains(CONTENT, 'missisipi', 'misspellings', 'CONTENT'); TITLE ----------------------------------------------------------------------------- Around the World in Eighty Days The Adventures of Tom Sawyer 2 rows returned
The $CONTEXT function retrieves excerpts of a text field based on a paired $CONTAINS function. By default, a simple excerpt is displayed; however, options exist to allow embedding HTML tags to highlight the search terms for easy display in a web environment.
> SELECT TITLE, >> $context >> FROM BOOKS >> WHERE $contains(CONTENT, 'missisipi', 'misspellings'); TITLE ----------------------------------------------------------------------------- $CONTEXT(BOOKS.CONTENT) ----------------------------------------------------------------------------- Around the World IN Eighty Days --- at Nauvoo, on the *Mississippi*, numbering twenty-five thousand --- >> night it crossed the *Mississippi* at Davenport, AND BY --- The Adventures OF Tom Sawyer --- a point where the *Mississippi* River was a trifle --- and saw the broad >> *Mississippi* rolling BY! --- 2 ROWS returned <edit/code> Excerpts can be easily formatted FOR display USING HTML, including assigning CSS classes AS needed: <code SQL> > SELECT TITLE, >> $context(255, 'STYLE=HTML CLASSES') >> FROM BOOKS >> WHERE $contains(CONTENT, 'missisipi', 'misspellings'); TITLE ----------------------------------------------------------------------------- $CONTEXT(BOOKS.CONTENT) ----------------------------------------------------------------------------- Around the World IN Eighty Days --- at Nauvoo, on the <span class="odx_word">Mississippi</span>, numbering >> twenty-five thousand --- night it crossed the <span >> class="odx_word">Mississippi</span> at Davenport, AND BY --- The Adventures OF Tom Sawyer --- a point where the <span class="odx_word">Mississippi</span> River was a >> trifle --- and saw the broad <span class="odx_word">Mississippi</span> >> rolling BY! --- 2 ROWS returned
See also: