📄 apitest.cpp
字号:
#define BUFFER2SIZE 60000
#define BUFFER3SIZE 60000
int main() {
IndexModeT IndexingMode = RecordMode;
ULongT IndexMode = 1;
/* The three buffers that are used for various processes during the indexing process */
char *Buffer1 = NULL; char *Buffer2 = NULL; char *Buffer3 = NULL;
/* The index manager that is used to open, manage, and search the index. */
OnixIndexManagerT IndexManager;
/* The indexer that is used during an indexing session. */
OnixIndexingEngineT Indexer;
/* Array of result vectors. Since it is an array, you can have more
than one result vector floating around which you can traverse or perform
boolean operations on. */
OnixQueryVectorT Vector[51];
/* Various buffers for getting the user's response as well
as getting the query and performing the query conversions. */
char Choice[2048], TextQueryString[2048],HexQueryString[2048], RankedHexQueryString[2048];
/* This buffer is used to retrieve stored text data and record IDs. */
char ScratchBuff[80];
/* Various status variables. */
int Result, Result2, VecPos1, VecPos2, VecPos3;
/* The file pointer that we are using to read the text to be indexed in through. */
FILE *Infile = NULL;
/* The filename of various files we might be working with. Note, it is only 80 characters long. */
char FileName[80];
int BuffSize, Counter;
StatusCodeT Status;
/* Variable to keep track of the various record and word numbers we are working with.
as well as how many search results we have. */
RecordNumT RecordNum, WordNum, CountNum, NumRecords, NumWords, NumbHits;
/* Flags as to whether a search term is found or whether we have a distributed index or not. */
BooleanT Found, DistributedIndex = BooleanFalse;
size_t Length;
/* This is the cursor that keeps track of where we are in the dictionary. */
DictionaryCursorT Cursor;
/* The data cursor that is used to retrieve data from the index. */
OnixDataCursorT DataCursor;
/* The length of the temporary files that are generated during indexing. */
ULongT TempFileLength;
/* These are the creation params that are used to create indexes. */
OnixIndexCreationParamsT IndexCreationParams;
/* The weight given to a given record for ranking purposes. */
FloatT HitWeight;
/* Flags to manage where we are in the interface. */
BooleanT IndexingSessionOngoingFlag = BooleanFalse;
BooleanT RetrievalSessionOngoingFlag = BooleanFalse;
BooleanT OpenIndexFlag = BooleanFalse;
/* You need to put your own passcodes here! If you are not sure of your
passcodes call Lextek at (801) 375-8332 */
IndexManager = ixCreateIndexManager(PASSCODE1, PASSCODE2, &Status);
if(Status < 0) {
printf("\n%d",Status);
}
/* Initialize the various buffers used during indexing. */
Buffer1 = (char *) malloc(BUFFER1SIZE);
Buffer2 = (char *) malloc(BUFFER2SIZE);
Buffer3 = (char *) malloc(BUFFER3SIZE);
if(Buffer1 == NULL || Buffer2 == NULL || Buffer3 == NULL) {
if(Buffer1 != NULL)
free(Buffer1);
if(Buffer2 != NULL)
free(Buffer2);
if(Buffer3 != NULL)
free(Buffer3);
printf("\nError allocating memory...");
exit(1);
}
/* Initialize the character convert arrary. */
init_character_convert();
for(;;) {
printf("\n\n1) Create Index 17) Output Stats File");
printf("\n2) Open / Close Index 18) Get Current Query Vector");
printf("\n3) Start / End Indexing Session 19) Get Record ID");
printf("\n4) Index File 20) Find ID's Record Num");
printf("\n5) Start / End RetrievalSession 21) Get Record Text");
printf("\n6) Set Index Output File Name 22) Get More Record Text");
printf("\n7) Query The Index 23) Get Error Message");
printf("\n8) Examine Wordlist 24) Get Temp Disk Space Usage.");
printf("\n9) Num. Recs In Index ");
printf("\n10) Rewind Vector ");
printf("\n11) Get Current Hit ");
printf("\n12) Get Next Hit ");
printf("\n13) Get Number Of Hits ");
printf("\n14) Delete Record ");
printf("\n15) Undelete Record ");
printf("\n16) Is Record Deleted ");
printf("\n0) Quit \n: ");
gets(Choice);
Result = atoi(Choice);
switch(Result) {
case 1:
/*
Before we create the index, we need to get certain
data from the user. We need to find out :
1) What style index is needed.
2) Whether the index will be distributed across multiple files.
2) Whether the index is going to store data with
each record.
3) Whether there will be a record ID with each record.
4) The filename for the index.
*/
printf("\n\t1) Record Mode");
printf("\n\t2) Word/Record Mode");
printf("\n\t3) Idf Mode");
printf("\n\t:");
gets(Choice);
IndexingMode = (IndexModeT) atoi(Choice);
/* We are going to use ixCreateIndexEx so as to handle the
additional options. So what we need to do is create the
index creation params object. So we can set the various
flags and variables.
*/
IndexCreationParams = ixCreateIndexCreationParams(&Status);
/* Set the indexing mode. */
ixSetIndexCreationParams(IndexCreationParams,ixSetIndexMode,&IndexingMode);
/* Set the ranking mode. */
if(IndexingMode == IDFMode || IndexingMode == WordMode)
ixSetIndexCreationParams(IndexCreationParams,ixSetRankingMethodTwo,NULL);
printf("\nDistributed Index? (Y/N) :");
gets(Choice);
/* Set whether we are going to distribute the index across multiple files.*/
if(strchr(Choice,'Y') || strchr(Choice,'y')) {
DistributedIndex = BooleanTrue;
ixSetIndexCreationParams(IndexCreationParams,ixSetDistributedIndex,NULL);
}
else {
DistributedIndex = BooleanFalse;
ixSetIndexCreationParams(IndexCreationParams,ixSetSinglePointIndex,NULL);
}
printf("\nStore Text Data? (Y/N)");
gets(Choice);
/*
Set whether we are going to store data with each record. Since the parser
is set up to store the record text when this is set, we will use a variable
length record option since the records are most likely of variable length.
*/
if(strchr(Choice,'Y') || strchr(Choice,'y')) {
StoreText = BooleanTrue;
ixSetIndexCreationParams(IndexCreationParams,ixSetVariableLengthRecordInfo,NULL);
ixSetIndexCreationParams(IndexCreationParams,ixSet32BitRecordInfoOffset,NULL);
}
else
StoreText = BooleanFalse;
printf("\nStore Record ID ? (y/n)");
gets(Choice);
/*
Set whether there will be record ID stored with each record.
If so, then there is a choice between a fixed or variable length
record ID which gets set also.
*/
if(strchr(Choice,'y') || strchr(Choice,'Y') ) {
printf("\nFixed Length ID ? (y/n)");
gets(Choice);
if(strchr(Choice,'y') || strchr(Choice,'Y')) {
printf("\nRecord ID Length :");
gets(Choice);
RecordIDLength = atoi(Choice);
ixSetIndexCreationParams(IndexCreationParams,ixSetFixedLengthRecordID,&RecordIDLength);
FixedLengthRecordIDFlag = 1;
StoreRecordIDFlag = 1;
}
else {
ixSetIndexCreationParams(IndexCreationParams,ixSetVariableLengthRecordID,NULL);
StoreRecordIDFlag = 1;
}
ixSetIndexCreationParams(IndexCreationParams,ixSetRecordID32BitOffset,NULL);
}
printf("\nIndex Name :");
gets(Choice);
/* Set the index's filename. */
ixSetIndexCreationParams(IndexCreationParams,ixSetIndexFileName,Choice);
/* Now that we have done all this, we can go ahead and create the index. */
ixCreateIndexEx(IndexManager,IndexCreationParams,&Status);
/* Delete the index creation params now that we don't need them anymore. */
ixDeleteIndexCreationParams(IndexCreationParams);
if(Status < 0)
printf("\nError Creating Index: %d",Status);
break;
case 2:
/*
We are going to be either opening or closing
the index. We use the OpenIndexFlag to tell
whether there is an open index or not. If there
isn't then we open one, if there is then we close it.
*/
if(OpenIndexFlag == BooleanTrue) {
if(IndexManager != NULL)
/* Close the index. */
ixCloseIndex(IndexManager,&Status);
if(Status < 0)
printf("\nError Closing Index: %d",Status);
else
printf("\nIndex Closed Successfully.");
OpenIndexFlag = BooleanFalse;
break;
}
printf("\nName of Index to Open :");
fgets(Choice,80,stdin);
strtok(Choice,"\n\r");
/* Open the index. */
ixOpenIndex(IndexManager,Choice,&Status);
if(Status < 0)
printf("\nFailure opening index: %d",Status);
else
OpenIndexFlag = BooleanTrue;
break;
case 3:
/*
When indexing, you need to start an indexing session
before performing the indexing and end the indexing
session when you are finished.
This does both. If an indexing session is already
in progress, it ends it. If not, it starts a new
indexing session.
In order for an indexing session to work, then we
must have an index both created and opened. (Or
just opened in the case of a pre-existing index
that we are going to add data to.)
*/
if(IndexingSessionOngoingFlag == BooleanTrue) {
size_t progress = 0;
ixEndIndexingSession(IndexManager,Indexer,&progress, 100, &Status);
if(Status < 0)
printf("\nError Ending Indexing Session. %d",Status);
else
printf("\nIndexing Session Successfully Ended.");
IndexingSessionOngoingFlag = BooleanFalse;
break;
}
Indexer = ixStartIndexingSession(IndexManager,&Status);
if(Indexer == NULL || Status < 0) {
printf("\nError Starting Indexing Session. %d",Status);
}
else {
printf("\nIndexing Session Successfully Started.");
IndexingSessionOngoingFlag = BooleanTrue;
}
break;
case 4:
/*
We are going to open the file and then
call the parser to parse it and close the
file here.
It is important to point out that the parser
is set up to break the text up into records
based on a single character delimiter. The
default is ASCII (decimal) 16.
We also need to ask about whether we are going
to store the text into the index as well as
whether we are going to have a record ID for each
record. If we are going to do these, we need
to make sure the index is created in such a way
that it is compatable with these options.
When we are done parsing the text, we will close
the file.
*/
printf("\nName of File to Scan :");
gets(FileName);
Infile = fopen(FileName,"rt");
if(Infile == NULL) {
printf("\nError opening file");
break;
}
else {
printf("\nFile opened successfully");
BuffSize = 4096;
setvbuf(Infile,NULL,_IOFBF,BuffSize);
}
/*
Find out whether we are going to store the
text data into the index.
*/
IndexRecordIDsFlag = BooleanFalse;
StoreRecordIDFlag = 0;
printf("\nStore Text Data? (Y/N)");
fgets(Choice,80,stdin);
if(strchr(Choice,'Y') || strchr(Choice,'y')) {
StoreText = BooleanTrue;
}
else
StoreText = BooleanFalse;
/*
Find out whether we are going to have a record
ID for each record. We also have the option
of indexing the record ID or not so we can map
from a record ID to a record number if needed.
(Indexing the record IDs expands the index slightly.)
*/
printf("\nStore Record ID ? (y/n) : ");
fgets(Choice,80,stdin);
if(strchr(Choice,'y') || strchr(Choice,'Y') ) {
printf("\nFixed Length ID ? (y/n) : ");
fgets(Choice,80,stdin);
if(strchr(Choice,'y') || strchr(Choice,'Y')) {
printf("\nRecord ID Length :");
fgets(Choice,80,stdin);
RecordIDLength = atoi(Choice);
FixedLengthRecordIDFlag = 1;
StoreRecordIDFlag = 1;
}
else {
StoreRecordIDFlag = 1;
}
printf("\nIndex Record ID ? (y/n) : ");
fgets(Choice,80,stdin);
if(strchr(Choice,'y') || strchr(Choice,'Y')) {
IndexRecordIDsFlag = BooleanTrue;
}
}
/*
Now that we have the parser all set up, we go
ahead and parse the text.
*/
scan(Infile, Indexer);
printf("\nDone\a...");
/* Close the text file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -