다음을 통해 공유


AppSearchManager Class

Definition

Provides access to the centralized AppSearch index maintained by the system.

[Android.Runtime.Register("android/app/appsearch/AppSearchManager", ApiSince=31, DoNotGenerateAcw=true)]
public class AppSearchManager : Java.Lang.Object
[<Android.Runtime.Register("android/app/appsearch/AppSearchManager", ApiSince=31, DoNotGenerateAcw=true)>]
type AppSearchManager = class
    inherit Object
Inheritance
AppSearchManager
Attributes

Remarks

Provides access to the centralized AppSearch index maintained by the system.

AppSearch is an offline, on-device search library for managing structured data featuring:

<ul> <li>APIs to index and retrieve data via full-text search. <li>An API for applications to explicitly grant read-access permission of their data to other applications. <b>See: SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage</b> <li>An API for applications to opt into or out of having their data displayed on System UI surfaces by the System-designated global querier. <b>See: SetSchemaRequest.Builder#setSchemaTypeDisplayedBySystem</b> </ul>

Applications create a database by opening an AppSearchSession.

Example:

AppSearchManager appSearchManager = context.getSystemService(AppSearchManager.class);

            AppSearchManager.SearchContext searchContext = new AppSearchManager.SearchContext.Builder().
               setDatabaseName(dbName).build());
            appSearchManager.createSearchSession(searchContext, mExecutor, appSearchSessionResult -&gt; {
                 mAppSearchSession = appSearchSessionResult.getResultValue();
            });

After opening the session, a schema must be set in order to define the organizational structure of data. The schema is set by calling AppSearchSession#setSchema. The schema is composed of a collection of AppSearchSchema objects, each of which defines a unique type of data.

Example:

AppSearchSchema emailSchemaType = new AppSearchSchema.Builder("Email")
                .addProperty(new StringPropertyConfig.Builder("subject")
                   .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                   .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                   .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
               .build()
            ).build();

            SetSchemaRequest request = new SetSchemaRequest.Builder().addSchema(emailSchemaType).build();
            mAppSearchSession.set(request, mExecutor, appSearchResult -&gt; {
                 if (appSearchResult.isSuccess()) {
                      //Schema has been successfully set.
                 }
            });

The basic unit of data in AppSearch is represented as a GenericDocument object, containing an ID, namespace, time-to-live, score, and properties. A namespace organizes a logical group of documents. For example, a namespace can be created to group documents on a per-account basis. An ID identifies a single document within a namespace. The combination of namespace and ID uniquely identifies a GenericDocument in the database.

Once the schema has been set, GenericDocument objects can be put into the database and indexed by calling AppSearchSession#put.

Example:

// Although for this example we use GenericDocument directly, we recommend extending
            // GenericDocument to create specific types (i.e. Email) with specific setters/getters.
            GenericDocument email = new GenericDocument.Builder<>(NAMESPACE, ID, EMAIL_SCHEMA_TYPE)
                .setPropertyString(“subject”, EMAIL_SUBJECT)
                .setScore(EMAIL_SCORE)
                .build();

            PutDocumentsRequest request = new PutDocumentsRequest.Builder().addGenericDocuments(email)
                .build();
            mAppSearchSession.put(request, mExecutor, appSearchBatchResult -&gt; {
                 if (appSearchBatchResult.isSuccess()) {
                      //All documents have been successfully indexed.
                 }
            });

Searching within the database is done by calling AppSearchSession#search and providing the query string to search for, as well as a SearchSpec.

Alternatively, AppSearchSession#getByDocumentId can be called to retrieve documents by namespace and ID.

Document removal is done either by time-to-live expiration, or explicitly calling a remove operation. Remove operations can be done by namespace and ID via AppSearchSession#remove(RemoveByDocumentIdRequest, Executor, BatchResultCallback), or by query via AppSearchSession#remove(String, SearchSpec, Executor, Consumer).

Java documentation for android.app.appsearch.AppSearchManager.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

AppSearchManager(IntPtr, JniHandleOwnership)

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass
ThresholdType

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CreateEnterpriseGlobalSearchSession(IExecutor, IConsumer)

Creates a new EnterpriseGlobalSearchSession

CreateGlobalSearchSession(IExecutor, IConsumer)

Creates a new GlobalSearchSession.

CreateSearchSession(AppSearchManager+SearchContext, IExecutor, IConsumer)

Creates a new AppSearchSession.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to