Esempio n. 1
0
bool XapianIndex::deleteDocuments(const string &term)
{
    bool unindexed = false;

    if (term.empty() == true)
    {
        return false;
    }

    XapianDatabase *pDatabase = XapianDatabaseFactory::getDatabase(m_databaseName, false);
    if (pDatabase == NULL)
    {
        cerr << "Bad index " << m_databaseName << endl;
        return false;
    }

    try
    {
        Xapian::WritableDatabase *pIndex = pDatabase->writeLock();
        if (pIndex != NULL)
        {
#ifdef DEBUG
            cout << "XapianIndex::deleteDocuments: term is " << term << endl;
#endif

            // Delete documents from the index
            pIndex->delete_document(term);

            unindexed = true;
        }
    }
    catch (const Xapian::Error &error)
    {
        cerr << "Couldn't unindex documents: " << error.get_type() << ": " << error.get_msg() << endl;
    }
    catch (...)
    {
        cerr << "Couldn't unindex documents, unknown exception occured" << endl;
    }
    pDatabase->unlock();

    return unindexed;
}
Esempio n. 2
0
/// Unindexes documents with the given label.
bool XapianIndex::unindexDocuments(const string &labelName)
{
	bool unindexed = false;

	if (labelName.empty() == true)
	{
		return false;
	}

	XapianDatabase *pDatabase = XapianDatabaseFactory::getDatabase(m_databaseName, false);
	if (pDatabase == NULL)
	{
		cerr << "Bad index " << m_databaseName << endl;
		return false;
	}

	try
	{
		Xapian::WritableDatabase *pIndex = pDatabase->writeLock();
		if (pIndex != NULL)
		{
			string term("XLABEL:");

			// Delete documents from the index
			term += labelName;
			pIndex->delete_document(term);
			unindexed = true;
		}
	}
	catch (const Xapian::Error &error)
	{
		cerr << "Couldn't unindex documents: " << error.get_type() << ": " << error.get_msg() << endl;
	}
	catch (...)
	{
		cerr << "Couldn't unindex documents, unknown exception occured" << endl;
	}
	pDatabase->unlock();

	return unindexed;
}
Esempio n. 3
0
/// Unindexes the given document; true if success.
bool XapianIndex::unindexDocument(unsigned int docId)
{
	bool unindexed = false;

	if (docId == 0)
	{
		return false;
	}

	XapianDatabase *pDatabase = XapianDatabaseFactory::getDatabase(m_databaseName, false);
	if (pDatabase == NULL)
	{
		cerr << "Bad index " << m_databaseName << endl;
		return false;
	}

	try
	{
		Xapian::WritableDatabase *pIndex = pDatabase->writeLock();
		if (pIndex != NULL)
		{
			// Delete the document from the index
			pIndex->delete_document(docId);
			unindexed = true;
		}
	}
	catch (const Xapian::Error &error)
	{
		cerr << "Couldn't unindex document: " << error.get_type() << ": " << error.get_msg() << endl;
	}
	catch (...)
	{
		cerr << "Couldn't unindex document, unknown exception occured" << endl;
	}
	pDatabase->unlock();

	return unindexed;
}