This is an automated email from the ASF dual-hosted git repository.
jianliangqi pushed a commit to branch clucene
in repository https://gitbox.apache.org/repos/asf/doris-thirdparty.git
The following commit(s) were added to refs/heads/clucene by this push:
new 6f8a21ff [feature](multi phrase) Add the MultiPhraseQuery interface
(#138)
6f8a21ff is described below
commit 6f8a21ffe15bd78a1cd3e685067ee5c9ed071827
Author: zzzxl <[email protected]>
AuthorDate: Wed Nov 22 15:07:40 2023 +0800
[feature](multi phrase) Add the MultiPhraseQuery interface (#138)
---
src/core/CLucene/search/MultiPhraseQuery.cpp | 27 +++++++++++++++++++++++++++
src/core/CLucene/search/MultiPhraseQuery.h | 4 ++++
2 files changed, 31 insertions(+)
diff --git a/src/core/CLucene/search/MultiPhraseQuery.cpp
b/src/core/CLucene/search/MultiPhraseQuery.cpp
index 56fdf61b..54273702 100644
--- a/src/core/CLucene/search/MultiPhraseQuery.cpp
+++ b/src/core/CLucene/search/MultiPhraseQuery.cpp
@@ -305,6 +305,14 @@ void MultiPhraseQuery::add(const
CL_NS(util)::ArrayBase<CL_NS(index)::Term*>* te
add(terms, position);
}
+void MultiPhraseQuery::add(std::vector<CL_NS(index)::Term*>& terms) {
+ int32_t position = 0;
+ if (positions->size() > 0)
+ position = (*positions)[positions->size()-1] + 1;
+
+ add(terms, position);
+}
+
void MultiPhraseQuery::add(const CL_NS(util)::ArrayBase<CL_NS(index)::Term*>*
_terms, const int32_t position) {
if (termArrays->size() == 0)
field = STRDUP_TtoT((*_terms)[0]->field());
@@ -321,6 +329,25 @@ void MultiPhraseQuery::add(const
CL_NS(util)::ArrayBase<CL_NS(index)::Term*>* _t
termArrays->push_back(terms);
positions->push_back(position);
}
+
+void MultiPhraseQuery::add(std::vector<CL_NS(index)::Term*>& _terms, const
int32_t position) {
+ if (termArrays->size() == 0)
+ field = STRDUP_TtoT((_terms)[0]->field());
+
+ CL_NS(util)::ArrayBase<CL_NS(index)::Term*>* terms = _CLNEW
CL_NS(util)::ValueArray<CL_NS(index)::Term*>(_terms.size());
+ for ( size_t i=0;i<_terms.size();i++ ){
+ if ( _tcscmp(_terms[i]->field(), field) != 0) {
+ TCHAR buf[250];
+ _sntprintf(buf,250,_T("All phrase terms must be in the
same field (%s): %s"),field, (*terms)[i]->field());
+ _CLTHROWT(CL_ERR_IllegalArgument,buf);
+ }
+ terms->values[i] = _CL_POINTER(_terms[i]);
+ }
+
+ termArrays->push_back(terms);
+ positions->push_back(position);
+}
+
const CL_NS(util)::CLArrayList<CL_NS(util)::ArrayBase<CL_NS(index)::Term*>*>*
MultiPhraseQuery::getTermArrays() {
return termArrays;
}
diff --git a/src/core/CLucene/search/MultiPhraseQuery.h
b/src/core/CLucene/search/MultiPhraseQuery.h
index 86419e5b..68d9f76f 100644
--- a/src/core/CLucene/search/MultiPhraseQuery.h
+++ b/src/core/CLucene/search/MultiPhraseQuery.h
@@ -11,6 +11,8 @@
#include "CLucene/util/Array.h"
#include "CLucene/util/VoidList.h"
+#include <vector>
+
CL_CLASS_DEF(index,Term)
CL_NS_DEF(search)
@@ -66,6 +68,7 @@ public:
* @see PhraseQuery#add(Term)
*/
void add(const CL_NS(util)::ArrayBase<CL_NS(index)::Term*>* terms);
+ void add(std::vector<CL_NS(index)::Term*>& terms);
/**
* Allows to specify the relative position of terms within the phrase.
@@ -76,6 +79,7 @@ public:
* @memory A pointer is taken of each term, the array memory must be cleaned
up by calle
*/
void add(const CL_NS(util)::ArrayBase<CL_NS(index)::Term*>* terms, const
int32_t position);
+ void add(std::vector<CL_NS(index)::Term*>& terms, const int32_t
position);
/**
* Returns a ArrayBase<Term[]> of the terms in the multiphrase.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]