Commit cba922a2 authored by Rachel Wong's avatar Rachel Wong Committed by Commit Bot

[search service] Add Mojo types and interfaces.

This CL adds the Mojo broker interface and associated structs for Local
Search Service.

The next CL will add StructTraits to allow for easy conversion between
the Mojo structs and their C++ counterparts.

Bug: 1092767
Change-Id: Ib4ca2dd1a61ccc775a36d4f99776bcdc62256b0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2235575Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Commit-Queue: Rachel Wong <wrong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777285}
parent 8302196d
...@@ -75,6 +75,7 @@ source_set("chromeos") { ...@@ -75,6 +75,7 @@ source_set("chromeos") {
"//chrome/browser/apps/platform_apps", "//chrome/browser/apps/platform_apps",
"//chrome/browser/apps/platform_apps/api", "//chrome/browser/apps/platform_apps/api",
"//chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_error_page", "//chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_error_page",
"//chrome/browser/chromeos/local_search_service:mojom",
"//chrome/browser/chromeos/net/network_health/public/mojom", "//chrome/browser/chromeos/net/network_health/public/mojom",
"//chrome/browser/chromeos/power/ml/smart_dim", "//chrome/browser/chromeos/power/ml/smart_dim",
"//chrome/browser/devtools", "//chrome/browser/devtools",
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") {
sources = [
"local_search_service.mojom",
"types.mojom",
]
public_deps = [ "//mojo/public/mojom/base" ]
}
...@@ -2,3 +2,6 @@ jiameng@chromium.org ...@@ -2,3 +2,6 @@ jiameng@chromium.org
tby@chromium.org tby@chromium.org
thanhdng@chromium.org thanhdng@chromium.org
wrong@chromium.org wrong@chromium.org
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
...@@ -15,7 +15,7 @@ namespace local_search_service { ...@@ -15,7 +15,7 @@ namespace local_search_service {
class Index; class Index;
enum class IndexId { kCrosSettings = 0 }; enum class IndexId { kInvalid = -1, kCrosSettings = 0 };
// LocalSearchService creates and owns content-specific Indices. Clients can // LocalSearchService creates and owns content-specific Indices. Clients can
// call it |GetIndex| method to get an Index for a given index id. // call it |GetIndex| method to get an Index for a given index id.
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module local_search_service.mojom;
import "chrome/browser/chromeos/local_search_service/types.mojom";
import "mojo/public/mojom/base/string16.mojom";
enum IndexId {
INVALID,
CROS_SETTINGS
// Add new client IDs here.
};
// LocalSearchServiceProxy creates and owns content-specific IndexProxies.
// Clients can call |GetIndex| to get an IndexProxy for a given index id.
interface LocalSearchServiceProxy {
// A client can call this function to get the Index for |index_id|. If the
// IndexProxy isn't created when this function is called, LocalSearchService
// will create one.
// Note, there should be one primary client that is the owner of the data and
// can read/write the data to the Index. The other clients should only use
// the Index for query search.
GetIndex(IndexId index_id, pending_receiver<IndexProxy> index);
};
// A proxy to a local search service Index.
// An Index has a registry of searchable data, which can be updated. It also
// runs a search function to find matching items for a given query.
// Each Index can serve multiple clients, but only one client (the primary
// client) that owns the data should be allowed to modify the Index.
interface IndexProxy {
// Returns number of data items.
GetSize() => (uint64 num_items);
// Adds or updates data and callbacks upon completion.
// Only the primary client should be allowed to do this operation.
AddOrUpdate(array<Data> data) => ();
// Deletes data with |ids| and returns the number of items deleted.
// 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.
Delete(array<string> ids) => (uint32 num_deleted);
// Takes an asynchronous search request call and returns results and status
// code via a callback. |results| will be null if there is an error.
Find(mojo_base.mojom.String16 query, uint32 max_results)
=> (ResponseStatus status, array<Result>? results);
};
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module local_search_service.mojom;
import "mojo/public/mojom/base/string16.mojom";
struct Content {
// An identifier for the content in Data.
string id;
mojo_base.mojom.String16 content;
};
struct Data {
// Identifier of the data item, should be unique across the registry. Clients
// will decide what ids to use, they could be paths, urls or any opaque
// string identifiers.
// Ideally IDs should persist across sessions, but this is not strictly
// required now because data is not persisted across sessions.
string id;
// Data item will be matched between its search tags and query term.
array<Content> contents;
};
struct SearchParams {
double relevance_threshold = 0.32;
double partial_match_penalty_rate = 0.9;
bool use_prefix_only = false;
bool use_edit_distance = false;
};
struct Position {
string content_id;
uint32 start;
uint32 length;
};
// Result is one item that matches a given query. It contains the id of the
// item and its matching score.
struct Result {
// Id of the data.
string id;
// Relevance score.
// Currently only linear map is implemented with fuzzy matching and score
// will always be in [0,1]. In the future, when an inverted index is
// implemented, the score will not be in this range any more. Client will be
// able to select a search backend to use (linear map vs inverted index) and
// hence client will be able to expect the range of the scores.
double score;
// Position of the matching text.
// We currently use linear map, which will return one matching content,
// hence the vector has only one element. When we have inverted index, we
// will have multiple matching contents.
array<Position> positions;
};
// Status of the search attempt.
// More will be added later.
enum ResponseStatus {
UNKNOWN_ERROR,
// Search operation is successful. But there could be no item and result list
// is empty.
SUCCESS,
// Query is empty.
EMPTY_QUERY,
// Index is empty (i.e. no data).
EMPTY_INDEX
};
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