Skip to content

Commit

Permalink
Added methods in database to access the Per document statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravaror committed Jun 16, 2012
1 parent f4e1036 commit 7492eb7
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 27 deletions.
41 changes: 41 additions & 0 deletions xapian-core/backends/brass/brass_database.cc
Expand Up @@ -827,6 +827,24 @@ BrassDatabase::get_nouniqterm(Xapian::docid did) const
RETURN(postlist_table.get_nouniqterms(did,ptrtothis));
}

Xapian::termcount
BrassDatabase::get_bigramdoclength(Xapian::docid did) const
{
LOGCALL(DB, Xapian::termcount, "BrassDatabase::get_bigramdoclength", did);
Assert(did != 0);
intrusive_ptr<const BrassDatabase> ptrtothis(this);
RETURN(postlist_table.get_bigramdoclength(did,ptrtothis));
}

Xapian::termcount
BrassDatabase::get_nouniqbigram(Xapian::docid did) const
{
LOGCALL(DB, Xapian::termcount, "BrassDatabase::get_nouniqbigram", did);
Assert(did != 0);
intrusive_ptr<const BrassDatabase> ptrtothis(this);
RETURN(postlist_table.get_nouniqbigrams(did,ptrtothis));
}

Xapian::doccount
BrassDatabase::get_termfreq(const string & term) const
{
Expand Down Expand Up @@ -1511,9 +1529,32 @@ Xapian::termcount
BrassWritableDatabase::get_nouniqterm(Xapian::docid did) const
{
LOGCALL(DB,Xapian::termcount,"BrassWritableDatabase::get_nouniqterm",did);
Xapian::termcount nouniqterm;
if(inverter.get_nouniqterms(did,nouniqterm))
RETURN(nouniqterm);
RETURN(BrassDatabase::get_nouniqterm(did));
}

Xapian::termcount
BrassWritableDatabase::get_bigramdoclength(Xapian::docid did) const
{
LOGCALL(DB, Xapian::termcount, "BrassWritableDatabase::get_bigramdoclength", did);
Xapian::termcount bigramdoclen;
if (inverter.get_bigramdoclength(did, bigramdoclen))
RETURN(bigramdoclen);
RETURN(BrassDatabase::get_bigramdoclength(did));
}

Xapian::termcount
BrassWritableDatabase::get_nouniqbigram(Xapian::docid did) const
{
LOGCALL(DB,Xapian::termcount,"BrassWritableDatabase::get_nouniqbigram",did);
Xapian::termcount nouniqbigram;
if(inverter.get_nouniqbigrams(did,nouniqbigram))
RETURN(nouniqbigram);
RETURN(BrassDatabase::get_nouniqbigram(did));
}

Xapian::doccount
BrassWritableDatabase::get_termfreq(const string & term) const
{
Expand Down
4 changes: 4 additions & 0 deletions xapian-core/backends/brass/brass_database.h
Expand Up @@ -262,6 +262,8 @@ class BrassDatabase : public Xapian::Database::Internal {
Xapian::doclength get_avlength() const;
Xapian::termcount get_doclength(Xapian::docid did) const;
Xapian::termcount get_nouniqterm(Xapian::docid did) const;
Xapian::termcount get_bigramdoclength(Xapian::docid did) const;
Xapian::termcount get_nouniqbigram(Xapian::docid did) const;
Xapian::doccount get_termfreq(const string & tname) const;
Xapian::termcount get_collection_freq(const string & tname) const;
Xapian::doccount get_value_freq(Xapian::valueno slot) const;
Expand Down Expand Up @@ -389,6 +391,8 @@ class BrassWritableDatabase : public BrassDatabase {
//@{
Xapian::termcount get_doclength(Xapian::docid did) const;
Xapian::termcount get_nouniqterm(Xapian::docid did) const;
Xapian::termcount get_bigramdoclength(Xapian::docid did) const;
Xapian::termcount get_nouniqbigram(Xapian::docid did) const;
Xapian::doccount get_termfreq(const string & tname) const;
Xapian::termcount get_collection_freq(const string & tname) const;
Xapian::doccount get_value_freq(Xapian::valueno slot) const;
Expand Down
36 changes: 28 additions & 8 deletions xapian-core/backends/chert/chert_database.cc
Expand Up @@ -796,12 +796,21 @@ ChertDatabase::get_doclength(Xapian::docid did) const
}

Xapian::termcount
ChertDatabase::get_nouniqterm(Xapian::docid did) const
ChertDatabase::get_nouniqterm(Xapian::docid) const
{
LOGCALL(DB, Xapian::termcount, "ChertDatabase::get_nouniqterm", did);
Assert(did != 0);
intrusive_ptr<const ChertDatabase> ptrtothis(this);
RETURN(postlist_table.get_doclength(did, ptrtothis));//Pending implementation
throw UnimplementedError("Number unique terms not implemented for Chert Backend use brass backend");
}

Xapian::termcount
ChertDatabase::get_bigramdoclength(Xapian::docid) const
{
throw UnimplementedError("Bigram Doclength not implemented for Chert Backend use Brass Backend");
}

Xapian::termcount
ChertDatabase::get_nouniqbigram(Xapian::docid) const
{
throw UnimplementedError("Number unique bigrams not implemented for Chert Backend use Brass backend");
}

Xapian::doccount
Expand Down Expand Up @@ -1531,10 +1540,21 @@ ChertWritableDatabase::get_doclength(Xapian::docid did) const
}

Xapian::termcount
ChertWritableDatabase::get_nouniqterm(Xapian::docid did) const
ChertWritableDatabase::get_nouniqterm(Xapian::docid) const
{
LOGCALL(DB, Xapian::termcount, "ChertWritableDatabase::get_nouniqterm", did);
RETURN(ChertDatabase::get_doclength(did));
throw UnimplementedError("Number unique terms not implemented for Chert Backend use Brass backend");
}

Xapian::termcount
ChertWritableDatabase::get_bigramdoclength(Xapian::docid) const
{
throw UnimplementedError("Bigram Doclength not implemented for Chert Backend use Brass backend");
}

Xapian::termcount
ChertWritableDatabase::get_nouniqbigram(Xapian::docid) const
{
throw UnimplementedError("Number unique bigram not implemented for Chert Backend use Brass backend");
}

Xapian::doccount
Expand Down
4 changes: 4 additions & 0 deletions xapian-core/backends/chert/chert_database.h
Expand Up @@ -259,6 +259,8 @@ class ChertDatabase : public Xapian::Database::Internal {
Xapian::doclength get_avlength() const;
Xapian::termcount get_doclength(Xapian::docid did) const;
Xapian::termcount get_nouniqterm(Xapian::docid did) const;
Xapian::termcount get_bigramdoclength(Xapian::docid did) const;
Xapian::termcount get_nouniqbigram(Xapian::docid did) const;
Xapian::doccount get_termfreq(const string & tname) const;
Xapian::termcount get_collection_freq(const string & tname) const;
Xapian::doccount get_value_freq(Xapian::valueno slot) const;
Expand Down Expand Up @@ -431,6 +433,8 @@ class ChertWritableDatabase : public ChertDatabase {
//@{
Xapian::termcount get_doclength(Xapian::docid did) const;
Xapian::termcount get_nouniqterm(Xapian::docid did) const;
Xapian::termcount get_bigramdoclength(Xapian::docid did) const;
Xapian::termcount get_nouniqbigram(Xapian::docid did) const;
Xapian::doccount get_termfreq(const string & tname) const;
Xapian::termcount get_collection_freq(const string & tname) const;
Xapian::doccount get_value_freq(Xapian::valueno slot) const;
Expand Down
34 changes: 28 additions & 6 deletions xapian-core/backends/inmemory/inmemory_database.cc
Expand Up @@ -160,8 +160,19 @@ InMemoryPostList::get_doclength() const
Xapian::termcount
InMemoryPostList::get_nouniqterm() const
{
if (db->is_closed()) InMemoryDatabase::throw_database_closed();
return db->get_nouniqterm(get_docid());
throw Xapian::UnimplementedError("Number of Unique terms not implemented for Inmemory Backend");
}

Xapian::termcount
InMemoryPostList::get_bigramdoclength() const
{
throw Xapian::UnimplementedError("Bigram document length not implemented for Inmemory Backend");
}

Xapian::termcount
InMemoryPostList::get_nouniqbigram() const
{
throw Xapian::UnimplementedError("Number of Unique bigrams not implemented for Inmemory Backend");
}

PositionList *
Expand Down Expand Up @@ -332,8 +343,7 @@ InMemoryAllDocsPostList::get_doclength() const
Xapian::termcount
InMemoryAllDocsPostList::get_nouniqterm() const
{
if (db->is_closed()) InMemoryDatabase::throw_database_closed();
return db->get_nouniqterm(did);
throw Xapian::UnimplementedError("Number of Unique terms not implemented for Inmemory Backend");
}

Xapian::termcount
Expand Down Expand Up @@ -543,9 +553,21 @@ InMemoryDatabase::get_doclength(Xapian::docid did) const
}

Xapian::termcount
InMemoryDatabase::get_nouniqterm(Xapian::docid did) const
InMemoryDatabase::get_nouniqterm(Xapian::docid) const
{
throw Xapian::UnimplementedError("Number of Unique terms not implemented for Inmemory Backend");
}

Xapian::termcount
InMemoryDatabase::get_bigramdoclength(Xapian::docid) const
{
throw Xapian::UnimplementedError("Bigram Document Length not implemented for Inmemory Backend");
}

Xapian::termcount
InMemoryDatabase::get_nouniqbigram(Xapian::docid) const
{
return doclengths[did-1];
throw Xapian::UnimplementedError("Number of Unique bigrams not implemented for Inmemory Backend");
}

TermList *
Expand Down
8 changes: 7 additions & 1 deletion xapian-core/backends/inmemory/inmemory_database.h
Expand Up @@ -155,7 +155,9 @@ class InMemoryPostList : public LeafPostList {

Xapian::docid get_docid() const; // Gets current docid
Xapian::termcount get_doclength() const; // Length of current document
Xapian::termcount get_nouniqterm() const; // Length of current document
Xapian::termcount get_nouniqterm() const; // Number of unique terms
Xapian::termcount get_bigramdoclength() const; // Length of current document
Xapian::termcount get_nouniqbigram() const; // Number of Unique terms of bigrams
Xapian::termcount get_wdf() const; // Within Document Frequency
PositionList * read_position_list();
PositionList * open_position_list() const;
Expand Down Expand Up @@ -186,6 +188,8 @@ class InMemoryAllDocsPostList : public LeafPostList {
Xapian::docid get_docid() const; // Gets current docid
Xapian::termcount get_doclength() const; // Length of current document
Xapian::termcount get_nouniqterm() const; // number of terms in current document
Xapian::termcount get_bigramdoclength() const; // Length of current document
Xapian::termcount get_nouniqbigram() const; // number of terms in current document
Xapian::termcount get_wdf() const; // Within Document Frequency
PositionList * read_position_list();
PositionList * open_position_list() const;
Expand Down Expand Up @@ -323,6 +327,8 @@ class InMemoryDatabase : public Xapian::Database::Internal {
Xapian::doclength get_avlength() const;
Xapian::termcount get_doclength(Xapian::docid did) const;
Xapian::termcount get_nouniqterm(Xapian::docid did) const;
Xapian::termcount get_bigramdoclength(Xapian::docid did) const;
Xapian::termcount get_nouniqbigram(Xapian::docid did) const;

Xapian::doccount get_termfreq(const string & tname) const;
Xapian::termcount get_collection_freq(const string & tname) const;
Expand Down
28 changes: 16 additions & 12 deletions xapian-core/backends/remote/remote-database.cc
Expand Up @@ -525,21 +525,25 @@ RemoteDatabase::get_doclength(Xapian::docid did) const
}
return doclen;
}

Xapian::termcount
RemoteDatabase::get_nouniqterm(Xapian::docid did) const
RemoteDatabase::get_nouniqterm(Xapian::docid) const
{
Assert(did != 0);
send_message(MSG_DOCLENGTH, encode_length(did));
string message;
get_message(message, REPLY_DOCLENGTH);
const char * p = message.c_str();
const char * p_end = p + message.size();
Xapian::termcount doclen = decode_length(&p, p_end, false);
if (p != p_end) {
throw Xapian::NetworkError("Bad REPLY_DOCLENGTH message received", context);
}
return doclen;
throw Xapian::UnimplementedError("Number of unique terms are not Supported by Remote Backend");
}

Xapian::termcount
RemoteDatabase::get_bigramdoclength(Xapian::docid) const
{
throw Xapian::UnimplementedError("Bigram Document Length is not Supported by Remote Backend");
}

Xapian::termcount
RemoteDatabase::get_nouniqbigram(Xapian::docid) const
{
throw Xapian::UnimplementedError("Number of unique bigrams are not Supported by Remote Backend");
}

reply_type
RemoteDatabase::get_message(string &result, reply_type required_type) const
{
Expand Down
2 changes: 2 additions & 0 deletions xapian-core/backends/remote/remote-database.h
Expand Up @@ -214,6 +214,8 @@ class RemoteDatabase : public Xapian::Database::Internal {

Xapian::termcount get_doclength(Xapian::docid did) const;
Xapian::termcount get_nouniqterm(Xapian::docid did) const;
Xapian::termcount get_bigramdoclength(Xapian::docid did) const;
Xapian::termcount get_nouniqbigram(Xapian::docid did) const;

/// Check if term exists.
bool term_exists(const string & tname) const;
Expand Down

0 comments on commit 7492eb7

Please sign in to comment.