#include "DocumentIteratorContainer.h"
#include "DocumentIterator.h"
#include "CombinedDocumentIterator.h"

using namespace sf1r;

DocumentIteratorContainer::~DocumentIteratorContainer()
{
    for (std::vector<DocumentIterator*>::iterator it = docIters_.begin();
         it != docIters_.end(); ++it)
    {
        delete *it;
    }
}

void DocumentIteratorContainer::add(DocumentIterator* docIter)
{
    if (docIter == NULL)
        return;

    docIters_.push_back(docIter);
}

DocumentIterator* DocumentIteratorContainer::combine()
{
    if (docIters_.empty())
        return NULL;

    DocumentIterator* result = NULL;

    if (docIters_.size() == 1)
    {
        result = docIters_[0];
    }
    else
    {
        result = new CombinedDocumentIterator;
        for (std::vector<DocumentIterator*>::iterator it = docIters_.begin();
             it != docIters_.end(); ++it)
        {
            result->add(*it);
        }
    }

    docIters_.clear();
    return result;
}

#include "DocumentIteratorContainer.h"
#include "DocumentIterator.h"
#include "CombinedDocumentIterator.h"

using namespace sf1r;

DocumentIteratorContainer::~DocumentIteratorContainer()
{
    for (std::vector<DocumentIterator*>::iterator it = docIters_.begin();
         it != docIters_.end(); ++it)
    {
        delete *it;
    }
}

void DocumentIteratorContainer::add(DocumentIterator* docIter)
{
    docIters_.push_back(docIter);
}

DocumentIterator* DocumentIteratorContainer::combine()
{
    if (docIters_.empty())
        return NULL;

    DocumentIterator* result = NULL;

    if (docIters_.size() == 1)
    {
        result = docIters_[0];
    }
    else
    {
        result = new CombinedDocumentIterator;
        for (std::vector<DocumentIterator*>::iterator it = docIters_.begin();
             it != docIters_.end(); ++it)
        {
            if (NULL == *it)
            {
                delete result;
                docIters_.clear();
                return NULL;
            }
            result->add(*it);
        }
    }

    docIters_.clear();
    return result;
}

Fix bug: Search result should be empty for specific keyword. However, when the condition is set, search result become not empty.
Fix bug: Search result should be empty for specific keyword. However, when the condition is set, search result become not empty.
