~ubuntu-branches/ubuntu/raring/clucene-core/raring-proposed

« back to all changes in this revision

Viewing changes to src/core/CLucene/search/FilteredTermEnum.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-08-11 09:33:38 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120811093338-fgrx41ftqew3qt6a
Tags: 2.3.3.4-1
* New upstream release (Closes: #661703).
* Convert package to multiarch.
* Drop obsolete patches:
  - 01_add_missing_include_bug505667.diff
  - 02_posixness_fix_bug530308.diff
* Add patches:
  - Fixing_ZLIB_configuration_in_shared_CMakeLists.patch
  - Fix-pkgconfig-file-by-adding-clucene-shared-library.patch
  - Install-contribs-lib.patch
  - multiarch.patch
* Update debian/compat: bump to 8.
* Update debian/control:
  - update build dependencies (add cmake, libboost-dev and libz-dev).
  - bump Standards-Version to 3.9.3.
  - rename packages due to ABI bump: libclucene0ldbl -> libclucene-core1.
  - add libclucene-contribs1 package.
* Update debian/rules:
  - rewrite to use CMake.
  - add multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------------
 
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
 
3
 
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"
 
10
 
 
11
CL_NS_USE(index)
 
12
CL_NS_DEF(search)
 
13
 
 
14
 
 
15
FilteredTermEnum::FilteredTermEnum():currentTerm(NULL),actualEnum(NULL){
 
16
}
 
17
 
 
18
    FilteredTermEnum::~FilteredTermEnum() {
 
19
    //Func - Destructor
 
20
        //Pre  - true
 
21
        //Post - The instance has been destroyed
 
22
      
 
23
        close();
 
24
    }
 
25
 
 
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
 
30
 
 
31
                if (actualEnum == NULL){
 
32
                        return -1;
 
33
                }
 
34
        return actualEnum->docFreq();
 
35
    }
 
36
    
 
37
    bool FilteredTermEnum::next() {
 
38
    //Func - Increments the enumeration to the next element.  
 
39
        //Pre  - true
 
40
        //Post - Returns True if the enumeration has been moved to the next element otherwise false
 
41
 
 
42
                //The actual enumerator is not initialized!
 
43
                if (actualEnum == NULL){
 
44
                        return false; 
 
45
                }
 
46
                
 
47
                //Finalize the currentTerm and reset it to NULL
 
48
       _CLDECDELETE( currentTerm );
 
49
 
 
50
                //Iterate through the enumeration
 
51
        while (currentTerm == NULL) {
 
52
            if (endEnum()) 
 
53
                                return false;
 
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);
 
63
                    return true;
 
64
                }
 
65
            }else 
 
66
                return false;
 
67
        }
 
68
        _CLDECDELETE(currentTerm);
 
69
        currentTerm = NULL;
 
70
 
 
71
        return false;
 
72
    }
 
73
 
 
74
    Term* FilteredTermEnum::term(bool pointer) {
 
75
        if ( pointer )
 
76
        return _CL_POINTER(currentTerm);
 
77
      else
 
78
        return currentTerm;
 
79
    }
 
80
 
 
81
    void FilteredTermEnum::close(){
 
82
        //Func - Closes the enumeration to further activity, freeing resources.
 
83
        //Pre  - true
 
84
        //Post - The Enumeration has been closed
 
85
 
 
86
                //Check if actualEnum is valid
 
87
                if (actualEnum){
 
88
                        //Close the enumeration
 
89
                        actualEnum->close();
 
90
                        //Destroy the enumeration
 
91
                        _CLDELETE(actualEnum);
 
92
                }
 
93
 
 
94
                //Destroy currentTerm
 
95
        _CLDECDELETE(currentTerm);
 
96
    }
 
97
 
 
98
        void FilteredTermEnum::setEnum(TermEnum* actualEnum) {
 
99
        //Func - Sets the actual Enumeration
 
100
        //Pre  - actualEnum != NULL
 
101
        //Post - The instance has been created
 
102
 
 
103
                CND_PRECONDITION(actualEnum != NULL,"actualEnum is NULL");
 
104
 
 
105
                _CLLDELETE(this->actualEnum);
 
106
        this->actualEnum = actualEnum;
 
107
 
 
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);
 
114
        }else{
 
115
            next();
 
116
                }
 
117
    }
 
118
 
 
119
CL_NS_END