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