Ticket #250: lazy_positionmods.patch

File lazy_positionmods.patch, 3.0 KB (added by Richard Boulton, 15 years ago)

Patch to track whether positionlists might be different

  • common/document.h

     
    5959        bool data_here;
    6060        mutable bool values_here; // FIXME mutable is a hack
    6161        mutable bool terms_here;
     62        bool positions_touched;
    6263
    6364        /// The (user defined) data associated with this document.
    6465        string data;
     
    174175            return terms_here;
    175176        }
    176177
     178        /** Return true if the positions in the document may have been modified.
     179         */
     180        bool positions_modified() const {
     181            return positions_touched;
     182        }
     183
    177184        /** Get the docid which is associated with this document (if any).
    178185         *
    179186         *  NB If multiple databases are being searched together, then this
     
    196203        Internal(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
    197204                 Xapian::docid did_)
    198205            : database(database_), data_here(false), values_here(false),
    199               terms_here(false), did(did_) { }
     206              terms_here(false), positions_touched(false), did(did_) { }
    200207
    201208        Internal()
    202209            : database(0), data_here(false), values_here(false),
    203               terms_here(false) { }
     210              terms_here(false), positions_touched(false) { }
    204211
    205212        /** Destructor.
    206213         *
  • api/omdocument.cc

     
    359359        i->second.add_position(tpos);
    360360        if (wdfinc) i->second.inc_wdf(wdfinc);
    361361    }
     362    positions_touched = true;
    362363}
    363364
    364365void
     
    391392                "Xapian::Document::Internal::remove_posting()");
    392393    }
    393394    i->second.remove_position(tpos);
     395    positions_touched = true;
    394396    if (wdfdec) i->second.dec_wdf(wdfdec);
    395397}
    396398
     
    405407                "' is not present in document, in "
    406408                "Xapian::Document::Internal::remove_term()");
    407409    }
     410    if (!(i->second.positions.empty())) {
     411        positions_touched = true;
     412    }
    408413    terms.erase(i);
    409414}
    410415       
     
    413418{
    414419    terms.clear();
    415420    terms_here = true;
     421    positions_touched = true;
    416422}
    417423
    418424Xapian::termcount
  • backends/flint/flint_database.cc

     
    13611361                    j->second.insert(make_pair(did, make_pair('A', wdf)));
    13621362                }
    13631363
    1364                 PositionIterator it = term.positionlist_begin();
    1365                 PositionIterator it_end = term.positionlist_end();
    1366                 if (it != it_end) {
    1367                     position_table.set_positionlist(
    1368                         did, tname, it, it_end);
    1369                 } else {
    1370                     position_table.delete_positionlist(did, tname);
     1364                if (!modifying || document.internal->positions_modified()) {
     1365                    PositionIterator it = term.positionlist_begin();
     1366                    PositionIterator it_end = term.positionlist_end();
     1367                    if (it != it_end) {
     1368                        position_table.set_positionlist(did, tname, it, it_end);
     1369                    } else {
     1370                        position_table.delete_positionlist(did, tname);
     1371                    }
    13711372                }
    13721373            }
    13731374            LOGLINE(DB, "Calculated doclen for replacement document " << did << " as " << new_doclen);