1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.appsearch.appsindexer; 17 18 import android.annotation.NonNull; 19 import android.app.appsearch.AppSearchBatchResult; 20 import android.app.appsearch.AppSearchSchema; 21 import android.app.appsearch.AppSearchSession; 22 import android.app.appsearch.PutDocumentsRequest; 23 import android.app.appsearch.SearchResults; 24 import android.app.appsearch.SearchSpec; 25 import android.app.appsearch.SetSchemaRequest; 26 import android.app.appsearch.SetSchemaResponse; 27 import android.app.appsearch.exceptions.AppSearchException; 28 29 import java.io.Closeable; 30 31 /** 32 * A synchronous wrapper around {@link AppSearchSession}. This allows us to perform operations in 33 * AppSearch without needing to handle async calls. 34 * 35 * @see AppSearchSession 36 */ 37 public interface SyncAppSearchSession extends Closeable { 38 /** 39 * Synchronously sets an {@link AppSearchSchema}. 40 * 41 * @see AppSearchSession#setSchema 42 */ 43 @NonNull setSchema(@onNull SetSchemaRequest setSchemaRequest)44 SetSchemaResponse setSchema(@NonNull SetSchemaRequest setSchemaRequest) 45 throws AppSearchException; 46 47 /** 48 * Synchronously inserts documents into AppSearch. 49 * 50 * @see AppSearchSession#put 51 */ 52 @NonNull put(@onNull PutDocumentsRequest request)53 AppSearchBatchResult<String, Void> put(@NonNull PutDocumentsRequest request) 54 throws AppSearchException; 55 56 /** 57 * Returns a synchronous version of {@link SearchResults}. 58 * 59 * <p>While the underlying method is not asynchronous, this method allows for convenience while 60 * synchronously searching AppSearch. 61 * 62 * @see AppSearchSession#search 63 */ 64 @NonNull search(@onNull String query, @NonNull SearchSpec searchSpec)65 SyncSearchResults search(@NonNull String query, @NonNull SearchSpec searchSpec); 66 67 /** 68 * Closes the session. 69 * 70 * @see AppSearchSession#close 71 */ 72 @Override close()73 void close(); 74 75 // TODO(b/275592563): Bring in additional methods such as getByDocumentId as needed 76 } 77