Ticket #47: alldocsiterator.patch

File alldocsiterator.patch, 8.2 KB (added by Olly Betts, 18 years ago)

Prototype patch against old version of Xapian

  • api/omdatabase.cc

    RCS file: /usr/data/cvs/xapian/xapian-core/api/omdatabase.cc,v
    retrieving revision 1.55
    diff -p -u -u -r1.55 omdatabase.cc
    OmPostListIterator  
    115115OmDatabase::postlist_begin(const om_termname &tname) const
    116116{
    117117    DEBUGAPICALL(OmPostListIterator, "OmDatabase::postlist_begin", tname);
    118     if (tname.empty())
    119         throw OmInvalidArgumentError("Zero length terms are invalid");
    120118    RETURN(OmPostListIterator(new OmPostListIterator::Internal(internal->open_post_list(tname, *this))));
    121119}
    122120
    OmPostListIterator  
    124122OmDatabase::postlist_end(const om_termname &tname) const
    125123{
    126124    DEBUGAPICALL(OmPostListIterator, "OmDatabase::postlist_end", tname);
    127     if (tname.empty())
    128         throw OmInvalidArgumentError("Zero length terms are invalid");
    129125    RETURN(OmPostListIterator(NULL));
    130126}
    131127
  • backends/inmemory/inmemory_database.cc

    RCS file: /usr/data/cvs/xapian/xapian-core/backends/inmemory/inmemory_database.cc,v
    retrieving revision 1.105
    diff -p -u -u -r1.105 inmemory_database.cc
    InMemoryPostList::get_wdf() const  
    7070    return (*pos).wdf;
    7171}
    7272
     73// InMemoryAllDocsPostList
     74
     75om_doclength
     76InMemoryAllDocsPostList::get_doclength() const
     77{
     78    return this_db->get_doclength(did);
     79}
     80
     81PositionList *
     82InMemoryAllDocsPostList::read_position_list()
     83{
     84    throw OmUnimplementedError("Can't open position list for all docs iterator");
     85}
     86
     87AutoPtr<PositionList>
     88InMemoryAllDocsPostList::open_position_list() const
     89{
     90    throw OmUnimplementedError("Can't open position list for all docs iterator");
     91}
     92
     93om_termcount
     94InMemoryAllDocsPostList::get_wdf() const
     95{
     96    return 1;
     97}
     98
    7399///////////////////////////
    74100// Actual database class //
    75101///////////////////////////
    InMemoryDatabase::~InMemoryDatabase()  
    99121LeafPostList *
    100122InMemoryDatabase::do_open_post_list(const om_termname & tname) const
    101123{
    102     if (!term_exists(tname)) {
    103         return new EmptyPostList();
    104     };
    105 
     124    if (tname.empty()) {
     125        if (termlists.empty()) return new EmptyPostList();
     126        return new InMemoryAllDocsPostList(RefCntPtr<const InMemoryDatabase>(RefCntPtrToThis(), this));
     127    }
    106128    map<om_termname, InMemoryTerm>::const_iterator i = postlists.find(tname);
    107     Assert(i != postlists.end());
     129    if (i == postlists.end()) return new EmptyPostList();
    108130
    109131    return new InMemoryPostList(RefCntPtr<const InMemoryDatabase>(RefCntPtrToThis(), this),
    110132                                i->second);
  • backends/inmemory/inmemory_database.h

    RCS file: /usr/data/cvs/xapian/xapian-core/backends/inmemory/inmemory_database.h,v
    retrieving revision 1.116
    diff -p -u -u -r1.116 inmemory_database.h
    class InMemoryPostList : public LeafPost  
    164164        string get_description() const;
    165165};
    166166
     167/** A PostList over all docs in an inmemory database.
     168 */
     169class InMemoryAllDocsPostList : public LeafPostList {
     170    friend class InMemoryDatabase;
     171    private:
     172        om_docid did;
     173
     174        RefCntPtr<const InMemoryDatabase> this_db;
     175
     176        InMemoryAllDocsPostList(RefCntPtr<const InMemoryDatabase> db);
     177    public:
     178        om_doccount get_termfreq() const;
     179
     180        om_docid       get_docid() const;     // Gets current docid
     181        om_doclength   get_doclength() const; // Length of current document
     182        om_termcount   get_wdf() const;       // Within Document Frequency
     183        PositionList *read_position_list();
     184        AutoPtr<PositionList> open_position_list() const;
     185
     186        PostList *next(om_weight w_min); // Moves to next docid
     187
     188        PostList *skip_to(om_docid did, om_weight w_min); // Moves to next docid >= specified docid
     189
     190        bool   at_end() const;        // True if we're off the end of the list
     191
     192        string get_description() const;
     193};
    167194
    168195// Term List
    169196class InMemoryTermList : public LeafTermList {
    class InMemoryTermList : public LeafTerm  
    198225 */
    199226class InMemoryDatabase : public Database {
    200227    friend class DatabaseBuilder;
     228    friend class InMemoryAllDocsPostList;
    201229    private:
    202230        map<om_termname, InMemoryTerm> postlists;
    203231        vector<InMemoryDoc> termlists;
    InMemoryPostList::get_description() cons  
    378405    return tname + ":" + om_tostring(termfreq);
    379406}
    380407
     408//////////////////////////////////////////////
     409// Inline function definitions for postlist over all docs //
     410//////////////////////////////////////////////
     411
     412inline
     413InMemoryAllDocsPostList::InMemoryAllDocsPostList(RefCntPtr<const InMemoryDatabase> db)
     414        : did(0), this_db(db)
     415{
     416}
     417
     418inline om_doccount
     419InMemoryAllDocsPostList::get_termfreq() const
     420{
     421    return this_db->totdocs;
     422}
     423
     424inline om_docid
     425InMemoryAllDocsPostList::get_docid() const
     426{
     427    Assert(did > 0 && did <= this_db->termlists.size());
     428    Assert(this_db->termlists[did - 1].is_valid);
     429    return did;
     430}
     431
     432inline PostList *
     433InMemoryAllDocsPostList::next(om_weight /*w_min*/)
     434{
     435    Assert(!at_end());
     436    do {
     437        ++did;
     438    } while (did <= this_db->termlists.size() && !this_db->termlists[did - 1].is_valid);
     439    return NULL;
     440}
     441
     442inline PostList *
     443InMemoryAllDocsPostList::skip_to(om_docid did_, om_weight /*w_min*/)
     444{
     445    Assert(!at_end());
     446    Assert(did <= did_);
     447    did = did_;
     448    while (did <= this_db->termlists.size() && !this_db->termlists[did - 1].is_valid) {
     449        ++did;
     450    }
     451    return NULL;
     452}
     453
     454inline bool
     455InMemoryAllDocsPostList::at_end() const
     456{
     457    return (did > this_db->termlists.size());
     458}
     459
     460
     461inline string
     462InMemoryAllDocsPostList::get_description() const
     463{
     464    return om_tostring(did);
     465}
    381466
    382467//////////////////////////////////////////////
    383468// Inline function definitions for termlist //
  • backends/quartz/quartz_database.cc

    RCS file: /usr/data/cvs/xapian/xapian-core/backends/quartz/quartz_database.cc,v
    retrieving revision 1.102
    diff -p -u -u -r1.102 quartz_database.cc
    QuartzDatabase::open_post_list_internal(  
    274274                                RefCntPtr<const Database> ptrtothis) const
    275275{
    276276    DEBUGCALL(DB, LeafPostList *, "QuartzDatabase::open_post_list_internal", tname << ", [ptrtothis]");
    277     Assert(!tname.empty());
    278     return(new QuartzPostList(ptrtothis,
     277    if (!tname.empty()) {
     278        // FIXME: RETURN(new QuartzAllPostList(ptrtothis, tables->get_record_table()));
     279    }
     280    RETURN(new QuartzPostList(ptrtothis,
    279281                              tables->get_postlist_table(),
    280282                              tables->get_positionlist_table(),
    281283                              tname));
  • backends/quartz/quartz_table.cc

    RCS file: /usr/data/cvs/xapian/xapian-core/backends/quartz/quartz_table.cc,v
    retrieving revision 1.69
    diff -p -u -u -r1.69 quartz_table.cc
    QuartzBufferedTable::get_or_make_tag(con  
    612609            AutoPtr<string> tag(new string);
    613610            tagptr = tag.get();
    614611            changed_entries.set_tag(key, tag);
    615             entry_count += 1;
     612            if (!key.empty()) ++entry_count;
    616613
    617614            AssertEq(changed_entries.get_tag(key), tagptr);
    618615            Assert(tag.get() == 0);
    619 
    620             RETURN(tagptr);
    621         } else {
    622             RETURN(tagptr);
    623616        }
     617        RETURN(tagptr);
    624618    }
    625619
    626620    AutoPtr<string> tag(new string);
    QuartzBufferedTable::get_or_make_tag(con  
    629623    bool found = disktable->get_exact_entry(key, *tag);
    630624
    631625    changed_entries.set_tag(key, tag);
    632     if (!found) {
    633         DEBUGLINE(DB, "QuartzBufferedTable::get_or_make_tag - increasing entry_count - '" << key << "' added");
    634         entry_count += 1;
     626    if (!found && !key.empty()) {
     627        DEBUGLINE(DB, "incrementing entry_count - '" << key << "' added");
     628        ++entry_count;
    635629    }
    636630    Assert(changed_entries.have_entry(key));
    637631    AssertEq(changed_entries.get_tag(key), tagptr);