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/StdHeader.h"
8
#include "SearchHeader.h"
9
#include "BooleanQuery.h"
10
#include "FieldDocSortedHitQueue.h"
15
CL_NS(document)::Document* Searchable::doc(const int32_t i){
16
CL_NS(document)::Document* ret = _CLNEW CL_NS(document)::Document;
23
Query* Query::mergeBooleanQueries(Query** queries) {
24
CL_NS(util)::CLVector<BooleanClause*> allClauses;
26
while ( queries[i] != NULL ){
27
BooleanQuery* bq = (BooleanQuery*)queries[i];
29
int32_t size = bq->getClauseCount();
30
BooleanClause** clauses = _CL_NEWARRAY(BooleanClause*, size);
31
bq->getClauses(clauses);
33
for (int32_t j = 0;j<size;++j ){
34
allClauses.push_back(clauses[j]);
37
_CLDELETE_ARRAY(clauses);
41
BooleanQuery* result = _CLNEW BooleanQuery();
42
CL_NS(util)::CLVector<BooleanClause*>::iterator itr = allClauses.begin();
43
while (itr != allClauses.end() ) {
49
Query::Query(const Query& clone):boost(clone.boost){
52
Weight* Query::_createWeight(Searcher* searcher){
53
_CLTHROWA(CL_ERR_UnsupportedOperation,"UnsupportedOperationException: Query::_createWeight");
64
/** Expert: called to re-write queries into primitive queries. */
65
Query* Query::rewrite(CL_NS(index)::IndexReader* reader){
69
Query* Query::combine(Query** queries){
70
_CLTHROWA(CL_ERR_UnsupportedOperation,"UnsupportedOperationException: Query::combine");
72
Similarity* Query::getSimilarity(Searcher* searcher) {
73
return searcher->getSimilarity();
75
bool Query::instanceOf(const TCHAR* other) const{
76
const TCHAR* t = getQueryName();
77
if ( t==other || _tcscmp( t, other )==0 )
82
TCHAR* Query::toString() const{
83
return toString(LUCENE_BLANK_STRING);
86
void Query::setBoost(float_t b) { boost = b; }
88
float_t Query::getBoost() const { return boost; }
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);
99
TopFieldDocs::TopFieldDocs (int32_t totalHits, FieldDoc** fieldDocs, int32_t scoreDocsLen, SortField** fields):
100
TopDocs (totalHits, NULL, scoreDocsLen)
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;
108
TopFieldDocs::~TopFieldDocs(){
110
for (int32_t i=0;i<scoreDocsLength;i++)
111
_CLDELETE(fieldDocs[i]);
112
_CLDELETE_ARRAY(fieldDocs);
114
if ( fields != NULL ){
115
for ( int i=0;fields[i]!=NULL;i++ )
116
_CLDELETE(fields[i]);
117
_CLDELETE_ARRAY(fields);
121
TopDocs::TopDocs(const int32_t th, ScoreDoc*sds, int32_t scoreDocsLen):
123
scoreDocsLength(scoreDocsLen),
127
//Pre - sds may or may not be NULL
129
//Post - The instance has been created
136
//Post - The instance has been destroyed
138
_CLDELETE_ARRAY(scoreDocs);