Skip to content

Commit

Permalink
Added implementation to insert bigrams in the Posting Changes object …
Browse files Browse the repository at this point in the history
…and finally send them to merge in postlist table,postlist table implementation pending
  • Loading branch information
gauravaror committed Jun 9, 2012
1 parent 76af871 commit 4b3e483
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
42 changes: 42 additions & 0 deletions xapian-core/backends/brass/brass_inverter.cc
Expand Up @@ -48,6 +48,18 @@ Inverter::flush_post_list(BrassPostListTable & table, const string & term)
postlist_changes.erase(i);
}

void
Inverter::flush_post_bigram_list(BrassPostListTable & table, const string & bigram)
{
map<string, PostingChanges>::iterator i;
i = postbigram_changes.find(bigram);
if (i == postbigram_changes.end()) return;

// Flush buffered changes for just this term's postlist.
table.merge_changes(bigram, i->second);
postbigram_changes.erase(i);
}

void
Inverter::flush_all_post_lists(BrassPostListTable & table)
{
Expand All @@ -58,6 +70,16 @@ Inverter::flush_all_post_lists(BrassPostListTable & table)
postlist_changes.clear();
}

void
Inverter::flush_all_post_bigram_lists(BrassPostListTable & table)
{
map<string, PostingChanges>::const_iterator i;
for (i = postbigram_changes.begin(); i != postbigram_changes.end(); ++i) {
table.merge_changes(i->first, i->second);
}
postbigram_changes.clear();
}

void
Inverter::flush_post_lists(BrassPostListTable & table, const string & pfx)
{
Expand All @@ -77,9 +99,29 @@ Inverter::flush_post_lists(BrassPostListTable & table, const string & pfx)
postlist_changes.erase(begin, end);
}

void
Inverter::flush_post_bigram_lists(BrassPostListTable & table, const string & pfx)
{
if (pfx.empty())
return flush_all_post_bigram_lists(table);

map<string, PostingChanges>::iterator i, begin, end;
begin = postbigram_changes.lower_bound(pfx);
end = postbigram_changes.upper_bound(pfx);

for (i = begin; i != end; ++i) {
table.merge_changes(i->first, i->second);
}

// Erase all the entries in one go, as that's:
// O(log(postlist_changes.size()) + O(number of elements removed)
postbigram_changes.erase(begin, end);
}

void
Inverter::flush(BrassPostListTable & table)
{
flush_doclengths(table);
flush_all_post_lists(table);
flush_all_post_bigram_lists(table);
}
72 changes: 72 additions & 0 deletions xapian-core/backends/brass/brass_inverter.h
Expand Up @@ -107,12 +107,16 @@ class Inverter {

/// Buffered changes to postlists.
std::map<std::string, PostingChanges> postlist_changes;

/// Buffered Changes to postlists for bigrams.
std::map<std::string,PostingChanges> postbigram_changes;

public:
/// Buffered changes to document lengths.
std::map<Xapian::docid, Xapian::termcount> doclen_changes;

public:
/// Add posting for term.
void add_posting(Xapian::docid did, const std::string & term,
Xapian::doccount wdf) {
std::map<std::string, PostingChanges>::iterator i;
Expand All @@ -125,6 +129,20 @@ class Inverter {
}
}

//// Add posting for this bigram.
void add_bigramposting(Xapian::docid did,const std::string & bigram,
Xapian::doccount wdf) {
std::map<std::string,PostingChanges>::iterator i;
i = postbigram_changes.find(bigram);
if (i == postbigram_changes.end()) {
postbigram_changes.insert(
std::make_pair(bigram, PostingChanges(did,wdf)));
} else {
i->second.add_posting(did,wdf);
}
}

/// Remove posting for this term.
void remove_posting(Xapian::docid did, const std::string & term,
Xapian::doccount wdf) {
std::map<std::string, PostingChanges>::iterator i;
Expand All @@ -137,6 +155,20 @@ class Inverter {
}
}

/// Remove posting for this bigram.
void remove_bigramposting(Xapian::docid did,const std::string & bigram,
Xapian::doccount wdf) {
std::map<std::string,PostingChanges>::iterator i;
i = postbigram_changes.find(bigram);
if (i == postbigram_changes.end()) {
postbigram_changes.insert(
std::make_pair(bigram,PostingChanges(did,wdf,false)));
} else {
i->second.remove_posting(did,wdf);
}
}

/// Update posting for this term.
void update_posting(Xapian::docid did, const std::string & term,
Xapian::termcount old_wdf,
Xapian::termcount new_wdf) {
Expand All @@ -150,9 +182,24 @@ class Inverter {
}
}

/// Updated posting for this bigram.
void update_bigramposting(Xapian::docid did,const std::string & bigram,
Xapian::termcount old_wdf,
Xapian::termcount new_wdf) {
std::map<std::string,PostingChanges>::iterator i;
i = postbigram_changes.find(bigram);
if (i == postbigram_changes.end()) {
postbigram_changes.insert(
std::make_pair(bigram,PostingChanges(did,old_wdf,new_wdf)));
} else {
i->second.update_posting(did,old_wdf,new_wdf);
}
}

void clear() {
doclen_changes.clear();
postlist_changes.clear();
postbigram_changes.clear();
}

void set_doclength(Xapian::docid did, Xapian::termcount doclen, bool add) {
Expand Down Expand Up @@ -190,6 +237,15 @@ class Inverter {
/// Flush postlist changes for all terms which start with @a pfx.
void flush_post_lists(BrassPostListTable & table, const std::string & pfx);

/// Flush postlist changes for @a bigram.
void flush_post_bigram_list(BrassPostListTable & table, const std::string & bigram);

/// Flush postlist changes for all terms.
void flush_all_post_bigram_lists(BrassPostListTable & table);

/// Flush postlist changes for all terms which start with @a pfx.
void flush_post_bigram_lists(BrassPostListTable & table, const std::string & pfx);

/// Flush all changes.
void flush(BrassPostListTable & table);

Expand All @@ -200,6 +256,14 @@ class Inverter {
return 0;
return i->second.get_tfdelta();
}

Xapian::termcount_diff get_bigramtfdelta(const std::string & bigram) const {
std::map<std::string, PostingChanges>::const_iterator i;
i = postbigram_changes.find(bigram);
if (i == postbigram_changes.end())
return 0;
return i->second.get_tfdelta();
}

Xapian::termcount_diff get_cfdelta(const std::string & term) const {
std::map<std::string, PostingChanges>::const_iterator i;
Expand All @@ -208,6 +272,14 @@ class Inverter {
return 0;
return i->second.get_cfdelta();
}

Xapian::termcount_diff get_bigramcfdelta(const std::string & bigram) const {
std::map<std::string, PostingChanges>::const_iterator i;
i = postbigram_changes.find(bigram);
if (i == postbigram_changes.end())
return 0;
return i->second.get_cfdelta();
}
};

#endif // XAPIAN_INCLUDED_BRASS_INVERTER_H

0 comments on commit 4b3e483

Please sign in to comment.