Changeset 60
- Timestamp:
- 1999-09-17 15:36:27 (9 years ago)
- Location:
- trunk/xapian-core
- Files:
-
- 4 modified
-
backends/da/da_database.cc (modified) (8 diffs)
-
backends/da/da_database.h (modified) (3 diffs)
-
common/omtypes.h (modified) (1 diff)
-
tests/dbtest.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xapian-core/backends/da/da_database.cc
r58 r60 2 2 3 3 #include <string.h> 4 #include <stdio.h> 4 5 #include <errno.h> 6 #include <math.h> 5 7 #include <string> 6 8 … … 9 11 #include "daread.h" 10 12 11 DAPostList::DAPostList(struct postings *pl, doccount tf ) {13 DAPostList::DAPostList(struct postings *pl, doccount tf, doccount size) { 12 14 termfreq = tf; 13 15 postlist = pl; 16 termweight = log((size - tf) / tf); 17 18 printf("(dbsize, termfreq) = (%4d, %4d)\t=> termweight = %f\n", 19 size, tf, termweight); 20 14 21 DAreadpostings(postlist, 0, 0); 15 22 } … … 28 35 } 29 36 37 /* This is the biggie */ 30 38 weight DAPostList::get_weight() { 31 39 if(at_end()) throw OmError("Attempt to access beyond end of postlist."); 32 return postlist->wdf; 40 doccount wdf; 41 weight wt; 42 43 wdf = postlist->wdf; 44 45 printf("(wdf, termweight) = (%4d, %4.2f)", wdf, termweight); 46 47 double k = 1; 48 // FIXME - precalculate this freq score for several values of wt - may 49 // remove much computation. 50 wt = (double) wdf / (k + wdf); 51 // printf("(freq score %4.2f)", wt); 52 53 wt *= termweight; 54 55 printf("\t=> weight = %f\n", wt); 56 57 return wt; 33 58 } 34 59 … … 69 94 DA_r = DAopen((byte *)(filename_r.c_str()), DARECS); 70 95 if(DA_r == NULL) 71 throw OpeningError(string(" Opening ") + filename_r + ": " + strerror(errno));96 throw OpeningError(string("When opening ") + filename_r + ": " + strerror(errno)); 72 97 73 98 DA_t = DAopen((byte *)(filename_t.c_str()), DATERMS); … … 75 100 DAclose(DA_r); 76 101 DA_r = NULL; 77 throw OpeningError(string(" Opening ") + filename_t + ": " + strerror(errno));102 throw OpeningError(string("When opening ") + filename_t + ": " + strerror(errno)); 78 103 } 104 105 dbsize = 1000; /* FIXME - read from database */ 106 79 107 opened = true; 80 108 … … 117 145 postlist = DAopenpostings(&ti, DA_t); 118 146 119 DAPostList * pl = new DAPostList(postlist, ti.freq );147 DAPostList * pl = new DAPostList(postlist, ti.freq, dbsize); 120 148 return pl; 121 149 } … … 130 158 DADatabase::term_name_to_id(termname name) 131 159 { 160 if(!opened) throw OmError("DADatabase not opened."); 132 161 termid id; 133 162 … … 146 175 DADatabase::term_id_to_name(termid id) 147 176 { 177 if(!opened) throw OmError("DADatabase not opened."); 148 178 if (id <= 0 || id > termidvec.size()) throw RangeError("invalid termid"); 149 179 // printf("Looking up termid %d: name = `%s'\n", id, termidvec[id - 1].c_str()); -
trunk/xapian-core/backends/da/da_database.h
r57 r60 13 13 docid currdoc; 14 14 doccount termfreq; 15 weight termweight; 15 16 16 DAPostList(struct postings *pl, doccount t f);17 DAPostList(struct postings *pl, doccount termf, doccount dbsize); 17 18 public: 18 19 ~DAPostList(); … … 21 22 22 23 docid get_docid(); // Gets current docid 23 docidget_weight(); // Gets current weight24 weight get_weight(); // Gets current weight 24 25 void next(); // Moves to next docid 25 26 void skip_to(docid); // Moves to next docid >= specified docid … … 36 37 struct DAfile * DA_r; 37 38 struct DAfile * DA_t; 39 doccount dbsize; 38 40 39 41 termid max_termid; -
trunk/xapian-core/common/omtypes.h
r57 r60 9 9 typedef docid doccount; 10 10 11 typedef unsigned intweight;11 typedef double weight; 12 12 13 13 #ifdef __cplusplus -
trunk/xapian-core/tests/dbtest.cc
r52 r60 21 21 did = postlist->get_docid(); 22 22 wt = postlist->get_weight(); 23 printf("TermId: %d DocId: %d Weight: % d\n", tid, did, wt);23 printf("TermId: %d DocId: %d Weight: %f\n", tid, did, wt); 24 24 if(did == 120) postlist->skip_to(144); 25 25 else postlist->next();
