Skip to content

Commit

Permalink
Removed bug ,if stemmer is not set bigrams were not addedd
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravaror committed Aug 19, 2012
1 parent 8880ea2 commit f0e97e9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions xapian-core/examples/simpleindex.cc
Expand Up @@ -56,8 +56,8 @@ try {
indexer.set_stemmer(stemmer);
Xapian::SimpleStopper stopper;

Xapian::BigramIterator bi = db1.bigramlist_begin(Xapian::docid(1));
while(bi != db1.bigramlist_end(1))
Xapian::TermIterator bi = db1.termlist_begin(Xapian::docid(1));
while(bi != db1.termlist_end(1))
{
cout<<"Bigram"<<*bi<<"\n";
bi++;
Expand Down
2 changes: 1 addition & 1 deletion xapian-core/queryparser/termgenerator_internal.cc
Expand Up @@ -294,6 +294,7 @@ TermGenerator::Internal::index_text(Utf8Iterator itor, termcount wdf_inc,
}
}
}
prevterm = term;
if ((flags & FLAG_SPELLING) && prefix.empty()) db.add_spelling(term);

if (strategy == TermGenerator::STEM_NONE ||
Expand Down Expand Up @@ -330,7 +331,6 @@ TermGenerator::Internal::index_text(Utf8Iterator itor, termcount wdf_inc,
}
doc.add_term(stem, wdf_inc);
}
prevterm = term;
prevstem = stem;
}
}
Expand Down
32 changes: 32 additions & 0 deletions xapian-core/tests/api_bigram.cc
Expand Up @@ -114,3 +114,35 @@ DEFINE_TESTCASE(bigramtest2, backend) {
}
return false;
}

DEFINE_TESTCASE(bigramtest3, backend) {
//To identify bug(in unit testing) if stemmer is not set then bigrams were not added.
SKIP_TEST_FOR_BACKEND("chert");
SKIP_TEST_FOR_BACKEND("inmemory");
mkdir(".brass", 0755);
string dbdir = ".brass/bigramtest2";
Xapian::WritableDatabase db(Xapian::Brass::open(dbdir, Xapian::DB_CREATE_OR_OVERWRITE));
Xapian::TermGenerator indexer;
Xapian::Document doc;
filebuf fb;
fb.open ("testdata/apitest_simpledata.txt",ios::in);
istream bigramfile(&fb);
string text = get_paragraph(bigramfile);
doc.set_data(text);
indexer.set_bigrams(true);
indexer.set_document(doc);
indexer.set_database(db);
indexer.index_text(text);
Xapian::docid docid1 = db.add_document(doc);
Xapian::TermIterator bi = db.termlist_begin(docid1);
tout<<"jdk"<<docid1;
while(bi != db.termlist_end(docid1)) {
string bigramterm = *bi;
tout<<bigramterm<<endl;
if( bigramterm.compare("mention banana") == 0) {
return true;
}
bi++;
}
return false;
}

0 comments on commit f0e97e9

Please sign in to comment.