mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Always prefer case insensitive suggestions
This commit is contained in:
parent
48a2b46499
commit
adf4ad6ce3
@ -52,19 +52,10 @@ LineReader::Suggest::WordsRange LineReader::Suggest::getCompletions(const String
|
||||
last_word = std::string_view(prefix).substr(last_word_pos + 1, std::string::npos);
|
||||
|
||||
/// last_word can be empty.
|
||||
|
||||
if (case_insensitive)
|
||||
return std::equal_range(
|
||||
words.begin(), words.end(), last_word, [prefix_length](std::string_view s, std::string_view prefix_searched)
|
||||
{
|
||||
return strncasecmp(s.data(), prefix_searched.data(), prefix_length) < 0;
|
||||
});
|
||||
else
|
||||
return std::equal_range(
|
||||
words.begin(), words.end(), last_word, [prefix_length](std::string_view s, std::string_view prefix_searched)
|
||||
{
|
||||
return strncmp(s.data(), prefix_searched.data(), prefix_length) < 0;
|
||||
});
|
||||
return std::equal_range(words.begin(), words.end(), last_word, [prefix_length](std::string_view s, std::string_view prefix_searched)
|
||||
{
|
||||
return strncasecmp(s.data(), prefix_searched.data(), prefix_length) < 0;
|
||||
});
|
||||
}
|
||||
|
||||
LineReader::LineReader(const String & history_file_path_, char extender_, char delimiter_)
|
||||
|
@ -18,9 +18,6 @@ public:
|
||||
|
||||
/// Get iterators for the matched range of words if any.
|
||||
WordsRange getCompletions(const String & prefix, size_t prefix_length) const;
|
||||
|
||||
/// case sensitive suggestion
|
||||
bool case_insensitive = false;
|
||||
};
|
||||
|
||||
LineReader(const String & history_file_path, char extender, char delimiter = 0); /// if delimiter != 0, then it's multiline mode
|
||||
|
@ -481,8 +481,6 @@ private:
|
||||
|
||||
if (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false))
|
||||
{
|
||||
if (config().has("case_insensitive_suggestion"))
|
||||
Suggest::instance().setCaseInsensitive();
|
||||
/// Load suggestion data from the server.
|
||||
Suggest::instance().load(connection_parameters, config().getInt("suggestion_limit"));
|
||||
}
|
||||
@ -1720,7 +1718,6 @@ public:
|
||||
("always_load_suggestion_data", "Load suggestion data even if clickhouse-client is run in non-interactive mode. Used for testing.")
|
||||
("suggestion_limit", po::value<int>()->default_value(10000),
|
||||
"Suggestion limit for how many databases, tables and columns to fetch.")
|
||||
("case_insensitive_suggestion", "Case sensitive suggestions.")
|
||||
("multiline,m", "multiline")
|
||||
("multiquery,n", "multiquery")
|
||||
("format,f", po::value<std::string>(), "default output format")
|
||||
|
@ -50,16 +50,13 @@ void Suggest::load(const ConnectionParameters & connection_parameters, size_t su
|
||||
|
||||
/// Note that keyword suggestions are available even if we cannot load data from server.
|
||||
|
||||
if (case_insensitive)
|
||||
std::sort(words.begin(), words.end(), [](const std::string & str1, const std::string & str2)
|
||||
std::sort(words.begin(), words.end(), [](const std::string & str1, const std::string & str2)
|
||||
{
|
||||
return std::lexicographical_compare(begin(str1), end(str1), begin(str2), end(str2), [](const char char1, const char char2)
|
||||
{
|
||||
return std::lexicographical_compare(begin(str1), end(str1), begin(str2), end(str2), [](const char char1, const char char2)
|
||||
{
|
||||
return std::tolower(char1) < std::tolower(char2);
|
||||
});
|
||||
return std::tolower(char1) < std::tolower(char2);
|
||||
});
|
||||
else
|
||||
std::sort(words.begin(), words.end());
|
||||
});
|
||||
|
||||
ready = true;
|
||||
});
|
||||
|
@ -23,9 +23,6 @@ public:
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// Need to set before load
|
||||
void setCaseInsensitive() { case_insensitive = true; }
|
||||
|
||||
void load(const ConnectionParameters & connection_parameters, size_t suggestion_limit);
|
||||
|
||||
/// Older server versions cannot execute the query above.
|
||||
|
Loading…
Reference in New Issue
Block a user