Commit 23647a93 authored by Jia's avatar Jia Committed by Commit Bot

[cros search service] Change id from string16 to string.

Following discussions with our clients, we believe string type of id
will be sufficient. Search tags will continue to be string16 for
multi-language support.

Bug: 1018613
Change-Id: Id45aac55d61aaf2885a2a752ddf56cbcea15cda7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090552Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Commit-Queue: Jia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747558}
parent 039bfad2
...@@ -97,7 +97,7 @@ void IndexImpl::AddOrUpdate(std::vector<mojom::DataPtr> data, ...@@ -97,7 +97,7 @@ void IndexImpl::AddOrUpdate(std::vector<mojom::DataPtr> data,
std::move(callback).Run(); std::move(callback).Run();
} }
void IndexImpl::Delete(const std::vector<base::string16>& ids, void IndexImpl::Delete(const std::vector<std::string>& ids,
DeleteCallback callback) { DeleteCallback callback) {
uint32_t num_deleted = 0u; uint32_t num_deleted = 0u;
for (const auto& id : ids) { for (const auto& id : ids) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <string>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -40,7 +41,7 @@ class IndexImpl : public mojom::Index { ...@@ -40,7 +41,7 @@ class IndexImpl : public mojom::Index {
void AddOrUpdate(std::vector<mojom::DataPtr> data, void AddOrUpdate(std::vector<mojom::DataPtr> data,
AddOrUpdateCallback callback) override; AddOrUpdateCallback callback) override;
void Delete(const std::vector<base::string16>& ids, void Delete(const std::vector<std::string>& ids,
DeleteCallback callback) override; DeleteCallback callback) override;
void Find(const base::string16& query, void Find(const base::string16& query,
...@@ -63,7 +64,7 @@ class IndexImpl : public mojom::Index { ...@@ -63,7 +64,7 @@ class IndexImpl : public mojom::Index {
const base::string16& query) const; const base::string16& query) const;
// A map from key to tokenized search-tags. // A map from key to tokenized search-tags.
std::map<base::string16, std::vector<std::unique_ptr<TokenizedString>>> data_; std::map<std::string, std::vector<std::unique_ptr<TokenizedString>>> data_;
mojo::ReceiverSet<mojom::Index> receivers_; mojo::ReceiverSet<mojom::Index> receivers_;
......
...@@ -113,8 +113,7 @@ TEST_F(LocalSearchServiceImplTest, UpdateData) { ...@@ -113,8 +113,7 @@ TEST_F(LocalSearchServiceImplTest, UpdateData) {
// Add "id3" to the index. // Add "id3" to the index.
mojom::DataPtr data_id3 = mojom::Data::New( mojom::DataPtr data_id3 = mojom::Data::New(
base::UTF8ToUTF16("id3"), "id3", std::vector<base::string16>({base::UTF8ToUTF16("tag3a")}));
std::vector<base::string16>({base::UTF8ToUTF16("tag3a")}));
std::vector<mojom::DataPtr> data_to_update; std::vector<mojom::DataPtr> data_to_update;
data_to_update.push_back(std::move(data_id3)); data_to_update.push_back(std::move(data_id3));
AddOrUpdateAndCheck(index_remote.get(), std::move(data_to_update)); AddOrUpdateAndCheck(index_remote.get(), std::move(data_to_update));
......
...@@ -39,7 +39,7 @@ interface Index { ...@@ -39,7 +39,7 @@ interface Index {
// Deletes data with |ids| and returns number of items deleted. // Deletes data with |ids| and returns number of items deleted.
// If an id doesn't exist in the Index, no operation will be done. // If an id doesn't exist in the Index, no operation will be done.
// Only the primary client should be allowed to do this operation. // Only the primary client should be allowed to do this operation.
Delete(array<mojo_base.mojom.String16> ids) => (uint32 num_deleted); Delete(array<string> ids) => (uint32 num_deleted);
// Takes an asynchronous search request call and returns results and status // Takes an asynchronous search request call and returns results and status
// code via a callback. // code via a callback.
......
...@@ -21,7 +21,7 @@ struct Data { ...@@ -21,7 +21,7 @@ struct Data {
// identifiers. // identifiers.
// Ideally IDs should persist across sessions, but this is not strictly // Ideally IDs should persist across sessions, but this is not strictly
// required now because data is not persisted across sessions. // required now because data is not persisted across sessions.
mojo_base.mojom.String16 id; string id;
// Data item will be matched between its search tags and query term. // Data item will be matched between its search tags and query term.
array<mojo_base.mojom.String16> search_tags; array<mojo_base.mojom.String16> search_tags;
...@@ -31,7 +31,7 @@ struct Data { ...@@ -31,7 +31,7 @@ struct Data {
// and its matching score. // and its matching score.
struct Result { struct Result {
// Id of the data. // Id of the data.
mojo_base.mojom.String16 id; string id;
// Relevance score, in the range of [0,1]. // Relevance score, in the range of [0,1].
double score; double score;
// Matching ranges. // Matching ranges.
......
...@@ -29,7 +29,7 @@ std::vector<mojom::DataPtr> CreateTestData( ...@@ -29,7 +29,7 @@ std::vector<mojom::DataPtr> CreateTestData(
std::vector<mojom::DataPtr> output; std::vector<mojom::DataPtr> output;
for (const auto& item : input) { for (const auto& item : input) {
const std::vector<base::string16> tags = MultiUTF8ToUTF16(item.second); const std::vector<base::string16> tags = MultiUTF8ToUTF16(item.second);
mojom::DataPtr data = mojom::Data::New(base::UTF8ToUTF16(item.first), tags); mojom::DataPtr data = mojom::Data::New(item.first, tags);
output.push_back(std::move(data)); output.push_back(std::move(data));
} }
return output; return output;
...@@ -53,7 +53,7 @@ void DeleteAndCheck(mojom::Index* index, ...@@ -53,7 +53,7 @@ void DeleteAndCheck(mojom::Index* index,
uint32_t expected_num_deleted) { uint32_t expected_num_deleted) {
DCHECK(index); DCHECK(index);
uint32_t num_deleted = 0u; uint32_t num_deleted = 0u;
mojom::IndexAsyncWaiter(index).Delete(MultiUTF8ToUTF16(ids), &num_deleted); mojom::IndexAsyncWaiter(index).Delete(ids, &num_deleted);
EXPECT_EQ(num_deleted, expected_num_deleted); EXPECT_EQ(num_deleted, expected_num_deleted);
} }
...@@ -77,7 +77,7 @@ void FindAndCheck(mojom::Index* index, ...@@ -77,7 +77,7 @@ void FindAndCheck(mojom::Index* index,
// If results are returned, check size and values match the expected. // If results are returned, check size and values match the expected.
EXPECT_EQ(results->size(), expected_result_ids.size()); EXPECT_EQ(results->size(), expected_result_ids.size());
for (size_t i = 0; i < results->size(); ++i) { for (size_t i = 0; i < results->size(); ++i) {
EXPECT_EQ((*results)[i]->id, base::UTF8ToUTF16(expected_result_ids[i])); EXPECT_EQ((*results)[i]->id, expected_result_ids[i]);
// Scores should be non-increasing. // Scores should be non-increasing.
if (i < results->size() - 1) { if (i < results->size() - 1) {
EXPECT_GE((*results)[i]->score, (*results)[i + 1]->score); EXPECT_GE((*results)[i]->score, (*results)[i + 1]->score);
......
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