summaryrefslogtreecommitdiffstats
path: root/3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit50123887ba0f33cf47520bee7c419d68742af2d1 (patch)
tree0eb8679b9e4e4370e59b44bfdcae616816e39aca /3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to '3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp')
-rw-r--r--3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp b/3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp
new file mode 100644
index 000000000..f90ceeaaf
--- /dev/null
+++ b/3rdparty/clucene/src/CLucene/search/FilteredTermEnum.cpp
@@ -0,0 +1,136 @@
+/*------------------------------------------------------------------------------
+* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
+*
+* Distributable under the terms of either the Apache License (Version 2.0) or
+* the GNU Lesser General Public License, as specified in the COPYING file.
+------------------------------------------------------------------------------*/
+#include "CLucene/StdHeader.h"
+
+#include "FilteredTermEnum.h"
+
+CL_NS_USE(index)
+CL_NS_DEF(search)
+
+
+ FilteredTermEnum::FilteredTermEnum(){
+ //Func - Constructor
+ //Pre - true
+ //Post - Instance has been created
+
+ currentTerm = NULL;
+ actualEnum = NULL;
+ }
+
+ FilteredTermEnum::~FilteredTermEnum() {
+ //Func - Destructor
+ //Pre - true
+ //Post - The instance has been destroyed
+
+ close();
+ }
+
+ int32_t FilteredTermEnum::docFreq() const {
+ //Func - Returns the docFreq of the current Term in the enumeration.
+ //Pre - next() must have been called at least once
+ //Post - if actualEnum is NULL result is -1 otherwise the frequencey is returned
+
+ if (actualEnum == NULL){
+ return -1;
+ }
+ return actualEnum->docFreq();
+ }
+
+ bool FilteredTermEnum::next() {
+ //Func - Increments the enumeration to the next element.
+ //Pre - true
+ //Post - Returns True if the enumeration has been moved to the next element otherwise false
+
+ //The actual enumerator is not initialized!
+ if (actualEnum == NULL){
+ return false;
+ }
+
+ //Finalize the currentTerm and reset it to NULL
+ _CLDECDELETE( currentTerm );
+
+ //Iterate through the enumeration
+ while (currentTerm == NULL) {
+ if (endEnum())
+ return false;
+ if (actualEnum->next()) {
+ //Order term not to return reference ownership here. */
+ Term* term = actualEnum->term(false);
+ //Compare the retrieved term
+ if (termCompare(term)){
+ //Matched so finalize the current
+ _CLDECDELETE(currentTerm);
+ //Get a reference to the matched term
+ currentTerm = _CL_POINTER(term);
+ return true;
+ }
+ }else
+ return false;
+ }
+ _CLDECDELETE(currentTerm);
+ currentTerm = NULL;
+
+ return false;
+ }
+
+ Term* FilteredTermEnum::term() {
+ //Func - Returns the current Term in the enumeration.
+ //Pre - next() must have been called at least once
+ // pointer is true or false
+ //Post - if pre(pointer) is true the reference counter of currentTerm is increased
+ // and current Term is returned otherwise currentTerm is only returned
+
+ return _CL_POINTER(currentTerm);
+ }
+ Term* FilteredTermEnum::term(bool pointer) {
+ if ( pointer )
+ return _CL_POINTER(currentTerm);
+ else
+ return currentTerm;
+ }
+
+ void FilteredTermEnum::close(){
+ //Func - Closes the enumeration to further activity, freeing resources.
+ //Pre - true
+ //Post - The Enumeration has been closed
+
+ //Check if actualEnum is valid
+ if (actualEnum){
+ //Close the enumeration
+ actualEnum->close();
+ }
+
+ //Destroy the enumeration
+ _CLDELETE(actualEnum);
+
+ //Destroy currentTerm
+ _CLDECDELETE(currentTerm);
+ }
+
+ void FilteredTermEnum::setEnum(TermEnum* actualEnum) {
+ //Func - Sets the actual Enumeration
+ //Pre - actualEnum != NULL
+ //Post - The instance has been created
+
+ CND_PRECONDITION(actualEnum != NULL,"actualEnum is NULL");
+
+ _CLDELETE(this->actualEnum);
+
+ this->actualEnum = actualEnum;
+
+ // Find the first term that matches
+ //Ordered term not to return reference ownership here.
+ Term* term = actualEnum->term(false);
+ if (term != NULL && termCompare(term)){
+ _CLDECDELETE(currentTerm);
+ currentTerm = _CL_POINTER(term);
+ }else{
+ next();
+ }
+ }
+
+CL_NS_END