mirror of https://gitee.com/bigwinds/arangodb
Fixing warnings and errors
This commit is contained in:
parent
635a3e9423
commit
152a3b6d8d
|
@ -136,7 +136,12 @@ AqlValue RocksDBAqlFunctions::Fulltext(
|
|||
trx->pinData(cid);
|
||||
try {
|
||||
transaction::BuilderLeaser builder(trx);
|
||||
Result res = fulltextIndex->executeQuery(queryString, *(builder.get()));
|
||||
FulltextQuery query;
|
||||
Result res = fulltextIndex->parseQueryString(queryString, query);
|
||||
if (!res.ok()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(res.errorNumber(), res.errorMessage());
|
||||
}
|
||||
res = fulltextIndex->executeQuery(query, maxResults, *(builder.get()));
|
||||
if (!res.ok()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(res.errorNumber(), res.errorMessage());
|
||||
}
|
||||
|
@ -144,51 +149,6 @@ AqlValue RocksDBAqlFunctions::Fulltext(
|
|||
} catch (...) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
/*TRI_fulltext_query_t* ft =
|
||||
TRI_CreateQueryMMFilesFulltextIndex(TRI_FULLTEXT_SEARCH_MAX_WORDS, maxResults);
|
||||
|
||||
if (ft == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
bool isSubstringQuery = false;
|
||||
int res =
|
||||
TRI_ParseQueryMMFilesFulltextIndex(ft, queryString.c_str(), &isSubstringQuery);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
TRI_FreeQueryMMFilesFulltextIndex(ft);
|
||||
THROW_ARANGO_EXCEPTION(res);
|
||||
}
|
||||
|
||||
// note: the following call will free "ft"!
|
||||
TRI_fulltext_result_t* queryResult =
|
||||
TRI_QueryMMFilesFulltextIndex(fulltextIndex->internals(), ft);
|
||||
|
||||
if (queryResult == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
TRI_ASSERT(trx->isPinned(cid));
|
||||
|
||||
transaction::BuilderLeaser builder(trx);
|
||||
try {
|
||||
builder->openArray();
|
||||
|
||||
ManagedDocumentResult mmdr;
|
||||
size_t const numResults = queryResult->_numDocuments;
|
||||
for (size_t i = 0; i < numResults; ++i) {
|
||||
if (collection->readDocument(trx, queryResult->_documents[i], mmdr)) {
|
||||
mmdr.addToBuilder(*builder.get(), true);
|
||||
}
|
||||
}
|
||||
builder->close();
|
||||
TRI_FreeResultRocksDBFulltextIndex(queryResult);
|
||||
return AqlValue(builder.get());
|
||||
} catch (...) {
|
||||
TRI_FreeResultRocksDBFulltextIndex(queryResult);
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}*/
|
||||
}
|
||||
|
||||
/// @brief function NEAR
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "Basics/StringRef.h"
|
||||
#include "Basics/Utf8Helper.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Logger/Logger.h"
|
||||
#include "RocksDBEngine/RocksDBCommon.h"
|
||||
#include "RocksDBEngine/RocksDBToken.h"
|
||||
|
@ -358,7 +359,114 @@ std::vector<std::string> RocksDBFulltextIndex::wordlist(VPackSlice const& doc) {
|
|||
return words;
|
||||
}
|
||||
|
||||
arangodb::Result RocksDBFulltextIndex::executeQuery(std::string const& queryString,
|
||||
VPackBuilder &builder) {
|
||||
arangodb::Result RocksDBFulltextIndex::parseQueryString(std::string const& qstr,
|
||||
FulltextQuery& query) {
|
||||
if (qstr.empty()) {
|
||||
return Result(TRI_ERROR_BAD_PARAMETER);
|
||||
}
|
||||
|
||||
const char* ptr = qstr.data();
|
||||
int i = 0;
|
||||
|
||||
while (*ptr) {
|
||||
|
||||
char c = *ptr;
|
||||
// ignore whitespace
|
||||
if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' ||
|
||||
c == '\b' || c == ',') {
|
||||
++ptr;
|
||||
continue;
|
||||
}
|
||||
|
||||
// defaults
|
||||
FulltextQueryToken::Operation operation = FulltextQueryToken::AND;
|
||||
FulltextQueryToken::MatchType matchType = FulltextQueryToken::COMPLETE;
|
||||
|
||||
// word begin
|
||||
// get operation
|
||||
if (c == '+') {
|
||||
operation = FulltextQueryToken::AND;
|
||||
} else if (c == '|') {
|
||||
operation = FulltextQueryToken::OR;
|
||||
} if (c == '-') {
|
||||
operation = FulltextQueryToken::EXCLUDE;
|
||||
}
|
||||
++ptr;
|
||||
|
||||
// find a word with ':' at the end, i.e. prefix: or complete:
|
||||
char const* split = nullptr;
|
||||
char const* start = ptr;
|
||||
while (*ptr) {
|
||||
c = *ptr;
|
||||
if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' ||
|
||||
c == '\b' || c == ',') {
|
||||
// end of word
|
||||
break;
|
||||
} else if (split == nullptr && c == ':') {
|
||||
split = ptr + 1;
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
char const* end = ptr;
|
||||
|
||||
if ((end - start == 0) || (split != nullptr && split - start == 0) ||
|
||||
(split != nullptr && end - split == 0)) {
|
||||
// invalid string
|
||||
return Result(TRI_ERROR_BAD_PARAMETER);
|
||||
}
|
||||
|
||||
// get command
|
||||
if (split != nullptr) {
|
||||
if (TRI_CaseEqualString(start, "prefix:", strlen("prefix:"))) {
|
||||
matchType = FulltextQueryToken::PREFIX;
|
||||
} else if (TRI_CaseEqualString(start, "complete:", strlen("complete:"))) {
|
||||
matchType = FulltextQueryToken::COMPLETE;
|
||||
}
|
||||
start = split;
|
||||
}
|
||||
|
||||
|
||||
// normalize a word for a fulltext search query this will create a copy of the word
|
||||
char const* word = start;
|
||||
size_t wordLength = (size_t)(end - start);
|
||||
|
||||
TRI_ASSERT(end >= start);
|
||||
size_t outLength;
|
||||
char* normalized = TRI_normalize_utf8_to_NFC(TRI_UNKNOWN_MEM_ZONE, word, wordLength,
|
||||
&outLength);
|
||||
if (normalized == nullptr) {
|
||||
return Result(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// lower case string
|
||||
int32_t outLength2;
|
||||
char* lowered = TRI_tolower_utf8(TRI_UNKNOWN_MEM_ZONE, normalized,
|
||||
(int32_t)outLength, &outLength2);
|
||||
TRI_Free(TRI_UNKNOWN_MEM_ZONE, normalized);
|
||||
|
||||
if (lowered == nullptr) {
|
||||
return Result(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// calculate the proper prefix
|
||||
char* prefixEnd = TRI_PrefixUtf8String(lowered, TRI_FULLTEXT_MAX_WORD_LENGTH);
|
||||
ptrdiff_t prefixLength = prefixEnd - lowered;
|
||||
|
||||
std::string value;
|
||||
value.append(lowered, (size_t)prefixLength);
|
||||
query.push_back(FulltextQueryToken(value, matchType, operation));
|
||||
|
||||
++i;
|
||||
if (i >= TRI_FULLTEXT_SEARCH_MAX_WORDS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Result(i == 0 ? TRI_ERROR_BAD_PARAMETER : TRI_ERROR_NO_ERROR);
|
||||
}
|
||||
|
||||
arangodb::Result RocksDBFulltextIndex::executeQuery(FulltextQuery const& query,
|
||||
size_t maxResults,
|
||||
VPackBuilder &builder) {
|
||||
return Result();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,9 @@
|
|||
/// @brief default minimum word length for a fulltext index
|
||||
#define TRI_FULLTEXT_MIN_WORD_LENGTH_DEFAULT 2
|
||||
|
||||
/// @brief maximum number of search words in a query
|
||||
#define TRI_FULLTEXT_SEARCH_MAX_WORDS 32
|
||||
|
||||
namespace arangodb {
|
||||
struct DocumentIdentifierToken;
|
||||
|
||||
|
@ -50,6 +53,9 @@ struct FulltextQueryToken {
|
|||
/// @brief fulltext query logical operators
|
||||
enum Operation {AND, OR, EXCLUDE};
|
||||
|
||||
FulltextQueryToken(std::string const& v, MatchType t, Operation o)
|
||||
: value(v), matchType(t), operation(o) {}
|
||||
|
||||
std::string value;
|
||||
MatchType matchType;
|
||||
Operation operation;
|
||||
|
@ -121,7 +127,9 @@ class RocksDBFulltextIndex final : public RocksDBIndex {
|
|||
static DocumentIdentifierToken toDocumentIdentifierToken(
|
||||
TRI_voc_rid_t revisionId);
|
||||
|
||||
arangodb::Result executeQuery(std::string const& queryString,
|
||||
|
||||
arangodb::Result parseQueryString(std::string const&, FulltextQuery&);
|
||||
arangodb::Result executeQuery(FulltextQuery const&, size_t maxResults,
|
||||
velocypack::Builder &builder);
|
||||
|
||||
private:
|
||||
|
|
|
@ -89,6 +89,13 @@ static rocksdb::Slice ReplicationApplierConfig(
|
|||
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
|
||||
&replicationApplierConfig),
|
||||
1);
|
||||
|
||||
static RocksDBEntryType fulltextIndexValue =
|
||||
RocksDBEntryType::FulltextIndexValue;
|
||||
static rocksdb::Slice FulltextIndexValue(
|
||||
reinterpret_cast<std::underlying_type<RocksDBEntryType>::type*>(
|
||||
&fulltextIndexValue),
|
||||
1);
|
||||
}
|
||||
|
||||
rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
|
||||
|
@ -115,6 +122,8 @@ rocksdb::Slice const& arangodb::rocksDBSlice(RocksDBEntryType const& type) {
|
|||
return SettingsValue;
|
||||
case RocksDBEntryType::ReplicationApplierConfig:
|
||||
return ReplicationApplierConfig;
|
||||
case RocksDBEntryType::FulltextIndexValue:
|
||||
return FulltextIndexValue;
|
||||
}
|
||||
|
||||
return Document; // avoids warning - errorslice instead ?!
|
||||
|
|
Loading…
Reference in New Issue