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.
Adding a Full-Text Index (FTI) to a New Table
To programmatically add FTS support to an empty data file is very straight forward:
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()");
[...]