1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
4
* Distributable under the terms of either the Apache License (Version 2.0) or
5
* the GNU Lesser General Public License, as specified in the COPYING file.
6
------------------------------------------------------------------------------*/
7
#include "CLucene/_ApiHeader.h"
8
#include "FilteredTermEnum.h"
9
#include "CLucene/index/Term.h"
15
FilteredTermEnum::FilteredTermEnum():currentTerm(NULL),actualEnum(NULL){
18
FilteredTermEnum::~FilteredTermEnum() {
21
//Post - The instance has been destroyed
26
int32_t FilteredTermEnum::docFreq() const {
27
//Func - Returns the docFreq of the current Term in the enumeration.
28
//Pre - next() must have been called at least once
29
//Post - if actualEnum is NULL result is -1 otherwise the frequencey is returned
31
if (actualEnum == NULL){
34
return actualEnum->docFreq();
37
bool FilteredTermEnum::next() {
38
//Func - Increments the enumeration to the next element.
40
//Post - Returns True if the enumeration has been moved to the next element otherwise false
42
//The actual enumerator is not initialized!
43
if (actualEnum == NULL){
47
//Finalize the currentTerm and reset it to NULL
48
_CLDECDELETE( currentTerm );
50
//Iterate through the enumeration
51
while (currentTerm == NULL) {
54
if (actualEnum->next()) {
55
//Order term not to return reference ownership here. */
56
Term* term = actualEnum->term(false);
57
//Compare the retrieved term
58
if (termCompare(term)){
59
//Matched so finalize the current
60
_CLDECDELETE(currentTerm);
61
//Get a reference to the matched term
62
currentTerm = _CL_POINTER(term);
68
_CLDECDELETE(currentTerm);
74
Term* FilteredTermEnum::term(bool pointer) {
76
return _CL_POINTER(currentTerm);
81
void FilteredTermEnum::close(){
82
//Func - Closes the enumeration to further activity, freeing resources.
84
//Post - The Enumeration has been closed
86
//Check if actualEnum is valid
88
//Close the enumeration
90
//Destroy the enumeration
91
_CLDELETE(actualEnum);
95
_CLDECDELETE(currentTerm);
98
void FilteredTermEnum::setEnum(TermEnum* actualEnum) {
99
//Func - Sets the actual Enumeration
100
//Pre - actualEnum != NULL
101
//Post - The instance has been created
103
CND_PRECONDITION(actualEnum != NULL,"actualEnum is NULL");
105
_CLLDELETE(this->actualEnum);
106
this->actualEnum = actualEnum;
108
// Find the first term that matches
109
//Ordered term not to return reference ownership here.
110
Term* term = actualEnum->term(false);
111
if (term != NULL && termCompare(term)){
112
_CLDECDELETE(currentTerm);
113
currentTerm = _CL_POINTER(term);