diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java index 1af387dadf4bc..5fd45eadbda97 100644 --- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java +++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java @@ -140,6 +140,25 @@ public class AppSearchManager { AppSearchSession.createSearchSession(searchContext, mService, executor, callback); } + /** + * Creates a new {@link GlobalSearchSession}. + * + *
This process requires an AppSearch native indexing file system for each user. If it's not
+ * created for this user, the initialization process will create one under user's directory.
+ *
+ * @param executor Executor on which to invoke the callback.
+ * @param callback The {@link AppSearchResult}<{@link GlobalSearchSession}> of
+ * performing this operation. Or a {@link AppSearchResult} with failure
+ * reason code and error information.
+ */
+ public void createGlobalSearchSession(
+ @NonNull @CallbackExecutor Executor executor,
+ @NonNull Consumer Apps can retrieve indexed documents through the query API.
+ * @hide
+ */
+public class GlobalSearchSession {
+
+ private final IAppSearchManager mService;
+
+ static void createGlobalSearchSession(
+ @NonNull IAppSearchManager service,
+ @NonNull @CallbackExecutor Executor executor,
+ @NonNull Consumer Currently we support following features in the raw query format:
+ * AND joins (e.g. “match documents that have both the terms ‘dog’ and
+ * ‘cat’”).
+ * Example: hello world matches documents that have both ‘hello’ and ‘world’
+ * OR joins (e.g. “match documents that have either the term ‘dog’ or
+ * ‘cat’”).
+ * Example: dog OR puppy
+ * Exclude a term (e.g. “match documents that do
+ * not have the term ‘dog’”).
+ * Example: -dog excludes the term ‘dog’
+ * Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
+ * “match documents that have either ‘dog’ or ‘puppy’, and either ‘cat’ or ‘kitten’”).
+ * Example: (dog puppy) (cat kitten) two one group containing two terms.
+ * Specifies which properties of a document to specifically match terms in (e.g.
+ * “match documents where the ‘subject’ property contains ‘important’”).
+ * Example: subject:important matches documents with the term ‘important’ in the
+ * ‘subject’ property
+ * This is similar to property restricts, but allows for restricts on top-level document
+ * fields, such as schema_type. Clients should be able to limit their query to documents of
+ * a certain schema_type (e.g. “match documents that are of the ‘Email’ schema_type”).
+ * Example: { schema_type_filters: “Email”, “Video”,query: “dog” } will match documents
+ * that contain the query term ‘dog’ and are of either the ‘Email’ schema type or the
+ * ‘Video’ schema type.
+ * This method is lightweight. The heavy work will be done in
+ * {@link SearchResults#getNextPage}.
+ *
+ * @param queryExpression Query String to search.
+ * @param searchSpec Spec for setting filters, raw query etc.
+ * @param executor Executor on which to invoke the callback of the following request
+ * {@link SearchResults#getNextPage}.
+ * @return The search result of performing this operation.
+ */
+ @NonNull
+ public SearchResults globalQuery(
+ @NonNull String queryExpression,
+ @NonNull SearchSpec searchSpec,
+ @NonNull @CallbackExecutor Executor executor) {
+ Objects.requireNonNull(queryExpression);
+ Objects.requireNonNull(searchSpec);
+ Objects.requireNonNull(executor);
+ return new SearchResults(mService, /*databaseName=*/null, queryExpression,
+ searchSpec, executor);
+ }
+}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl b/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
index e09abe540fe06..22e00f2cdfdc3 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
+++ b/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
@@ -94,6 +94,20 @@ interface IAppSearchManager {
in Bundle searchSpecBundle,
in IAppSearchResultCallback callback);
+ /**
+ * Executes a global query, i.e. over all permitted databases, against the AppSearch index and
+ * returns results.
+ *
+ * @param queryExpression String to search for
+ * @param searchSpecBundle SearchSpec bundle
+ * @param callback {@link AppSearchResult}<{@link Bundle}> of performing this
+ * operation.
+ */
+ void globalQuery(
+ in String queryExpression,
+ in Bundle searchSpecBundle,
+ in IAppSearchResultCallback callback);
+
/**
* Fetches the next page of results of a previously executed query. Results can be empty if
* next-page token is invalid or all pages have been returned.
diff --git a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
index aec69bb492ddf..8548d209c7871 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
@@ -85,23 +85,18 @@ public class SearchResults implements Closeable {
try {
if (mIsFirstLoad) {
mIsFirstLoad = false;
- //TODO(b/162450968) add support for global query.
- mService.query(mDatabaseName, mQueryExpression, mSearchSpec.getBundle(),
- new IAppSearchResultCallback.Stub() {
- public void onResult(AppSearchResult result) {
- mExecutor.execute(() -> invokeCallback(result, callback));
- }
- });
+ if (mDatabaseName == null) {
+ mService.globalQuery(mQueryExpression, mSearchSpec.getBundle(),
+ wrapCallback(callback));
+ } else {
+ mService.query(mDatabaseName, mQueryExpression, mSearchSpec.getBundle(),
+ wrapCallback(callback));
+ }
} else {
- mService.getNextPage(mNextPageToken,
- new IAppSearchResultCallback.Stub() {
- public void onResult(AppSearchResult result) {
- mExecutor.execute(() -> invokeCallback(result, callback));
- }
- });
+ mService.getNextPage(mNextPageToken, wrapCallback(callback));
}
} catch (RemoteException e) {
- e.rethrowFromSystemServer();
+ throw e.rethrowFromSystemServer();
}
}
@@ -131,4 +126,13 @@ public class SearchResults implements Closeable {
}
});
}
+
+ private IAppSearchResultCallback wrapCallback(
+ @NonNull Consumer
+ *
+ *
+ *