Some databases have spcific text search modules. You can use the database abstraction layer to determine if current database has text search facilifies. And you can also obtain the best method to perform a text search.

1 Text search functions

The following functions provide access to text seach facilities on current database

Return Function Description
boolean hasTextSearch() Returns if database has text search extensions
String getBasicTextSearch(String colname, Stirng text) Returns the basic text search statement for the engine. It does not check if column has text search eanbled.
String getFuzzyTextSearch(String colname, Stirng text) Returns the fuzzy (approximate) text search statement. It does not check if column has text search eanbled.
String getBestTextSearch(String tabname, String colname, String text, boolean fuzzy) Returns the best text search possible for the column. This can be a specific text search statement if database has a text search module or a simple LIKE if no TS module is available.

In the following example we have the Informix stores_demo database with BTS installed. As there is no BTS index created, the getBestTextSearch will return LIKE instead of the BTS functions.

Copy
console.log(Ax.db.hasTextSearch());
console.log(Ax.db.getBasicTextSearch("lname", "smith"));
console.log(Ax.db.getFuzzyTextSearch("lname", "smith"));
console.log(Ax.db.getBestTextSearch("customer", "lname", "smith", false));
true
bts_contains(lname, 'smith')
bts_contains(lname, 'smith~')
UPPER(lname) LIKE UPPER('%smith%') ---- There is NO text search index on the column

2 Creating a BTS Index

Let's see how to use a BTS index. In the example we will use the customer table. A simple SQL quuery will show.

Copy
select lname, lname,company from customer
lname           lname           company

Ludwig          Pauli           All Sports Supplies
Carole          Sadler          Sports Spot
Philip          Currie          Phil's Sports
Anthony         Higgins         Play Ball!
Raymond         Vector          Los Altos Sports
George          Watson          Watson & Son
Charles         Ream            Athletic Supplies
Donald          Quinn           Quinn's Sports
Jane            Miller          Sport Stuff
Roy             Jaeger          AA Athletics
Frances         Keyes           Sports Center
Margaret        Lawson          Runners & Others
Lana            Beatty          Sportstown
Frank           Albertson       Sporting Place
Alfred          Grant           Gold Medal Sports
Jean            Parmelee        Olympic City
Arnold          Sipes           Kids Korner
Dick            Baxter          Blue Ribbon Sports
Bob             Shorter         The Triathletes Club
Fred            Jewell          Century Pro Shop
Jason           Wallack         City Sports
Cathy           O'Brian         The Sporting Life
Marvin          Hanlon          Bay Sports
Chris           Putnum          Putnum's Putters
James           Henry           Total Fitness Sports
Eileen          Neelie          Neelie's Discount Sp
Kim             Satifer         Big Blue Bike Shop
Frank           Lessor          Phoenix University

Let's now create a BTS index on lname column and do a fuzzy query.

Copy
CREATE INDEX i_bts_customer1 ON customer(lname bts_char_ops)  USING BTS IN s_sbstd;

select * from customer where
bts_contains(lname, 'brian~')
customer_num  122
fname         Cathy
lname         O'Brian
company       The Sporting Life
address1      543 Nassau Street
address2
city          Princeton
state         NJ
zipcode       08540
phone         609-342-0054

Running again the script will get

Copy
console.log(Ax.db.hasTextSearch());
console.log(Ax.db.getBasicTextSearch("lname", "smith"));
console.log(Ax.db.getFuzzyTextSearch("lname", "smith"));
console.log(Ax.db.getBestTextSearch("customer", "lname", "smith", false));
true
bts_contains(lname, 'smith')
bts_contains(lname, 'smith~')
bts_contains(lname, 'smith')

You should use getBestTextSearch function as preferred option as it will automatically provide the available search option.