diff options
author | Cassie Wang <cassiewang@google.com> | 2020-07-24 15:02:17 -0700 |
---|---|---|
committer | Cassie Wang <cassiewang@google.com> | 2020-07-24 15:42:02 -0700 |
commit | dd9a0fa36f5a982ccb2ac30108ed067479d73b85 (patch) | |
tree | eb28e79b321b229a248f5fe00d4d7dd365602857 /java | |
parent | 260b5e176352e656013d635694a35e795e7dccab (diff) | |
parent | c994b6ea30c9be8976da0b1bf6a8923907ff903f (diff) | |
download | icing-dd9a0fa36f5a982ccb2ac30108ed067479d73b85.tar.gz |
Merge remote-tracking branch 'aosp/upstream-master' into androidx-master-dev
* aosp/upstream-master:
Pull upstream changes.
Change-Id: I1dfaf946045f9b00d1f560a1b9e71ea16938c4d0
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/google/android/icing/IcingSearchEngine.java | 58 | ||||
-rw-r--r-- | java/tests/instrumentation/src/com/google/android/icing/IcingSearchEngineTest.java | 25 |
2 files changed, 69 insertions, 14 deletions
diff --git a/java/src/com/google/android/icing/IcingSearchEngine.java b/java/src/com/google/android/icing/IcingSearchEngine.java index 9e63b9f..d981d1b 100644 --- a/java/src/com/google/android/icing/IcingSearchEngine.java +++ b/java/src/com/google/android/icing/IcingSearchEngine.java @@ -20,6 +20,7 @@ import com.google.android.icing.proto.DeleteByNamespaceResultProto; import com.google.android.icing.proto.DeleteBySchemaTypeResultProto; import com.google.android.icing.proto.DeleteResultProto; import com.google.android.icing.proto.DocumentProto; +import com.google.android.icing.proto.GetAllNamespacesResultProto; import com.google.android.icing.proto.GetOptimizeInfoResultProto; import com.google.android.icing.proto.GetResultProto; import com.google.android.icing.proto.GetSchemaResultProto; @@ -37,12 +38,15 @@ import com.google.android.icing.proto.SearchResultProto; import com.google.android.icing.proto.SearchSpecProto; import com.google.android.icing.proto.SetSchemaResultProto; import com.google.android.icing.proto.StatusProto; +import com.google.protobuf.ExtensionRegistryLite; import com.google.protobuf.InvalidProtocolBufferException; /** Java wrapper to access native APIs in external/icing/icing/icing-search-engine.h */ public final class IcingSearchEngine { private static final String TAG = "IcingSearchEngine"; + private static final ExtensionRegistryLite EXTENSION_REGISTRY_LITE = + ExtensionRegistryLite.getEmptyRegistry(); private final long nativePointer; @@ -71,7 +75,7 @@ public final class IcingSearchEngine { } try { - return InitializeResultProto.parseFrom(initializeResultBytes); + return InitializeResultProto.parseFrom(initializeResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing InitializeResultProto.", e); return InitializeResultProto.newBuilder() @@ -98,7 +102,7 @@ public final class IcingSearchEngine { } try { - return SetSchemaResultProto.parseFrom(setSchemaResultBytes); + return SetSchemaResultProto.parseFrom(setSchemaResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing SetSchemaResultProto.", e); return SetSchemaResultProto.newBuilder() @@ -118,7 +122,7 @@ public final class IcingSearchEngine { } try { - return GetSchemaResultProto.parseFrom(getSchemaResultBytes); + return GetSchemaResultProto.parseFrom(getSchemaResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing GetSchemaResultProto.", e); return GetSchemaResultProto.newBuilder() @@ -138,7 +142,7 @@ public final class IcingSearchEngine { } try { - return GetSchemaTypeResultProto.parseFrom(getSchemaTypeResultBytes); + return GetSchemaTypeResultProto.parseFrom(getSchemaTypeResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing GetSchemaTypeResultProto.", e); return GetSchemaTypeResultProto.newBuilder() @@ -158,7 +162,7 @@ public final class IcingSearchEngine { } try { - return PutResultProto.parseFrom(putResultBytes); + return PutResultProto.parseFrom(putResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing PutResultProto.", e); return PutResultProto.newBuilder() @@ -178,7 +182,7 @@ public final class IcingSearchEngine { } try { - return GetResultProto.parseFrom(getResultBytes); + return GetResultProto.parseFrom(getResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing GetResultProto.", e); return GetResultProto.newBuilder() @@ -188,6 +192,27 @@ public final class IcingSearchEngine { } @NonNull + public GetAllNamespacesResultProto getAllNamespaces() { + byte[] getAllNamespacesResultBytes = nativeGetAllNamespaces(nativePointer); + if (getAllNamespacesResultBytes == null) { + Log.e(TAG, "Received null GetAllNamespacesResultProto from native."); + return GetAllNamespacesResultProto.newBuilder() + .setStatus(StatusProto.newBuilder().setCode(StatusProto.Code.INTERNAL)) + .build(); + } + + try { + return GetAllNamespacesResultProto.parseFrom( + getAllNamespacesResultBytes, EXTENSION_REGISTRY_LITE); + } catch (InvalidProtocolBufferException e) { + Log.e(TAG, "Error parsing GetAllNamespacesResultProto.", e); + return GetAllNamespacesResultProto.newBuilder() + .setStatus(StatusProto.newBuilder().setCode(StatusProto.Code.INTERNAL)) + .build(); + } + } + + @NonNull public SearchResultProto search( @NonNull SearchSpecProto searchSpec, @NonNull ScoringSpecProto scoringSpec, @@ -206,7 +231,7 @@ public final class IcingSearchEngine { } try { - return SearchResultProto.parseFrom(searchResultBytes); + return SearchResultProto.parseFrom(searchResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing SearchResultProto.", e); return SearchResultProto.newBuilder() @@ -226,7 +251,7 @@ public final class IcingSearchEngine { } try { - return DeleteResultProto.parseFrom(deleteResultBytes); + return DeleteResultProto.parseFrom(deleteResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing DeleteResultProto.", e); return DeleteResultProto.newBuilder() @@ -246,7 +271,8 @@ public final class IcingSearchEngine { } try { - return DeleteByNamespaceResultProto.parseFrom(deleteByNamespaceResultBytes); + return DeleteByNamespaceResultProto.parseFrom( + deleteByNamespaceResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing DeleteByNamespaceResultProto.", e); return DeleteByNamespaceResultProto.newBuilder() @@ -266,7 +292,8 @@ public final class IcingSearchEngine { } try { - return DeleteBySchemaTypeResultProto.parseFrom(deleteBySchemaTypeResultBytes); + return DeleteBySchemaTypeResultProto.parseFrom( + deleteBySchemaTypeResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing DeleteBySchemaTypeResultProto.", e); return DeleteBySchemaTypeResultProto.newBuilder() @@ -286,7 +313,7 @@ public final class IcingSearchEngine { } try { - return PersistToDiskResultProto.parseFrom(persistToDiskResultBytes); + return PersistToDiskResultProto.parseFrom(persistToDiskResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing PersistToDiskResultProto.", e); return PersistToDiskResultProto.newBuilder() @@ -306,7 +333,7 @@ public final class IcingSearchEngine { } try { - return OptimizeResultProto.parseFrom(optimizeResultBytes); + return OptimizeResultProto.parseFrom(optimizeResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing OptimizeResultProto.", e); return OptimizeResultProto.newBuilder() @@ -326,7 +353,8 @@ public final class IcingSearchEngine { } try { - return GetOptimizeInfoResultProto.parseFrom(getOptimizeInfoResultBytes); + return GetOptimizeInfoResultProto.parseFrom( + getOptimizeInfoResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing GetOptimizeInfoResultProto.", e); return GetOptimizeInfoResultProto.newBuilder() @@ -346,7 +374,7 @@ public final class IcingSearchEngine { } try { - return ResetResultProto.parseFrom(resetResultBytes); + return ResetResultProto.parseFrom(resetResultBytes, EXTENSION_REGISTRY_LITE); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Error parsing ResetResultProto.", e); return ResetResultProto.newBuilder() @@ -370,6 +398,8 @@ public final class IcingSearchEngine { private static native byte[] nativeGet(long nativePointer, String namespace, String uri); + private static native byte[] nativeGetAllNamespaces(long nativePointer); + private static native byte[] nativeSearch( long nativePointer, byte[] searchSpecBytes, byte[] scoringSpecBytes, byte[] resultSpecBytes); diff --git a/java/tests/instrumentation/src/com/google/android/icing/IcingSearchEngineTest.java b/java/tests/instrumentation/src/com/google/android/icing/IcingSearchEngineTest.java index 01a6050..a01e7db 100644 --- a/java/tests/instrumentation/src/com/google/android/icing/IcingSearchEngineTest.java +++ b/java/tests/instrumentation/src/com/google/android/icing/IcingSearchEngineTest.java @@ -21,6 +21,7 @@ import com.google.android.icing.proto.DeleteByNamespaceResultProto; import com.google.android.icing.proto.DeleteBySchemaTypeResultProto; import com.google.android.icing.proto.DeleteResultProto; import com.google.android.icing.proto.DocumentProto; +import com.google.android.icing.proto.GetAllNamespacesResultProto; import com.google.android.icing.proto.GetOptimizeInfoResultProto; import com.google.android.icing.proto.GetResultProto; import com.google.android.icing.proto.GetSchemaResultProto; @@ -311,6 +312,30 @@ public final class IcingSearchEngineTest { } @Test + public void testGetAllNamespaces() throws Exception { + IcingSearchEngineOptions options = + IcingSearchEngineOptions.newBuilder().setBaseDir(filesDir).build(); + IcingSearchEngine icing = new IcingSearchEngine(options); + assertThat(icing.initialize().getStatus().getCode()).isEqualTo(StatusProto.Code.OK); + + SchemaTypeConfigProto emailTypeConfig = createEmailTypeConfig(); + SchemaProto schema = SchemaProto.newBuilder().addTypes(emailTypeConfig).build(); + assertThat( + icing + .setSchema(schema, /*ignoreErrorsAndDeleteDocuments=*/ false) + .getStatus() + .getCode()) + .isEqualTo(StatusProto.Code.OK); + + DocumentProto emailDocument = createEmailDocument("namespace", "uri"); + assertThat(icing.put(emailDocument).getStatus().getCode()).isEqualTo(StatusProto.Code.OK); + + GetAllNamespacesResultProto getAllNamespacesResultProto = icing.getAllNamespaces(); + assertThat(getAllNamespacesResultProto.getStatus().getCode()).isEqualTo(StatusProto.Code.OK); + assertThat(getAllNamespacesResultProto.getNamespacesList()).containsExactly("namespace"); + } + + @Test public void testReset() throws Exception { IcingSearchEngineOptions options = IcingSearchEngineOptions.newBuilder().setBaseDir(filesDir).build(); |