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

« back to all changes in this revision

Viewing changes to src/CLucene/search/SearchHeader.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/StdHeader.h"
8
 
#include "SearchHeader.h"
9
 
#include "BooleanQuery.h"
10
 
#include "FieldDocSortedHitQueue.h"
11
 
 
12
 
CL_NS_USE(index)
13
 
CL_NS_DEF(search)
14
 
 
15
 
CL_NS(document)::Document* Searchable::doc(const int32_t i){
16
 
    CL_NS(document)::Document* ret = _CLNEW CL_NS(document)::Document;
17
 
    if (!doc(i,ret) )
18
 
        _CLDELETE(ret);
19
 
    return ret;
20
 
}
21
 
 
22
 
//static
23
 
Query* Query::mergeBooleanQueries(Query** queries) {
24
 
    CL_NS(util)::CLVector<BooleanClause*> allClauses;
25
 
    int32_t i = 0;
26
 
    while ( queries[i] != NULL ){
27
 
                BooleanQuery* bq = (BooleanQuery*)queries[i];
28
 
                
29
 
                int32_t size = bq->getClauseCount();
30
 
                BooleanClause** clauses = _CL_NEWARRAY(BooleanClause*, size);
31
 
                bq->getClauses(clauses);
32
 
                
33
 
                for (int32_t j = 0;j<size;++j ){
34
 
                        allClauses.push_back(clauses[j]);
35
 
                        j++;
36
 
                }
37
 
                _CLDELETE_ARRAY(clauses);
38
 
                i++;
39
 
    }
40
 
 
41
 
    BooleanQuery* result = _CLNEW BooleanQuery();
42
 
    CL_NS(util)::CLVector<BooleanClause*>::iterator itr = allClauses.begin();
43
 
    while (itr != allClauses.end() ) {
44
 
                result->add(*itr);
45
 
    }
46
 
    return result;
47
 
}
48
 
 
49
 
Query::Query(const Query& clone):boost(clone.boost){
50
 
                //constructor
51
 
}
52
 
Weight* Query::_createWeight(Searcher* searcher){
53
 
        _CLTHROWA(CL_ERR_UnsupportedOperation,"UnsupportedOperationException: Query::_createWeight");
54
 
}
55
 
 
56
 
Query::Query():
57
 
   boost(1.0f)
58
 
{
59
 
        //constructor
60
 
}
61
 
Query::~Query(){
62
 
}
63
 
 
64
 
/** Expert: called to re-write queries into primitive queries. */
65
 
Query* Query::rewrite(CL_NS(index)::IndexReader* reader){
66
 
   return this;
67
 
}
68
 
 
69
 
Query* Query::combine(Query** queries){
70
 
   _CLTHROWA(CL_ERR_UnsupportedOperation,"UnsupportedOperationException: Query::combine");
71
 
}
72
 
Similarity* Query::getSimilarity(Searcher* searcher) {
73
 
   return searcher->getSimilarity();
74
 
}
75
 
bool Query::instanceOf(const TCHAR* other) const{
76
 
   const TCHAR* t = getQueryName();
77
 
        if ( t==other || _tcscmp( t, other )==0 )
78
 
                return true;
79
 
        else
80
 
                return false;
81
 
}
82
 
TCHAR* Query::toString() const{
83
 
   return toString(LUCENE_BLANK_STRING);
84
 
}
85
 
 
86
 
void Query::setBoost(float_t b) { boost = b; }
87
 
 
88
 
float_t Query::getBoost() const { return boost; }
89
 
 
90
 
Weight* Query::weight(Searcher* searcher){
91
 
    Query* query = searcher->rewrite(this);
92
 
    Weight* weight = query->_createWeight(searcher);
93
 
    float_t sum = weight->sumOfSquaredWeights();
94
 
    float_t norm = getSimilarity(searcher)->queryNorm(sum);
95
 
    weight->normalize(norm);
96
 
    return weight;
97
 
}
98
 
 
99
 
TopFieldDocs::TopFieldDocs (int32_t totalHits, FieldDoc** fieldDocs, int32_t scoreDocsLen, SortField** fields):
100
 
 TopDocs (totalHits, NULL, scoreDocsLen)
101
 
{
102
 
        this->fields = fields;
103
 
        this->fieldDocs = fieldDocs;
104
 
        this->scoreDocs = _CL_NEWARRAY(ScoreDoc,scoreDocsLen);
105
 
        for (int32_t i=0;i<scoreDocsLen;i++ )
106
 
                this->scoreDocs[i] = this->fieldDocs[i]->scoreDoc;
107
 
}
108
 
TopFieldDocs::~TopFieldDocs(){
109
 
        if ( fieldDocs ){
110
 
                for (int32_t i=0;i<scoreDocsLength;i++)
111
 
                        _CLDELETE(fieldDocs[i]);
112
 
                _CLDELETE_ARRAY(fieldDocs);
113
 
        }
114
 
        if ( fields != NULL ){
115
 
       for ( int i=0;fields[i]!=NULL;i++ )
116
 
           _CLDELETE(fields[i]);
117
 
       _CLDELETE_ARRAY(fields);
118
 
    }
119
 
}
120
 
 
121
 
TopDocs::TopDocs(const int32_t th, ScoreDoc*sds, int32_t scoreDocsLen):
122
 
    totalHits(th),
123
 
        scoreDocsLength(scoreDocsLen),
124
 
        scoreDocs(sds)
125
 
{
126
 
//Func - Constructor
127
 
//Pre  - sds may or may not be NULL
128
 
//       sdLength >= 0
129
 
//Post - The instance has been created
130
 
 
131
 
}
132
 
 
133
 
TopDocs::~TopDocs(){
134
 
//Func - Destructor
135
 
//Pre  - true
136
 
//Post - The instance has been destroyed
137
 
 
138
 
        _CLDELETE_ARRAY(scoreDocs);
139
 
}
140
 
 
141
 
CL_NS_END