Commit 9b15a507 authored by Jia's avatar Jia Committed by Commit Bot

[cros search service] Add case-insensitive exact match to TokenizedStringMatch

We're consolidating exact & fuzzy string match to be both supported by
the search service. In this cl, we add case-insensitive exact match to
TokenizedStringMatch and remove it from app_search_provider. Note, fuzzy
string match already performs case-insensitive exact match internally.

Bug: 1018613
Change-Id: Ia7d17352e3b263ab09fac1e590748a08d7b16eb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089534Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748068}
parent 257a9cc7
...@@ -551,7 +551,6 @@ void AppSearchProvider::UpdateQueriedResults() { ...@@ -551,7 +551,6 @@ void AppSearchProvider::UpdateQueriedResults() {
// Exact matches should be shown even if the threshold isn't reached, // Exact matches should be shown even if the threshold isn't reached,
// e.g. due to a localized name being particularly short. // e.g. due to a localized name being particularly short.
if (match.relevance() <= app->relevance_threshold() && if (match.relevance() <= app->relevance_threshold() &&
!base::EqualsCaseInsensitiveASCII(query_, app->name()) &&
!app->MatchSearchableText(query_terms, use_exact_match)) { !app->MatchSearchableText(query_terms, use_exact_match)) {
continue; continue;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/i18n/string_search.h" #include "base/i18n/string_search.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_util.h"
#include "chrome/common/string_matching/tokenized_string_char_iterator.h" #include "chrome/common/string_matching/tokenized_string_char_iterator.h"
namespace { namespace {
...@@ -195,6 +196,19 @@ bool TokenizedStringMatch::Calculate(const TokenizedString& query, ...@@ -195,6 +196,19 @@ bool TokenizedStringMatch::Calculate(const TokenizedString& query,
relevance_ = kNoMatchScore; relevance_ = kNoMatchScore;
hits_.clear(); hits_.clear();
// If there is an exact match, relevance will be 1.0 and there is only 1 hit
// that is the entire text/query.
const auto& query_text = query.text();
const auto& text_text = text.text();
const auto query_size = query_text.size();
const auto text_size = text_text.size();
if (query_size > 0 && query_size == text_size &&
base::EqualsCaseInsensitiveASCII(query_text, text_text)) {
hits_.push_back(gfx::Range(0, query_size));
relevance_ = 1.0;
return true;
}
PrefixMatcher matcher(query, text); PrefixMatcher matcher(query, text);
if (matcher.Match()) { if (matcher.Match()) {
relevance_ = matcher.relevance(); relevance_ = matcher.relevance();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment