00001 00004 /* Copyright (C) 2009 Olly Betts 00005 * Copyright (C) 2011 Dan Colish 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as 00009 * published by the Free Software Foundation; either version 2 of the 00010 * License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef XAPIAN_INCLUDED_BRASS_DBSTATS_H 00023 #define XAPIAN_INCLUDED_BRASS_DBSTATS_H 00024 00025 #include "brass_types.h" 00026 #include "xapian/types.h" 00027 00028 #include "internaltypes.h" 00029 00030 class BrassPostListTable; 00031 00033 class BrassDatabaseStats { 00035 void operator=(const BrassDatabaseStats &); 00036 00038 BrassDatabaseStats(const BrassDatabaseStats &); 00039 00041 totlen_t total_doclen; 00042 00044 Xapian::docid last_docid; 00045 00047 Xapian::termcount doclen_lbound; 00048 00050 Xapian::termcount doclen_ubound; 00051 00053 Xapian::termcount wdf_ubound; 00054 00056 brass_revision_number_t oldest_changeset; 00057 00058 public: 00059 BrassDatabaseStats() 00060 : total_doclen(0), last_docid(0), doclen_lbound(0), doclen_ubound(0), 00061 wdf_ubound(0), oldest_changeset(0) { } 00062 00063 totlen_t get_total_doclen() const { return total_doclen; } 00064 00065 Xapian::docid get_last_docid() const { return last_docid; } 00066 00067 Xapian::termcount get_doclength_lower_bound() const { 00068 return doclen_lbound; 00069 } 00070 00071 Xapian::termcount get_doclength_upper_bound() const { 00072 return doclen_ubound; 00073 } 00074 00075 Xapian::termcount get_wdf_upper_bound() const { return wdf_ubound; } 00076 00077 brass_revision_number_t get_oldest_changeset() const { return oldest_changeset; } 00078 00079 void zero() { 00080 total_doclen = 0; 00081 last_docid = 0; 00082 doclen_lbound = 0; 00083 doclen_ubound = 0; 00084 wdf_ubound = 0; 00085 oldest_changeset = 0; 00086 } 00087 00088 void read(BrassPostListTable & postlist_table); 00089 00090 void set_last_docid(Xapian::docid did) { last_docid = did; } 00091 00092 void set_oldest_changeset(brass_revision_number_t changeset) { oldest_changeset = changeset; } 00093 00094 void add_document(Xapian::termcount doclen) { 00095 if (total_doclen == 0 || (doclen && doclen < doclen_lbound)) 00096 doclen_lbound = doclen; 00097 if (doclen > doclen_ubound) 00098 doclen_ubound = doclen; 00099 total_doclen += doclen; 00100 } 00101 00102 void delete_document(Xapian::termcount doclen) { 00103 total_doclen -= doclen; 00104 // If the database no longer contains any postings, we can reset 00105 // doclen_lbound, doclen_ubound and wdf_ubound. 00106 if (total_doclen == 0) { 00107 doclen_lbound = 0; 00108 doclen_ubound = 0; 00109 wdf_ubound = 0; 00110 } 00111 } 00112 00113 void check_wdf(Xapian::termcount wdf) { 00114 if (wdf > wdf_ubound) wdf_ubound = wdf; 00115 } 00116 00117 Xapian::docid get_next_docid() { return ++last_docid; } 00118 00119 void write(BrassPostListTable & postlist_table) const; 00120 }; 00121 00122 #endif // XAPIAN_INCLUDED_BRASS_DBSTATS_H