Product Documentation

Full-Text Search

Previous Topic

Next Topic

Quick Start Guide to FTS

This chapter will get you up and running with FairCom Full-Text Search (FTS) in a hurry.

Currently, FairCom provides support at the navigational API level for interfacing with FTS. Support is presently being added for the relational APIs.

In This Chapter

Navigational Full-Text Search Using c-treeDB

Previous Topic

Next Topic

Navigational Full-Text Search Using c-treeDB

Adding a Full-Text Index (FTI) to a New Table

To programmatically add FTS support to an empty data file is very straight forward: 

  1. Add a new FTS index using the ctdbAddFTI() function call. This defines the index. 
  2. Add a field to the new index file using the ctdbAddFTIFieldByName() function call. This tells FairCom DB which field to fully index. At this time only a single field can be part of an FTI. Multiple FTI can be defined over the same table.
  3. To finish creating the new table, call ctdbCreateTable() to complete the file creation, including the new FTI.

See ctdbCreateTable.

That's it! You are now ready to start adding data. 

Here is an example:

CTHANDLE dTable;

pFTI = ctdbAddFTI(dTable, "myFTSidx");

if (!pFTI)

Handle_Error(hSession, "ctdbAddFTI");

if (ctdbAddFTIFieldByName(pFTI, 0, "body", CTDB_FTI_MODE_REG))

Handle_Error(hSession, "ctdbAddFTIFieldByName");

Adding an FTI to an Existing File

If you are adding an FTI over an existing FairCom DB data file that is already populated, then once you have performed the first 2 steps above, simply call ctdbAlterTable(dTable, CTDB_ALTER_INDEX).

Performing an FTS Query

The following code snippet demonstrates a query using the c-treeDB interface:


[...]

if (ctdbFTSearchOn(hRecord, string, 0))

Handle_Error(hSession, "ctdbFTSearchOn()");

rv = ctdbFirstRecord(hRecord);

while (rv == NO_ERROR)

{

if (ctdbGetFieldAsString(hRecord, 0, string, 65536) != CTDBRET_OK)

Handle_Error(hSession, "ctdbGetFieldAsString()");

printf("%s\n",string);

rv = ctdbNextRecord(hRecord);

}

if (ctdbFTSearchOff(hRecord))

Handle_Error(hSession, "ctdbFTSearchOff()");

[...]

TOCIndex