From: Mark W. <mwi...@gm...> - 2015-03-22 21:49:37
|
Ah, thanks a lot! I knew it had to be a dumb mistake, and it was! Thanks for the hint about Luke.... On Sun, Mar 22, 2015 at 5:24 PM, cel tix44 <cel...@gm...> wrote: > Mark > > Looks like your "field config" is not correct. > > In your code, you used the logical AND ( && ) -- rather than the bitwise > OR ( | ): > int config = Field::STORE_YES | Field::INDEX_TOKENIZED; > > >>> I can see my fields in the index file > To browse your index, you can use a wonderful tool called "Luke". To find > it, just google for: luke lucene > > With Luke, I was able to see that : > -- your original code produced an 'empty' index (it had no terms); > -- with the change suggested above -- the index was populated with 3 terms > (nixon, obama, clinton); and your query returned 1 hit in Document ID 0. > > Hope this helps. > > Regards > Celto > > > > On Mon, Mar 23, 2015 at 1:24 AM, Mark Wilson <mwi...@gm...> > wrote: > >> I'm not sure what I'm doing wrong. I can see my fields in the index >> file, but my query/search returns no hits. >> >> Here is my index creation code: >> >> lucene::analysis::SimpleAnalyzer* analyzer; >> >> int main(int argc, char** argv) >> { >> analyzer = new lucene::analysis::SimpleAnalyzer(); >> Directory* indexDir = FSDirectory::getDirectory("../Index"); >> >> IndexWriter* w = new IndexWriter(indexDir, analyzer, true, true); >> >> int config = Field::STORE_YES && Field::INDEX_TOKENIZED; >> >> Field* field; >> Document* doc; >> >> doc = new Document(); >> >> field = new Field(L"president", L"Nixon", config); >> doc->clear(); >> doc->add(*field); >> w->addDocument(doc); >> >> field = new Field(L"president", L"Obama", config); >> doc->clear(); >> doc->add(*field); >> w->addDocument(doc); >> >> field = new Field(L"president", L"Clinton", config); >> doc->clear(); >> doc->add(*field); >> w->addDocument(doc); >> >> w->close(); >> >> indexDir->close(); >> } >> >> Here is my query code: >> >> >> int main(int argc, char** argv) >> { >> >> IndexReader* reader = IndexReader::open("../Index"); >> >> lucene::analysis::SimpleAnalyzer* analyzer = >> new lucene::analysis::SimpleAnalyzer(); >> >> IndexReader* newreader = reader->reopen(); >> if ( newreader != reader ) >> { >> _CLLDELETE(reader); >> reader = newreader; >> } >> IndexSearcher searcher(reader); >> >> >> Query* query = QueryParser::parse(L"Nixon*", >> L"president", analyzer); >> Hits* hits = searcher.search(query); >> cout << "Total hits: " << hits->length() << endl; >> } >> >> >> I get no hits on this. I've tried to make my experiment as simple as >> possible, but I get nothing. Is the query formed wrong? >> >> Thanks for any help. >> >> Regards, >> Mark >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming The Go Parallel Website, >> sponsored >> by Intel and developed in partnership with Slashdot Media, is your hub >> for all >> things parallel software development, from weekly thought leadership >> blogs to >> news, videos, case studies, tutorials and more. Take a look and join the >> conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> CLucene-developers mailing list >> CLu...@li... >> https://lists.sourceforge.net/lists/listinfo/clucene-developers >> >> > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, > sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for > all > things parallel software development, from weekly thought leadership blogs > to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > CLucene-developers mailing list > CLu...@li... > https://lists.sourceforge.net/lists/listinfo/clucene-developers > > |