void SearchFilesC(const char* index, const char* fobizzle){ standard::StandardAnalyzer analyzer; char line[80]; TCHAR tline[80]; TCHAR* buf; IndexReader* reader = IndexReader::open(index); //printf("Enter query string: "); strncpy(line,fobizzle,80); //line[strlen(line)-1]=0; IndexReader* newreader = reader->reopen(); if ( newreader != reader ){ _CLLDELETE(reader); reader = newreader; } IndexSearcher s(reader); STRCPY_AtoT(tline,line,80); Query* q = QueryParser::parse(tline,_T("contents"),&analyzer); buf = q->toString(_T("contents")); _tprintf(_T("Searching for: %S\n\n"), buf); _CLDELETE_LCARRAY(buf); uint64_t str = Misc::currentTimeMillis(); Hits* h = s.search(q); uint32_t srch = (int32_t)(Misc::currentTimeMillis() - str); str = Misc::currentTimeMillis(); //SearchData search[h->length()]; for ( size_t i=0; i < h->length(); i++ ){ Document* doc = &h->doc(i); //const TCHAR* buf = doc.get(_T("contents")); _tprintf(_T("%d. %S - %f\n"), i, doc->get(_T("path")), h->score(i)); //search[i].set_path(doc->get(_T("path"))); } printf("\n\nSearch took: %d ms.\n", srch); printf("Screen dump took: %d ms.\n\n", (int32_t)(Misc::currentTimeMillis() - str)); _CLLDELETE(h); _CLLDELETE(q); s.close(); reader->close(); _CLLDELETE(reader); };
void SearchFiles(const char* index){ standard::StandardAnalyzer analyzer; char line[80]; TCHAR tline[80]; TCHAR* buf; IndexReader* reader = IndexReader::open(index); while (true) { printf("Enter query string: "); char* tmp = fgets(line,80,stdin); if ( tmp == NULL ) continue; line[strlen(line)-1]=0; IndexReader* newreader = reader->reopen(); if ( newreader != reader ){ _CLLDELETE(reader); reader = newreader; } IndexSearcher s(reader); if ( strlen(line) == 0 ) break; STRCPY_AtoT(tline,line,80); Query* q = QueryParser::parse(tline,_T("contents"),&analyzer); buf = q->toString(_T("contents")); _tprintf(_T("Searching for: %s\n\n"), buf); _CLDELETE_LCARRAY(buf); uint64_t str = Misc::currentTimeMillis(); Hits* h = s.search(q); uint32_t srch = (int32_t)(Misc::currentTimeMillis() - str); str = Misc::currentTimeMillis(); for ( size_t i=0;i<h->length();i++ ){ Document* doc = &h->doc(i); //const TCHAR* buf = doc.get(_T("contents")); _tprintf(_T("%d. %s - %f\n"), i, doc->get(_T("path")), h->score(i)); //print result to web interface: LINH_PRINT_WEB(i,doc->get(_T("path")),h->score(i)); } printf("\n\nSearch took: %d ms.\n", srch); printf("Screen dump took: %d ms.\n\n", (int32_t)(Misc::currentTimeMillis() - str)); _CLLDELETE(h); _CLLDELETE(q); s.close(); } reader->close(); _CLLDELETE(reader); }
static int EIO_Search(eio_req* req) { search_baton_t* baton = static_cast<search_baton_t*>(req->data); standard::StandardAnalyzer analyzer; IndexReader* reader = 0; try { reader = IndexReader::open(*(*baton->index)); } catch (CLuceneError& E) { baton->error.assign(E.what()); return 0; } catch(...) { baton->error = "Got an unknown exception"; return 0; } IndexReader* newreader = reader->reopen(); if ( newreader != reader ) { delete reader; reader = newreader; } IndexSearcher s(reader); try { TCHAR* searchString = STRDUP_AtoT(*(*baton->search)); Query* q = QueryParser::parse(searchString, _T(""), &analyzer); Hits* hits = s.search(q); HandleScope scope; //_CLDELETE(q); free(searchString); // Build the result array Local<v8::Array> resultArray = v8::Array::New(); for (size_t i=0; i < hits->length(); i++) { Document& doc(hits->doc(i)); // {"id":"ab34", "score":1.0} Local<Object> resultObject = Object::New(); // TODO: This dup might be a leak resultObject->Set(String::New("id"), String::New(STRDUP_TtoA(doc.get(_T("_id"))))); resultObject->Set(String::New("score"), Number::New(hits->score(i))); resultArray->Set(i, resultObject); } baton->results = Persistent<v8::Array>::New(resultArray); } catch (CLuceneError& E) { baton->error.assign(E.what()); } catch(...) { baton->error = "Got an unknown exception"; } return 0; }
SearchData *SearchFilesC(const char* index, const char* fobizzle){ standard::StandardAnalyzer analyzer; char line[80]; TCHAR tline[80]; TCHAR* buf; IndexReader* reader = IndexReader::open(index); //printf("Enter query string: "); strncpy(line,fobizzle,80); //line[strlen(line)-1]=0; IndexReader* newreader = reader->reopen(); if ( newreader != reader ){ _CLLDELETE(reader); reader = newreader; } IndexSearcher s(reader); STRCPY_AtoT(tline,line,80); Query* q = QueryParser::parse(tline,_T("contents"),&analyzer); buf = q->toString(_T("contents")); _tprintf(_T("Searching for: %S\n\n"), buf); _CLDELETE_LCARRAY(buf); uint64_t str = Misc::currentTimeMillis(); Hits* h = s.search(q); uint32_t srch = (int32_t)(Misc::currentTimeMillis() - str); str = Misc::currentTimeMillis(); arrsize = h->length(); SearchData *search = new SearchData[h->length()]; for ( size_t i=0; i < h->length(); i++ ){ Document* doc = &h->doc(i); //const TCHAR* buf = doc.get(_T("contents")); _tprintf(_T("%d. %S - %f\n"), i, doc->get(_T("path")), h->score(i)); //const TCHAR* wtfbatman; //wtfbatman = doc->get(_T("path")); //search[(int)i].score = h->score(i); //printf("Adding %S %d\n", search[i].path, i); char *wtfbbq; wtfbbq = new char[100]; sprintf(wtfbbq,"%S %f", doc->get(_T("path")), h->score(i)); search[(int)i].path = wtfbbq; //sprintf(str,"%S", String::New((char*)doc->get(_T("path")),5)); //printf("PIZZA %s\n", wtfbbq); //sprintf(search[i].path,"%S",(const char*)doc->get(_T("path"))); //printf("segfault"); //strcpy(search[i].path,(const char*)doc->get(_T("path"))); } printf("\n\nSearch took: %d ms.\n", srch); printf("Screen dump took: %d ms.\n\n", (int32_t)(Misc::currentTimeMillis() - str)); //_CLLDELETE(h); //_CLLDELETE(q); //s.close(); //reader->close(); //_CLLDELETE(reader); //printf("Testing %S\n\n", search[0].path); return search; };