-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
get_keys
function in fts (#4647)
* Implement get-keys function --------- Co-authored-by: CI Bot <[email protected]>
- Loading branch information
1 parent
109012e
commit c46eec1
Showing
8 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "function/get_keys.h" | ||
|
||
#include "common/exception/binder.h" | ||
#include "common/string_utils.h" | ||
#include "function/scalar_function.h" | ||
#include "function/stem.h" | ||
#include "function/string/functions/lower_function.h" | ||
#include "libstemmer.h" | ||
#include "re2.h" | ||
|
||
namespace kuzu { | ||
namespace fts_extension { | ||
|
||
using namespace function; | ||
using namespace common; | ||
|
||
struct GetKeys { | ||
static void operation(common::ku_string_t& word, common::ku_string_t& stemmer, | ||
common::list_entry_t& result, common::ValueVector& resultVector); | ||
}; | ||
|
||
void GetKeys::operation(common::ku_string_t& query, common::ku_string_t& stemmer, | ||
common::list_entry_t& result, common::ValueVector& resultVector) { | ||
std::string regexPattern = "[0-9!@#$%^&*()_+={}\\[\\]:;<>,.?~\\/\\|'\"`-]+"; | ||
std::string replacePattern = " "; | ||
std::string resultStr = query.getAsString(); | ||
RE2::GlobalReplace(&resultStr, regexPattern, replacePattern); | ||
StringUtils::toLower(resultStr); | ||
auto words = StringUtils::split(resultStr, " "); | ||
StemFunction::validateStemmer(stemmer.getAsString()); | ||
auto sbStemmer = sb_stemmer_new(reinterpret_cast<const char*>(stemmer.getData()), "UTF_8"); | ||
result = ListVector::addList(&resultVector, words.size()); | ||
for (auto i = 0u; i < result.size; i++) { | ||
auto& word = words[i]; | ||
auto stemData = sb_stemmer_stem(sbStemmer, reinterpret_cast<const sb_symbol*>(word.c_str()), | ||
word.length()); | ||
ListVector::getDataVector(&resultVector) | ||
->setValue(result.offset + i, | ||
std::string_view{reinterpret_cast<const char*>(stemData)}); | ||
} | ||
sb_stemmer_delete(sbStemmer); | ||
} | ||
|
||
static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) { | ||
return FunctionBindData::getSimpleBindData(input.arguments, | ||
LogicalType::LIST(LogicalType::STRING())); | ||
} | ||
|
||
function::function_set GetKeysFunction::getFunctionSet() { | ||
function_set result; | ||
result.push_back(std::make_unique<ScalarFunction>(name, | ||
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING}, | ||
LogicalTypeID::LIST, | ||
ScalarFunction::BinaryStringExecFunction<ku_string_t, ku_string_t, list_entry_t, GetKeys>, | ||
bindFunc)); | ||
return result; | ||
} | ||
|
||
} // namespace fts_extension | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "function/function.h" | ||
|
||
namespace kuzu { | ||
namespace fts_extension { | ||
|
||
struct GetKeysFunction { | ||
static constexpr const char* name = "GET_KEYS"; | ||
|
||
static function::function_set getFunctionSet(); | ||
}; | ||
|
||
} // namespace fts_extension | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-DATASET CSV empty | ||
|
||
-- | ||
|
||
-CASE get_keys_function | ||
-STATEMENT load extension "${KUZU_ROOT_DIRECTORY}/extension/fts/build/libfts.kuzu_extension" | ||
---- ok | ||
-STATEMENT RETURN get_keys('alice bob carol', 'english') | ||
---- 1 | ||
[alic,bob,carol] | ||
-STATEMENT RETURN get_keys('alice bo\'b dan', 'english') | ||
---- 1 | ||
[alic,bo,b,dan] | ||
-STATEMENT RETURN get_keys('Uwaterloo ut', 'english') | ||
---- 1 | ||
[uwaterloo,ut] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters