| Posted on 2008-07-25 13:21:37-07 by netman |
| Problem With Offline indexing |
|
Hi
I am one the new Users of CLUCENE.
I downloaded clucene demo and it worked properly but I understood that this demo conatins two steps that are runned in just one function.
Here is the body of fuction main in demo.
int main( int32_t argc, char** argv ){
//Dumper Debug
#ifdef TR_LEAKS
#ifdef _CLCOMPILER_MSVC
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );//| _CRTDBG_CHECK_ALWAYS_DF | _CR
+TDBG_CHECK_CRT_DF );
#endif
#endif
#endif
uint64_t str = lucene::util::Misc::currentTimeMillis();
try{
printf("Location of text files to be indexed: ");
char files[250];
fgets(files,250,stdin);
files[strlen(files)-1] = 0;
printf("Location to store the clucene index: ");
char ndx[250];
fgets(ndx,250,stdin);
ndx[strlen(ndx)-1] = 0;
IndexFiles(files,ndx,true);
getStats(ndx);
SearchFiles(ndx);
DeleteFiles(ndx);
}catch(CLuceneError& err){
printf(err.what());
}catch(...){
printf("Unknown error");
}
_lucene_shutdown(); //clears all static memory
//print lucenebase debug
#ifdef LUCENE_ENABLE_MEMLEAKTRACKING
lucene::debug::LuceneBase::__cl_PrintUnclosedObjects();
//clear memtracking memory (not the unclosed objects)
lucene::debug::LuceneBase::__cl_ClearMemory();
#endif
//Debuggin techniques:
//For msvc, use this for breaking on memory leaks:
// _crtBreakAlloc
//to break at this clucene item:
// _lucene_counter_break
//run a memory check before deleting objects:
// _lucene_run_objectcheck
//if LUCENE_ENABLE_CONSTRUCTOR_LOG is on, dont do log if this is true:
// _lucene_disable_debuglogging
printf ("\n\nTime taken: %d\n\n",lucene::util::Misc::currentTimeMillis() - str);
return 0;
}
According to this code, you index the documents and then search the word that the user is looking for and after that you delete the index files.
But I want to have an option which is resposible for indexing and another option for searching. I want to use created index files. But When I use indexing and searching separately,
the result is not correct becasue it can not find the index documents. I tried to use indexing function with ClearIndex=false but it has an error in segmentreader in norm fuction.
Here is the body of my main function:
#ifdef _CLCOMPILER_MSVC
#ifdef _DEBUG
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#endif
#include <iostream>
using namespace std;
void DeleteFiles(const char* dir);
void IndexFiles(char* path, char* target, const bool clearIndex);
void SearchFiles(const char* index,char* word);
void getStats(const char* directory);
int main(int argc, char** argv)
{
if (argc < 4){
printf ("Bad Input Parameter\n");
return 0;
}
uint64_t str = lucene::util::Misc::currentTimeMillis();
if(!strcmp(argv[1],"-s")){
try{
//retrieve the path of index file
char files[250];
strcpy(files,argv[2]);
char ndx[250];
strcpy(ndx,argv[3]);
char word[80];
strcpy(word,argv[4]);
//IndexFiles(files,ndx,true);
//IndexFiles(files,ndx,false);
getStats(ndx);
SearchFiles(ndx,word);
//DeleteFiles(ndx);
}catch(CLuceneError& err){
printf(err.what());
}catch(...){
printf("Unknown error");
}
}
else if (!strcmp(argv[1],"-i")){
try{
char files[250];
strcpy(files,argv[2]);
char ndx[250];
strcpy(ndx,argv[3]);
IndexFiles(files,ndx,true);
/*IndexFiles(files,ndx,false);*/
getStats(ndx);
DeleteFiles(ndx);
}catch(CLuceneError& err){
printf(err.what());
}catch(...){
printf("Unknown error");
}
}
_lucene_shutdown(); //clears all static memory
//print lucenebase debug
#ifdef LUCENE_ENABLE_MEMLEAKTRACKING
lucene::debug::LuceneBase::__cl_PrintUnclosedObjects();
//clear memtracking memory (not the unclosed objects)
lucene::debug::LuceneBase::__cl_ClearMemory();
#endif
//Debuggin techniques:
//For msvc, use this for breaking on memory leaks:
// _crtBreakAlloc
//to break at this clucene item:
// _lucene_counter_break
//run a memory check before deleting objects:
// _lucene_run_objectcheck
//if LUCENE_ENABLE_CONSTRUCTOR_LOG is on, dont do log if this is true:
// _lucene_disable_debuglogging
printf ("\n\nTime taken: %d\n\n",lucene::util::Misc::currentTimeMillis() - str);
return 0;
}
I really don't know how to solve this problem.
Would you please help me to the right direction I have to follow.
Thanks for you attention.
B.R
|
| Direct Responses: Write a response |