summaryrefslogtreecommitdiffstats
path: root/3rdparty/clucene/src/CLucene/search/Compare.h
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/Compare.h
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/Compare.h')
-rw-r--r--3rdparty/clucene/src/CLucene/search/Compare.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/3rdparty/clucene/src/CLucene/search/Compare.h b/3rdparty/clucene/src/CLucene/search/Compare.h
new file mode 100644
index 000000000..ab38b17f1
--- /dev/null
+++ b/3rdparty/clucene/src/CLucene/search/Compare.h
@@ -0,0 +1,161 @@
+/*------------------------------------------------------------------------------
+* 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.
+------------------------------------------------------------------------------*/
+#ifndef _lucene_search_Compare_
+#define _lucene_search_Compare_
+
+#if defined(_LUCENE_PRAGMA_ONCE)
+# pragma once
+#endif
+
+#include "FieldSortedHitQueue.h"
+
+CL_NS_DEF(search)
+
+
+class ScoreDocComparators:LUCENE_BASE {
+protected:
+ ScoreDocComparators(){}
+public:
+ ~ScoreDocComparators(){
+ }
+
+ class Relevance:public ScoreDocComparator {
+ public:
+ int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j) {
+ if (i->score > j->score) return -1;
+ if (i->score < j->score) return 1;
+ return 0;
+ }
+ CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i) {
+ return _CLNEW CL_NS(util)::Compare::Float (i->score);
+ }
+ int32_t sortType() {
+ return SortField::DOCSCORE;
+ }
+ };
+
+ class IndexOrder:public ScoreDocComparator{
+ public:
+ IndexOrder():
+ ScoreDocComparator()
+ {
+
+ }
+ int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j) {
+ if (i->doc < j->doc) return -1;
+ if (i->doc > j->doc) return 1;
+ return 0;
+ }
+ CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i) {
+ return _CLNEW CL_NS(util)::Compare::Int32(i->doc);
+ }
+ int32_t sortType() {
+ return SortField::DOC;
+ }
+ };
+
+
+ class String: public ScoreDocComparator {
+ FieldCache::StringIndex* index;
+#ifdef _CL__CND_DEBUG
+ int32_t length;
+#endif
+ public:
+ String(FieldCache::StringIndex* index, int32_t len)
+ {
+#ifdef _CL__CND_DEBUG
+ this->length = len;
+#endif
+ this->index = index;
+ }
+
+ int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j) {
+ CND_PRECONDITION(i->doc<length, "i->doc>=length")
+ CND_PRECONDITION(j->doc<length, "j->doc>=length")
+ if (index->order[i->doc] < index->order[j->doc]) return -1;
+ if (index->order[i->doc] > index->order[j->doc]) return 1;
+ return 0;
+ }
+
+ CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i) {
+ return _CLNEW CL_NS(util)::Compare::TChar(index->lookup[index->order[i->doc]]);
+ }
+
+ int32_t sortType() {
+ return SortField::STRING;
+ }
+ };
+
+ class Int32:public ScoreDocComparator{
+ int32_t* fieldOrder;
+#ifdef _CL__CND_DEBUG
+ int32_t length;
+#endif
+ public:
+ Int32(int32_t* fieldOrder, int32_t len)
+ {
+ this->fieldOrder = fieldOrder;
+#ifdef _CL__CND_DEBUG
+ this->length = len;
+#endif
+ }
+
+
+ int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j) {
+ CND_PRECONDITION(i->doc<length, "i->doc>=length")
+ CND_PRECONDITION(j->doc<length, "j->doc>=length")
+ if (fieldOrder[i->doc] < fieldOrder[j->doc]) return -1;
+ if (fieldOrder[i->doc] > fieldOrder[j->doc]) return 1;
+ return 0;
+ }
+
+ CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i) {
+ CND_PRECONDITION(i->doc<length, "i->doc>=length")
+ return _CLNEW CL_NS(util)::Compare::Int32(fieldOrder[i->doc]);
+ }
+
+ int32_t sortType() {
+ return SortField::INT;
+ }
+ };
+
+ class Float:public ScoreDocComparator {
+ qreal* fieldOrder;
+#ifdef _CL__CND_DEBUG
+ int32_t length;
+#endif
+ public:
+ Float(qreal* fieldOrder, int32_t len)
+ {
+ this->fieldOrder = fieldOrder;
+#ifdef _CL__CND_DEBUG
+ this->length = len;
+#endif
+ }
+
+ int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j) {
+ CND_PRECONDITION(i->doc<length, "i->doc>=length")
+ CND_PRECONDITION(j->doc<length, "j->doc>=length")
+ if (fieldOrder[i->doc] < fieldOrder[j->doc]) return -1;
+ if (fieldOrder[i->doc] > fieldOrder[j->doc]) return 1;
+ return 0;
+ }
+
+ CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i) {
+ CND_PRECONDITION(i->doc<length, "i->doc>=length")
+ return _CLNEW CL_NS(util)::Compare::Float(fieldOrder[i->doc]);
+ }
+
+ int32_t sortType() {
+ return SortField::FLOAT;
+ }
+ };
+};
+
+
+CL_NS_END
+#endif