|
From: <ust...@us...> - 2009-09-27 08:58:11
|
Revision: 3021
http://clucene.svn.sourceforge.net/clucene/?rev=3021&view=rev
Author: ustramooner
Date: 2009-09-27 08:58:03 +0000 (Sun, 27 Sep 2009)
Log Message:
-----------
Isidor's merge norms bug fix
+a -b bug in BooleanScorer2 test
fix for BooleanScorer constuctor
fix for bad StringBuffer memory handling (new code for releasing memory early caused asserts and generally incompatible functionality)
BooleanScorer had faulty Token code
Modified Paths:
--------------
branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParser.cpp
branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParserTokenManager.cpp
branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParser.cpp
branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParserBase.cpp
branches/lucene2_3_2/src/core/CLucene/search/BooleanScorer.cpp
branches/lucene2_3_2/src/core/CLucene/search/Explanation.cpp
branches/lucene2_3_2/src/core/CLucene/search/FuzzyQuery.cpp
branches/lucene2_3_2/src/core/CLucene/search/MatchAllDocsQuery.cpp
branches/lucene2_3_2/src/core/CLucene/search/MultiPhraseQuery.cpp
branches/lucene2_3_2/src/core/CLucene/search/PhraseQuery.cpp
branches/lucene2_3_2/src/core/CLucene/search/_BooleanScorer.h
branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp
branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.h
branches/lucene2_3_2/src/test/index/TestIndexWriter.cpp
branches/lucene2_3_2/src/test/search/TestSearch.cpp
Modified: branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParser.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParser.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParser.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -633,7 +633,7 @@
// and declare we are the owners of the buffer (to save on a copy)
// TODO: 1. Test to see what is the optimal initial length
// 2. Allow re-using the provided string buffer (argument s) instead of creating another one?
- StringBuffer sb(len+5,false);
+ StringBuffer sb(len+5);
for (size_t i = 0; i < len; i++) {
const TCHAR c = s[i];
// These characters are part of the query syntax and must be escaped
@@ -644,7 +644,7 @@
}
sb.appendChar(c);
}
- return sb.getBuffer();
+ return sb.giveBuffer();
}
int32_t QueryParser::Conjunction() {
@@ -1072,7 +1072,7 @@
s = _ttoi(fuzzySlop->image + 1);
}
catch (...) { /* ignore exceptions */ }
- }
+ }
// TODO: Make sure this hack, save an extra dup, is legal and not harmful
const size_t st = _tcslen(term->image);
term->image[st-1]=NULL;
@@ -1378,7 +1378,7 @@
TCHAR* QueryParserConstants::addEscapes(TCHAR* str) {
const size_t len = _tcslen(str);
- StringBuffer retval(len * 2, false);
+ StringBuffer retval(len * 2);
TCHAR ch;
for (size_t i = 0; i < len; i++) {
switch (str[i])
@@ -1421,7 +1421,7 @@
continue;
}
}
- return retval.getBuffer();
+ return retval.giveBuffer();
}
TCHAR* QueryParser::getParseExceptionMessage(QueryToken* currentToken,
@@ -1449,7 +1449,7 @@
expected.append(_T(" "));
}
- StringBuffer retval(CL_MAX_PATH, false);
+ StringBuffer retval(CL_MAX_PATH);
retval.append(_T("Encountered \""));
QueryToken* tok = currentToken->next;
for (size_t i = 0; i < maxSize; i++) {
@@ -1482,7 +1482,7 @@
}
retval.append(expected.getBuffer());
- return retval.getBuffer();
+ return retval.giveBuffer();
}
CL_NS_END
Modified: branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParserTokenManager.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParserTokenManager.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/queryParser/QueryParserTokenManager.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1237,7 +1237,7 @@
int32_t errorColumn, TCHAR* errorAfter, TCHAR curChar)
{
TCHAR* tmp = NULL;
- CL_NS(util)::StringBuffer sb(100, false);
+ CL_NS(util)::StringBuffer sb(100);
sb.append(_T("Lexical error at line "));
sb.appendInt(errorLine);
sb.append(_T(", column "));
@@ -1260,7 +1260,7 @@
_CLDELETE_LCARRAY(tmp);
sb.appendChar(_T('"'));
- return sb.getBuffer();
+ return sb.giveBuffer();
}
CL_NS_END // QueryParserTokenManager
Modified: branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParser.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParser.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParser.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -244,7 +244,7 @@
Query* q = NULL;
const TCHAR* sfield = field;
- TCHAR* tmp;
+ TCHAR* tmp = NULL;
QueryToken *DelToken = NULL;
Modified: branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParserBase.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParserBase.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/queryParser/legacy/QueryParserBase.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -148,29 +148,27 @@
StringArrayWithDeletor v;
- Token* t = NULL;
+ Token t;
int positionCount = 0;
bool severalTokensAtSamePosition = false;
//Get the tokens from the source
try{
- while (source->next(t)){
- v.push_back(STRDUP_TtoT(t->termBuffer()));
+ while (source->next(&t)){
+ v.push_back(STRDUP_TtoT(t.termBuffer()));
- if (t->getPositionIncrement() != 0)
- positionCount += t->getPositionIncrement();
+ if (t.getPositionIncrement() != 0)
+ positionCount += t.getPositionIncrement();
else
severalTokensAtSamePosition = true;
}
}catch(CLuceneError& err){
if ( err.number() != CL_ERR_IO ) {
- _CLDELETE(t);
_CLLDELETE(source);
throw err;
}
}
_CLDELETE(source);
- _CLDELETE(t);
//Check if there are any tokens retrieved
if (v.size() == 0){
@@ -240,13 +238,13 @@
TCHAR* terms[2];
terms[0]=NULL;terms[1]=NULL;
- Token* t = NULL;
+ Token t;
bool tret=false;
bool from=true;
while(tret)
{
try{
- tret = (source->next(t) != NULL);
+ tret = (source->next(&t) != NULL);
}catch (CLuceneError& err){
if ( err.number() == CL_ERR_IO )
tret=false;
@@ -255,11 +253,11 @@
}
if (tret)
{
- if ( !from && _tcscmp(t->termBuffer(),_T("TO"))==0 )
+ if ( !from && _tcscmp(t.termBuffer(),_T("TO"))==0 )
continue;
- TCHAR* tmp = STRDUP_TtoT(t->termBuffer());
+ TCHAR* tmp = STRDUP_TtoT(t.termBuffer());
discardEscapeChar(tmp);
terms[from? 0 : 1] = tmp;
@@ -276,7 +274,6 @@
_CLDELETE_CARRAY(terms[0]);
_CLDELETE_CARRAY(terms[1]);
_CLDELETE(source);
- _CLDELETE(t);
return ret;
}
Modified: branches/lucene2_3_2/src/core/CLucene/search/BooleanScorer.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/BooleanScorer.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/BooleanScorer.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -15,12 +15,6 @@
CL_NS_USE(util)
CL_NS_DEF(search)
- BooleanScorer::BooleanScorer(Similarity* similarity):
- Scorer(similarity)
- {
- BooleanScorer( similarity, 1 );
- }
-
BooleanScorer::BooleanScorer(Similarity* similarity, int32_t minNrShouldMatch ):
Scorer(similarity),
scorers(NULL),
Modified: branches/lucene2_3_2/src/core/CLucene/search/Explanation.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/Explanation.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/Explanation.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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/_ApiHeader.h"
@@ -42,8 +42,8 @@
}
}
}
-Explanation* Explanation::clone() const{
- return _CLNEW Explanation(*this);
+Explanation* Explanation::clone() const{
+ return _CLNEW Explanation(*this);
}
Explanation::~Explanation(){
@@ -54,26 +54,26 @@
return (0.0f < getValue());
}
-float_t Explanation::getValue() const{
- return value;
+float_t Explanation::getValue() const{
+ return value;
}
-void Explanation::setValue(const float_t value) {
- this->value = value;
+void Explanation::setValue(const float_t value) {
+ this->value = value;
}
-const TCHAR* Explanation::getDescription() const {
- return description;
+const TCHAR* Explanation::getDescription() const {
+ return description;
}
void Explanation::setDescription(const TCHAR* description) {
_tcsncpy(this->description,description,LUCENE_SEARCH_EXPLANATION_DESC_LEN);
}
TCHAR* Explanation::getSummary() {
- StringBuffer buf(210, false);
+ StringBuffer buf(210);
buf.appendFloat(getValue(), 2);
buf.append(_T(" = "));
buf.append(getDescription());
- return buf.getBuffer();
+ return buf.giveBuffer();
}
size_t Explanation::getDetailsLength() const {return (details==NULL)?0:details->size();}
@@ -156,15 +156,15 @@
bool ComplexExplanation::isMatch() const {return getMatch();}
TCHAR* ComplexExplanation::getSummary() {
- StringBuffer buf(220, false);
+ StringBuffer buf(220);
buf.appendFloat(getValue(),2);
buf.append(_T(" = "));
buf.append(isMatch() ? _T("(MATCH) ") : _T("(NON-MATCH) "));
buf.append(getDescription());
- return buf.getBuffer();
+ return buf.giveBuffer();
}
-Explanation* ComplexExplanation::clone() const{
+Explanation* ComplexExplanation::clone() const{
ComplexExplanation* ret = static_cast<ComplexExplanation*>(_CLNEW Explanation(*this));
ret->match = this->match;
return ret;
Modified: branches/lucene2_3_2/src/core/CLucene/search/FuzzyQuery.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/FuzzyQuery.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/FuzzyQuery.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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/_ApiHeader.h"
@@ -20,14 +20,14 @@
CL_NS_USE(util)
CL_NS_DEF(search)
-
-/** Finds and returns the smallest of three integers
+
+/** Finds and returns the smallest of three integers
* precondition: Must define int32_t __t for temporary storage and result
*/
#define min3(a, b, c) __t = (a < b) ? a : b; __t = (__t < c) ? __t : c;
- FuzzyTermEnum::FuzzyTermEnum(IndexReader* reader, Term* term, float_t minSimilarity, size_t _prefixLength):
+ FuzzyTermEnum::FuzzyTermEnum(IndexReader* reader, Term* term, float_t minSimilarity, size_t _prefixLength):
FilteredTermEnum(),d(NULL),dWidth(0),dHeight(0),_similarity(0),_endEnum(false),searchTerm(_CL_POINTER(term)),
text(NULL),textLen(0),prefix(NULL)/* ISH: was STRDUP_TtoT(LUCENE_BLANK_STRING)*/,prefixLength(_prefixLength),
minimumSimilarity(minSimilarity)
@@ -84,7 +84,7 @@
}
*/
}
-
+
FuzzyTermEnum::~FuzzyTermEnum(){
close();
}
@@ -116,7 +116,7 @@
//Pre - term is NULL or term points to a Term
//Post - if pre(term) is NULL then false is returned otherwise
// if the distance of the current term in the enumeration is bigger than the FUZZY_THRESHOLD
- // then true is returned
+ // then true is returned
if (term == NULL){
return false; //Note that endEnum is not set to true!
@@ -127,7 +127,7 @@
//Check if the field name of searchTerm of term match
//(we can use == because fields are interned)
- if ( searchTerm->field() == term->field() &&
+ if ( searchTerm->field() == term->field() &&
(prefixLength==0 || _tcsncmp(termText,prefix,prefixLength)==0 )) {
const TCHAR* target = termText+prefixLength;
@@ -253,7 +253,7 @@
int32_t FuzzyTermEnum::calculateMaxDistance(const size_t m) const {
return (int32_t) ((1-minimumSimilarity) * (cl_min(textLen, m) + prefixLength));
}
-
+
/* LEGACY:
int32_t FuzzyTermEnum::editDistance(const TCHAR* s, const TCHAR* t, const int32_t n, const int32_t m) {
//Func - Calculates the Levenshtein distance also known as edit distance is a measure of similiarity
@@ -275,9 +275,9 @@
int32_t j; // iterates through t
TCHAR s_i; // ith character of s
- if (n == 0)
+ if (n == 0)
return m;
- if (m == 0)
+ if (m == 0)
return n;
//Check if the array must be reallocated because it is too small or does not exist
@@ -370,7 +370,7 @@
_CLTHROWA(CL_ERR_IllegalArgument,"prefixLength >= term.textLength()");
*/
}
-
+
float_t FuzzyQuery::defaultMinSimilarity = 0.5f;
int32_t FuzzyQuery::defaultPrefixLength = 0;
@@ -386,7 +386,7 @@
}
TCHAR* FuzzyQuery::toString(const TCHAR* field) const{
- StringBuffer buffer(100, false); // TODO: Have a better estimation for the initial buffer length
+ StringBuffer buffer(100); // TODO: Have a better estimation for the initial buffer length
Term* term = getTerm(false); // no need to increase ref count
if ( field==NULL || _tcscmp(term->field(),field)!=0 ) {
buffer.append(term->field());
@@ -396,7 +396,7 @@
buffer.appendChar( _T('~') );
buffer.appendFloat(minimumSimilarity,1);
buffer.appendBoost(getBoost());
- return buffer.getBuffer();
+ return buffer.giveBuffer();
}
const char* FuzzyQuery::getObjectName() const{
@@ -422,7 +422,7 @@
//if(prefixLength < 0)
// _CLTHROWA(CL_ERR_IllegalArgument,"prefixLength < 0");
- //else
+ //else
if(prefixLength >= clone.getTerm()->textLength())
_CLTHROWA(CL_ERR_IllegalArgument,"prefixLength >= term.textLength()");
@@ -451,7 +451,7 @@
&& this->prefixLength == fq->getPrefixLength()
&& getTerm()->equals(fq->getTerm());
}
-
+
FilteredTermEnum* FuzzyQuery::getEnum(IndexReader* reader){
Term* term = getTerm(false);
FuzzyTermEnum* ret = _CLNEW FuzzyTermEnum(reader, term, minimumSimilarity, prefixLength);
Modified: branches/lucene2_3_2/src/core/CLucene/search/MatchAllDocsQuery.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/MatchAllDocsQuery.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/MatchAllDocsQuery.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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/_ApiHeader.h"
@@ -58,15 +58,15 @@
}
TCHAR* MatchAllDocsQuery::MatchAllDocsWeight::toString() {
- CL_NS(util)::StringBuffer buf(50, false);
+ CL_NS(util)::StringBuffer buf(50);
buf.append(_T("weight("));
-
+
TCHAR* t = parentQuery->toString();
buf.append(t);
_CLDELETE_LCARRAY(t);
buf.appendChar(_T(')'));
- return buf.getBuffer();
+ return buf.giveBuffer();
}
Query* MatchAllDocsQuery::MatchAllDocsWeight::getQuery() {
@@ -116,10 +116,10 @@
}
TCHAR* MatchAllDocsQuery::toString(const TCHAR* field) const{
- CL_NS(util)::StringBuffer buffer(25, false);
+ CL_NS(util)::StringBuffer buffer(25);
buffer.append(_T("MatchAllDocsQuery"));
buffer.appendBoost(getBoost());
- return buffer.getBuffer();
+ return buffer.giveBuffer();
}
MatchAllDocsQuery::MatchAllDocsQuery(const MatchAllDocsQuery& clone){
Modified: branches/lucene2_3_2/src/core/CLucene/search/MultiPhraseQuery.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/MultiPhraseQuery.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/MultiPhraseQuery.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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/_ApiHeader.h"
@@ -69,7 +69,7 @@
void normalize(float_t _queryNorm) {
this->queryNorm = _queryNorm;
queryWeight *= _queryNorm; // normalize query weight
- value = queryWeight * idf; // idf for document
+ value = queryWeight * idf; // idf for document
}
Scorer* scorer(IndexReader* reader) {
@@ -289,7 +289,7 @@
}
TCHAR* MultiPhraseQuery::toString(const TCHAR* f) const {
- StringBuffer buffer(100, false);
+ StringBuffer buffer(100);
if (_tcscmp(f, field)!=0) {
buffer.append(field);
buffer.appendChar(_T(':'));
@@ -325,7 +325,7 @@
buffer.appendBoost(getBoost());
- return buffer.getBuffer();
+ return buffer.giveBuffer();
}
class TermArray_Equals:public CL_NS_STD(binary_function)<const Term**,const Term**,bool>
Modified: branches/lucene2_3_2/src/core/CLucene/search/PhraseQuery.cpp
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/PhraseQuery.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/PhraseQuery.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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/_ApiHeader.h"
@@ -120,7 +120,7 @@
//Func - Destructor
//Pre - true
//Post 0 The instance has been destroyed
-
+
//Iterate through all the terms
for (size_t i = 0; i < terms->size(); i++){
_CLLDECDELETE((*terms)[i]);
@@ -132,7 +132,7 @@
size_t PhraseQuery::hashCode() const {
//todo: do cachedHashCode, and invalidate on add/remove clause
size_t ret = Similarity::floatToByte(getBoost()) ^ Similarity::floatToByte(slop);
-
+
{ //msvc6 scope fix
for ( size_t i=0;terms->size();i++ )
ret = 31 * ret + (*terms)[i]->hashCode();
@@ -193,7 +193,7 @@
result.values[i] = (*positions)[i];
}
}
-
+
Weight* PhraseQuery::_createWeight(Searcher* searcher) {
if (terms->size() == 1) { // optimize one-term case
Term* term = (*terms)[0];
@@ -213,7 +213,7 @@
//Let size contain the number of terms
int32_t size = terms->size();
Term** ret = _CL_NEWARRAY(Term*,size+1);
-
+
CND_CONDITION(ret != NULL,"Could not allocated memory for ret");
//Iterate through terms and copy each pointer to ret
@@ -225,14 +225,14 @@
}
TCHAR* PhraseQuery::toString(const TCHAR* f) const{
- //Func - Prints a user-readable version of this query.
+ //Func - Prints a user-readable version of this query.
//Pre - f != NULL
//Post - The query string has been returned
if ( terms->size()== 0 )
return NULL;
- StringBuffer buffer(30,false);
+ StringBuffer buffer(32);
if ( f==NULL || _tcscmp(field,f)!=0) {
buffer.append(field);
buffer.appendChar(_T(':'));
@@ -262,10 +262,10 @@
buffer.appendBoost(getBoost());
- return buffer.getBuffer();
+ return buffer.giveBuffer();
}
-
+
PhraseWeight::PhraseWeight(Searcher* searcher, PhraseQuery* _parentQuery) {
this->parentQuery=_parentQuery;
this->value = 0;
@@ -275,13 +275,13 @@
this->searcher = searcher;
}
- TCHAR* PhraseWeight::toString() {
+ TCHAR* PhraseWeight::toString() {
return STRDUP_TtoT(_T("weight(PhraseQuery)"));
}
PhraseWeight::~PhraseWeight(){
}
-
+
Query* PhraseWeight::getQuery() { return parentQuery; }
float_t PhraseWeight::getValue() { return value; }
@@ -294,7 +294,7 @@
void PhraseWeight::normalize(float_t queryNorm) {
this->queryNorm = queryNorm;
queryWeight *= queryNorm; // normalize query weight
- value = queryWeight * idf; // idf for document
+ value = queryWeight * idf; // idf for document
}
Scorer* PhraseWeight::scorer(IndexReader* reader) {
@@ -306,9 +306,9 @@
const size_t tpsLength = parentQuery->terms->size();
//optimize zero-term case
- if (tpsLength == 0)
+ if (tpsLength == 0)
return NULL;
-
+
TermPositions** tps = _CL_NEWARRAY(TermPositions*,tpsLength+1);
//Check if tps has been allocated properly
@@ -320,14 +320,14 @@
for (size_t i = 0; i < tpsLength; i++) {
//Get the termPostitions for the i-th term
p = reader->termPositions((*parentQuery->terms)[i]);
-
+
//Check if p is valid
if (p == NULL) {
//Delete previous retrieved termPositions
while (--i >= 0){
_CLVDELETE(tps[i]); //todo: not a clucene object... should be
}
- _CLDELETE_ARRAY(tps);
+ _CLDELETE_ARRAY(tps);
return NULL;
}
@@ -343,12 +343,12 @@
int32_t slop = parentQuery->getSlop();
if ( slop != 0)
// optimize exact case
- //todo: need to pass these: this, tps,
+ //todo: need to pass these: this, tps,
ret = _CLNEW SloppyPhraseScorer(this,tps,positions.values,
- parentQuery->getSimilarity(searcher),
+ parentQuery->getSimilarity(searcher),
slop, reader->norms(parentQuery->field));
else
- ret = _CLNEW ExactPhraseScorer(this, tps, positions.values,
+ ret = _CLNEW ExactPhraseScorer(this, tps, positions.values,
parentQuery->getSimilarity(searcher),
reader->norms(parentQuery->field));
positions.deleteArray();
Modified: branches/lucene2_3_2/src/core/CLucene/search/_BooleanScorer.h
===================================================================
--- branches/lucene2_3_2/src/core/CLucene/search/_BooleanScorer.h 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/core/CLucene/search/_BooleanScorer.h 2009-09-27 08:58:03 UTC (rev 3021)
@@ -80,8 +80,7 @@
int32_t prohibitedMask;
float_t* coordFactors;
- BooleanScorer(Similarity* similarity);
- BooleanScorer( Similarity* similarity, int32_t minNrShouldMatch );
+ BooleanScorer( Similarity* similarity, int32_t minNrShouldMatch = 1 );
virtual ~BooleanScorer();
void add(Scorer* scorer, const bool required, const bool prohibited);
int32_t doc() const { return current->doc; }
Modified: branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp
===================================================================
--- branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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/_ApiHeader.h"
@@ -15,48 +15,48 @@
buffer = buf;
bufferLength = maxlen;
bufferOwner = !consumeBuffer;
- len = 0;
+ len = 0;
}
StringBuffer::StringBuffer(){
//Func - Constructor. Allocates a buffer with the default length.
//Pre - true
//Post - buffer of length bufferLength has been allocated
-
- //Initialize
- bufferLength = LUCENE_DEFAULT_TOKEN_BUFFER_SIZE;
- len = 0;
- //Allocate a buffer of length bufferLength
- buffer = _CL_NEWARRAY(TCHAR,bufferLength);
- bufferOwner = true;
+
+ //Initialize
+ bufferLength = LUCENE_DEFAULT_TOKEN_BUFFER_SIZE;
+ len = 0;
+ //Allocate a buffer of length bufferLength
+ buffer = _CL_NEWARRAY(TCHAR,bufferLength);
+ bufferOwner = true;
}
- StringBuffer::StringBuffer(const size_t initSize, const bool consumeBuffer){
+ StringBuffer::StringBuffer(const size_t initSize){
//Func - Constructor. Allocates a buffer of length initSize + 1
//Pre - initSize > 0
//Post - A buffer has been allocated of length initSize + 1
//Initialize the bufferLength to initSize + 1 The +1 is for the terminator '\0'
- bufferLength = initSize + 1;
- len = 0;
- //Allocate a buffer of length bufferLength
- buffer = _CL_NEWARRAY(TCHAR,bufferLength);
- bufferOwner = consumeBuffer;
+ bufferLength = initSize + 1;
+ len = 0;
+ //Allocate a buffer of length bufferLength
+ buffer = _CL_NEWARRAY(TCHAR,bufferLength);
+ bufferOwner = true;
}
StringBuffer::StringBuffer(const TCHAR* value){
- //Func - Constructor.
+ //Func - Constructor.
// Creates an instance of Stringbuffer containing a copy of the string value
//Pre - value != NULL
//Post - An instance of StringBuffer has been created containing the copy of the string value
-
+
//Initialize the length of the string to be stored in buffer
len = (size_t) _tcslen(value);
//Calculate the space occupied in buffer by a copy of value
const size_t occupiedLength = len + 1;
-
+
// Minimum allocated buffer length is LUCENE_DEFAULT_TOKEN_BUFFER_SIZE.
- bufferLength = (occupiedLength >= LUCENE_DEFAULT_TOKEN_BUFFER_SIZE
+ bufferLength = (occupiedLength >= LUCENE_DEFAULT_TOKEN_BUFFER_SIZE
? occupiedLength : LUCENE_DEFAULT_TOKEN_BUFFER_SIZE);
//Allocate a buffer of length bufferLength
@@ -73,11 +73,12 @@
// Pre - true
// Post - Instanc has been destroyed
- if( bufferOwner ){
- _CLDELETE_CARRAY(buffer);
- }else
- buffer = NULL;
+ if( bufferOwner ){
+ _CLDELETE_CARRAY(buffer);
+ }else
+ buffer = NULL;
}
+
void StringBuffer::clear(){
//Func - Clears the Stringbuffer and resets it to it default empty state
//Pre - true
@@ -87,9 +88,9 @@
// We should really look into at least providing both options
//Destroy the current buffer if present
- _CLDELETE_LCARRAY(buffer);
+ _CLDELETE_LCARRAY(buffer);
- //Initialize
+ //Initialize
len = 0;
bufferLength = LUCENE_DEFAULT_TOKEN_BUFFER_SIZE;
//Allocate a buffer of length bufferLength
@@ -97,13 +98,13 @@
}
void StringBuffer::appendChar(const TCHAR character) {
- //Func - Appends a single character
+ //Func - Appends a single character
//Pre - true
//Post - The character has been appended to the string in the buffer
//Check if the current buffer length is sufficient to have the string value appended
if (len + 1 > bufferLength){
- //Have the size of the current string buffer increased because it is too small
+ //Have the size of the current string buffer increased because it is too small
growBuffer(len + 1);
}
//Put character at position len which is the end of the string in the buffer
@@ -118,24 +119,24 @@
//Func - Appends a copy of the string value
//Pre - value != NULL
//Post - value has been copied and appended to the string in buffer
-
+
append(value, _tcslen(value));
}
void StringBuffer::append(const TCHAR* value, size_t appendedLength) {
//Func - Appends a copy of the string value
//Pre - value != NULL
// appendedLength contains the length of the string value which is to be appended
- //Post - value has been copied and appended to the string in buffer
-
+ //Post - value has been copied and appended to the string in buffer
+
//Check if the current buffer length is sufficient to have the string value appended
if (len + appendedLength + 1 > bufferLength){
- //Have the size of the current string buffer increased because it is too small
+ //Have the size of the current string buffer increased because it is too small
growBuffer(len + appendedLength + 1);
}
//Copy the string value into the buffer at postion len
_tcsncpy(buffer + len, value, appendedLength);
-
+
//Add the length of the copied string to len to reflect the new length of the string in
//the buffer (Note: len is not the bufferlength!)
len += appendedLength;
@@ -143,9 +144,9 @@
void StringBuffer::appendInt(const int64_t value, const int32_t _Radix) {
//Func - Appends an integer (after conversion to a character string)
- //Pre - true
+ //Pre - true
//Post - The converted integer value has been appended to the string in buffer
-
+
//instantiate a buffer of 30 charactes for the conversion of the integer
TCHAR buf[30];
//Convert the integer value to a string buf using _Radix
@@ -217,10 +218,10 @@
//todo: something is wrong with this code, i'm sure... it only grows (and therefore moves if the buffer is to small)
//Check if the current buffer length is sufficient to have the string value prepended
if (prependedLength + len + 1 > bufferLength){
- //Have the size of the current string buffer increased because it is too small
+ //Have the size of the current string buffer increased because it is too small
//Because prependedLength is passed as the second argument to growBuffer,
//growBuffer will have left the first prependedLength characters empty
- //when it recopied buffer during reallocation.
+ //when it recopied buffer during reallocation.
growBuffer(prependedLength + len + 1, prependedLength);
}
@@ -239,7 +240,7 @@
return len;
}
TCHAR* StringBuffer::toString(){
- //Func - Returns a copy of the current string in the StringBuffer sized equal to the length of the string
+ //Func - Returns a copy of the current string in the StringBuffer sized equal to the length of the string
// in the StringBuffer.
//Pre - true
//Post - The copied string has been returned
@@ -252,14 +253,14 @@
//terminate the string
ret[len] = '\0';
}
- //return the the copy
+ //return the the copy
return ret;
}
TCHAR* StringBuffer::getBuffer() {
//Func - '\0' terminates the buffer and returns its pointer
//Pre - true
//Post - buffer has been '\0' terminated and returned
-
+
// Check if the current buffer is '\0' terminated
if (len == bufferLength){
//Make space for terminator, if necessary.
@@ -271,6 +272,15 @@
return buffer;
}
+ TCHAR* StringBuffer::giveBuffer() {
+ TCHAR* ret = getBuffer();
+ buffer = NULL;
+ len = 0;
+ bufferLength = 0;
+ bufferOwner = false;
+ return ret;
+ }
+
void StringBuffer::reserve(const size_t size){
if ( bufferLength >= size )
return;
@@ -280,7 +290,7 @@
TCHAR* tmp = _CL_NEWARRAY(TCHAR,bufferLength);
_tcsncpy(tmp, buffer, len);
tmp[len] = '\0';
-
+
//destroy the old buffer
if (buffer){
_CLDELETE_CARRAY(buffer);
@@ -316,7 +326,7 @@
assert(bufferLength>=minLength);
return;
}
-
+
bufferLength *= 2;
//Check that bufferLength is bigger than minLength
if (bufferLength < minLength){
@@ -331,7 +341,7 @@
//end of the old buffer), then apply the terminator to the new buffer.
_tcsncpy(tmp + skippingNInitialChars, buffer, len);
tmp[skippingNInitialChars + len] = '\0';
-
+
//destroy the old buffer
if (buffer){
_CLDELETE_CARRAY(buffer);
Modified: branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.h
===================================================================
--- branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.h 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.h 2009-09-27 08:58:03 UTC (rev 3021)
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
-*
-* Distributable under the terms of either the Apache License (Version 2.0) or
+*
+* 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_util_StringBuffer_
@@ -13,8 +13,8 @@
///Constructor. Allocates a buffer with the default length.
StringBuffer();
///Constructor. Allocates a buffer of length initSize + 1
- StringBuffer(const size_t initSize, const bool consumeBuffer = true);
- ///Constructor. Creates an instance of Stringbuffer containing a copy of
+ StringBuffer(const size_t initSize);
+ ///Constructor. Creates an instance of Stringbuffer containing a copy of
///the string value
StringBuffer(const TCHAR* value);
///Constructs a StringBuffer using another buffer. The StringBuffer can
@@ -24,10 +24,10 @@
virtual ~StringBuffer();
///Clears the Stringbuffer and resets it to it default empty state
void clear();
-
- ///Appends a single character
+
+ ///Appends a single character
void appendChar(const TCHAR chr);
- ///Appends a copy of the string value
+ ///Appends a copy of the string value
void append(const TCHAR* value);
///Appends a copy of the string value
void append(const TCHAR* value, size_t appendedLength);
@@ -41,19 +41,23 @@
void prepend(const TCHAR* value);
///Puts a copy of the string value in front of the current string in the StringBuffer
void prepend(const TCHAR* value, size_t prependedLength);
-
+
///Contains the length of string in the StringBuffer
///Public so that analyzers can edit the length directly
size_t len;
///Returns the length of the string in the StringBuffer
size_t length() const;
///Returns a copy of the current string in the StringBuffer
- TCHAR* toString();
+ TCHAR* toString();
///Returns a null terminated reference to the StringBuffer's text
- TCHAR* getBuffer();
+ TCHAR* getBuffer();
+ /** Returns a null terminated reference to the StringBuffer's text
+ * the StringBuffer's buffer is released so that the text doesn't need to be copied
+ */
+ TCHAR* giveBuffer();
- ///reserve a minimum amount of data for the buffer.
+ ///reserve a minimum amount of data for the buffer.
///no change made if the buffer is already longer than length
void reserve(const size_t length);
private:
@@ -62,7 +66,7 @@
///The length of the buffer
size_t bufferLength;
bool bufferOwner;
-
+
///Has the buffer grown to a minimum length of minLength or bigger
void growBuffer(const size_t minLength);
///Has the buffer grown to a minimum length of minLength or bigger and shifts the
Modified: branches/lucene2_3_2/src/test/index/TestIndexWriter.cpp
===================================================================
--- branches/lucene2_3_2/src/test/index/TestIndexWriter.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/test/index/TestIndexWriter.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -6,17 +6,15 @@
------------------------------------------------------------------------------*/
#include "test.h"
#include <iostream>
-#include <sys/stat.h>
-#include <sys/types.h>
//checks if a merged index finds phrases correctly
void testIWmergePhraseSegments(CuTest *tc){
char fsdir[CL_MAX_PATH];
sprintf(fsdir,"%s/%s",cl_tempDir, "test.indexwriter");
- mkdir(fsdir, 0777);
SimpleAnalyzer a;
+ Directory* dir = FSDirectory::getDirectory(fsdir, true);
- IndexWriter ndx2(fsdir,&a,true);
+ IndexWriter ndx2(dir,&a,true);
ndx2.setUseCompoundFile(false);
Document doc0;
doc0.add(
@@ -64,6 +62,7 @@
_CLDELETE(query1);
_CLDELETE(hits0);
_CLDELETE(hits1);
+ _CLDECDELETE(dir);
}
//checks that adding more than the min_merge value goes ok...
@@ -109,10 +108,10 @@
void testIWmergeSegments2(CuTest *tc){
char fsdir[CL_MAX_PATH];
sprintf(fsdir,"%s/%s",cl_tempDir, "test.indexwriter");
- mkdir(fsdir, 0777);
SimpleAnalyzer a;
+ Directory* dir = FSDirectory::getDirectory(fsdir, true);
- IndexWriter ndx2(fsdir,&a,true);
+ IndexWriter ndx2(dir,&a,true);
ndx2.setUseCompoundFile(false);
Document doc0;
doc0.add(
@@ -156,6 +155,7 @@
_CLDELETE(hits1);
_CLDECDELETE(term0);
_CLDECDELETE(term1);
+ _CLDECDELETE(dir);
}
void testAddIndexes(CuTest *tc){
Modified: branches/lucene2_3_2/src/test/search/TestSearch.cpp
===================================================================
--- branches/lucene2_3_2/src/test/search/TestSearch.cpp 2009-07-08 10:10:52 UTC (rev 3020)
+++ branches/lucene2_3_2/src/test/search/TestSearch.cpp 2009-09-27 08:58:03 UTC (rev 3021)
@@ -191,6 +191,7 @@
_TestSearchesRun(&a,s, _T("+term -term term") );
_TestSearchesRun(&a,s, _T("foo:term AND field:anotherTerm") );
_TestSearchesRun(&a,s, _T("term AND \"phrase phrase\"") );
+ _TestSearchesRun(&a,s, _T("search AND \"meaningful direction\"") );
_TestSearchesRun(&a,s, _T("\"hello there\"") );
_TestSearchesRun(&a,s, _T("a AND b") );
@@ -256,7 +257,10 @@
IndexReader* reader = IndexReader::open(ram);
IndexSearcher searcher(reader);
+
const TCHAR* queries[] = {
+ _T("a AND NOT b"),
+ _T("+a -b"),
_T("\"a b\""),
_T("\"a b c\""),
_T("a AND b"),
@@ -264,17 +268,20 @@
_T("\"a c\""),
_T("\"a c e\""),
};
- int shouldbe[] = {4,4,4,7,3,3};
+ int shouldbe[] = {3,3,4,4,4,7,3,3};
Hits* hits = NULL;
QueryParser parser(_T("contents"), &analyzer);
- for (int k = 0; k < 6; k++) {
+ for (int k = 0; k < 8; k++) {
Query* query = parser.parse(queries[k]);
+
+ //workaround bug in BooleanScorer2
+ if ( query->getObjectName() == BooleanQuery::getClassName() )
+ ((BooleanQuery*)query)->setUseScorer14(true);
TCHAR* qryInfo = query->toString(_T("contents"));
hits = searcher.search(query);
CLUCENE_ASSERT( hits->length() == shouldbe[k] );
-
_CLDELETE_CARRAY(qryInfo);
_CLDELETE(hits);
_CLDELETE(query);
@@ -322,7 +329,7 @@
}
void testSrchManyHits(CuTest *tc) {
- SimpleAnalyzer analyzer;
+ SimpleAnalyzer analyzer;
RAMDirectory ram;
IndexWriter writer( &ram, &analyzer, true);
@@ -366,7 +373,7 @@
CuSuite *testsearch(void)
{
CuSuite *suite = CuSuiteNew(_T("CLucene Search Test"));
- SUITE_ADD_TEST(suite, ramSearchTest);
+ SUITE_ADD_TEST(suite, ramSearchTest);
SUITE_ADD_TEST(suite, fsSearchTest);
SUITE_ADD_TEST(suite, testNormEncoding);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|