Switch to unified view

a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp
...
...
787
        // flushes on allterms_begin(), used in
787
        // flushes on allterms_begin(), used in
788
        // subDocs(). This issue has been gone for a long time
788
        // subDocs(). This issue has been gone for a long time
789
                // (now: Xapian 1.2) and the separate objects seem to
789
                // (now: Xapian 1.2) and the separate objects seem to
790
                // trigger other Xapian issues, so the query db is now
790
                // trigger other Xapian issues, so the query db is now
791
                // a clone of the update one.
791
                // a clone of the update one.
792
//        m_ndb->xrdb = Xapian::Database(dir);
793
        m_ndb->xrdb = m_ndb->xwdb;
792
        m_ndb->xrdb = m_ndb->xwdb;
794
        LOGDEB(("Db::open: lastdocid: %d\n", 
793
        LOGDEB(("Db::open: lastdocid: %d\n", 
795
            m_ndb->xwdb.get_lastdocid()));
794
            m_ndb->xwdb.get_lastdocid()));
796
                LOGDEB2(("Db::open: resetting updated\n"));
795
                LOGDEB2(("Db::open: resetting updated\n"));
797
                updated.resize(m_ndb->xwdb.get_lastdocid() + 1);
796
                updated.resize(m_ndb->xwdb.get_lastdocid() + 1);
...
...
1723
    }
1722
    }
1724
    m_flushtxtsz = m_curtxtsz;
1723
    m_flushtxtsz = m_curtxtsz;
1725
    return true;
1724
    return true;
1726
}
1725
}
1727
1726
1727
void Db::setExistingFlags(const string& udi, unsigned int docid)
1728
{
1729
    if (m_mode == DbRO)
1730
        return;
1731
    if (docid == (unsigned int)-1) {
1732
        LOGERR(("Db::setExistingFlags: called with bogus docid !!\n"));
1733
        return;
1734
    }
1735
#ifdef IDX_THREADS
1736
    PTMutexLocker lock(m_ndb->m_mutex);
1737
#endif
1738
    i_setExistingFlags(udi, docid);
1739
}
1740
1741
void Db::i_setExistingFlags(const string& udi, unsigned int docid)
1742
{
1743
    // Set the up to date flag for the document and its subdocs
1744
    if (docid >= updated.size()) {
1745
        LOGERR(("needUpdate: existing docid beyond "
1746
                "updated.size(). Udi [%s], docid %u, "
1747
                "updated.size() %u\n", udi.c_str(), 
1748
                unsigned(docid), (unsigned)updated.size()));
1749
        return;
1750
    } else {
1751
        updated[docid] = true;
1752
    }
1753
1754
    // Set the existence flag for all the subdocs (if any)
1755
    vector<Xapian::docid> docids;
1756
    if (!m_ndb->subDocs(udi, 0, docids)) {
1757
        LOGERR(("Rcl::Db::needUpdate: can't get subdocs\n"));
1758
        return;
1759
    }
1760
    for (vector<Xapian::docid>::iterator it = docids.begin();
1761
         it != docids.end(); it++) {
1762
        if (*it < updated.size()) {
1763
            LOGDEB2(("Db::needUpdate: docid %d set\n", *it));
1764
            updated[*it] = true;
1765
        }
1766
    }
1767
}
1768
1728
// Test if doc given by udi has changed since last indexed (test sigs)
1769
// Test if doc given by udi has changed since last indexed (test sigs)
1729
bool Db::needUpdate(const string &udi, const string& sig, bool *existed)
1770
bool Db::needUpdate(const string &udi, const string& sig, 
1771
                    unsigned int *docidp, string *osigp)
1730
{
1772
{
1731
    if (m_ndb == 0)
1773
    if (m_ndb == 0)
1732
        return false;
1774
        return false;
1733
1775
1776
    if (osigp)
1777
        osigp->clear();
1778
    if (docidp)
1779
        *docidp = 0;
1780
1734
    // If we are doing an in place or full reset, no need to test.
1781
    // If we are doing an in place or full reset, no need to test.
1735
    if (o_inPlaceReset || m_mode == DbTrunc) {
1782
    if (o_inPlaceReset || m_mode == DbTrunc) {
1736
    // For in place reset, pretend the doc existed, to enable subdoc purge
1783
    // For in place reset, pretend the doc existed, to enable
1737
  if (existed)
1784
  // subdoc purge. The value is only used as a boolean in this case.
1738
      *existed = o_inPlaceReset;
1785
  if (docidp && o_inPlaceReset) {
1786
      *docidp = -1;
1787
        }
1739
    return true;
1788
    return true;
1740
    }
1789
    }
1741
1742
    if (existed)
1743
        *existed = false;
1744
1790
1745
    string uniterm = make_uniterm(udi);
1791
    string uniterm = make_uniterm(udi);
1746
    string ermsg;
1792
    string ermsg;
1747
1793
1748
#ifdef IDX_THREADS
1794
#ifdef IDX_THREADS
...
...
1771
    if (!m_reason.empty()) {
1817
    if (!m_reason.empty()) {
1772
        LOGERR(("Db::needUpdate: get_document error: %s\n", m_reason.c_str()));
1818
        LOGERR(("Db::needUpdate: get_document error: %s\n", m_reason.c_str()));
1773
        return true;
1819
        return true;
1774
    }
1820
    }
1775
1821
1776
    if (existed)
1822
    if (docidp) {
1777
        *existed = true;
1823
        *docidp = *docid;
1824
    }
1778
1825
1779
    // Retrieve old file/doc signature from value
1826
    // Retrieve old file/doc signature from value
1780
    string osig;
1827
    string osig;
1781
    XAPTRY(osig = xdoc.get_value(VALUE_SIG), m_ndb->xrdb, m_reason);
1828
    XAPTRY(osig = xdoc.get_value(VALUE_SIG), m_ndb->xrdb, m_reason);
1782
    if (!m_reason.empty()) {
1829
    if (!m_reason.empty()) {
1783
        LOGERR(("Db::needUpdate: get_value error: %s\n", m_reason.c_str()));
1830
        LOGERR(("Db::needUpdate: get_value error: %s\n", m_reason.c_str()));
1784
        return true;
1831
        return true;
1785
    }
1832
    }
1786
    LOGDEB2(("Db::needUpdate: oldsig [%s] new [%s]\n",
1833
    LOGDEB2(("Db::needUpdate: oldsig [%s] new [%s]\n",
1787
             osig.c_str(), sig.c_str()));
1834
             osig.c_str(), sig.c_str()));
1835
1836
    if (osigp) {
1837
        *osigp = osig;
1838
    }
1839
1788
    // Compare new/old sig
1840
    // Compare new/old sig
1789
    if (sig != osig) {
1841
    if (sig != osig) {
1790
        LOGDEB(("Db::needUpdate:yes: olsig [%s] new [%s] [%s]\n",
1842
        LOGDEB(("Db::needUpdate:yes: olsig [%s] new [%s] [%s]\n",
1791
                osig.c_str(), sig.c_str(), uniterm.c_str()));
1843
                osig.c_str(), sig.c_str(), uniterm.c_str()));
1792
        // Db is not up to date. Let's index the file
1844
        // Db is not up to date. Let's index the file
1793
        return true;
1845
        return true;
1794
    }
1846
    }
1795
1847
1796
    // Up to date. 
1848
    // Up to date. Set the existance flags in the map for the doc and
1849
    // its subdocs.
1797
    LOGDEB(("Db::needUpdate:no: [%s]\n", uniterm.c_str()));
1850
    LOGDEB(("Db::needUpdate:no: [%s]\n", uniterm.c_str()));
1798
1851
    i_setExistingFlags(udi, *docid);
1799
    if (m_mode    != DbRO) {
1800
        // Set the up to date flag for the document and its subdocs
1801
        if (*docid >= updated.size()) {
1802
            LOGERR(("needUpdate: existing docid beyond "
1803
                    "updated.size(). Udi [%s], docid %u, "
1804
                    "updated.size() %u\n", udi.c_str(), 
1805
                    unsigned(*docid), (unsigned)updated.size()));
1806
        } else {
1807
            updated[*docid] = true;
1808
        }
1809
1810
        // Set the existence flag for all the subdocs (if any)
1811
        vector<Xapian::docid> docids;
1812
        if (!m_ndb->subDocs(udi, 0, docids)) {
1813
            LOGERR(("Rcl::Db::needUpdate: can't get subdocs\n"));
1814
            return true;
1815
        }
1816
        for (vector<Xapian::docid>::iterator it = docids.begin();
1817
             it != docids.end(); it++) {
1818
            if (*it < updated.size()) {
1819
                LOGDEB2(("Db::needUpdate: docid %d set\n", *it));
1820
                updated[*it] = true;
1821
            }
1822
        }
1823
    }
1824
    return false;
1852
    return false;
1825
}
1853
}
1826
1854
1827
// Return existing stem db languages
1855
// Return existing stem db languages
1828
vector<string> Db::getStemLangs()
1856
vector<string> Db::getStemLangs()