Skip to content

Commit

Permalink
create index on _policyId and __policyRev for thingEntities collectio…
Browse files Browse the repository at this point in the history
…n in search

Signed-off-by: Florian Fendt <Florian.Fendt@bosch-si.com>
  • Loading branch information
ffendt committed Nov 6, 2018
1 parent e337ad1 commit e11d183
Showing 1 changed file with 19 additions and 1 deletion.
Expand Up @@ -18,12 +18,16 @@
import static org.eclipse.ditto.services.thingsearch.persistence.PersistenceConstants.FIELD_NAMESPACE;
import static org.eclipse.ditto.services.thingsearch.persistence.PersistenceConstants.FIELD_PATH_KEY;
import static org.eclipse.ditto.services.thingsearch.persistence.PersistenceConstants.FIELD_PATH_VALUE;
import static org.eclipse.ditto.services.thingsearch.persistence.PersistenceConstants.FIELD_POLICY_ID;
import static org.eclipse.ditto.services.thingsearch.persistence.PersistenceConstants.FIELD_POLICY_REVISION;
import static org.eclipse.ditto.services.thingsearch.persistence.read.MongoThingsSearchPersistence.filterNotDeleted;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.bson.BsonBoolean;
import org.bson.BsonDocument;
import org.eclipse.ditto.services.utils.persistence.mongo.indices.Index;
import org.eclipse.ditto.services.utils.persistence.mongo.indices.IndexFactory;

Expand Down Expand Up @@ -56,13 +60,17 @@ public static final class Things {
private static final Index DELETED = IndexFactory.newInstance("deleted",
keys(FIELD_DELETED), false);

private static final Index POLICY = IndexFactory.newInstance("policy",
keys(FIELD_POLICY_ID, FIELD_POLICY_REVISION), false)
.withPartialFilterExpression(filterPolicyIdExists());

/**
* Gets all defined indices.
*
* @return the indices
*/
public static List<Index> all() {
return Collections.unmodifiableList(Arrays.asList(KEY_VALUE, ACL, GLOBAL_READS, DELETED));
return Collections.unmodifiableList(Arrays.asList(KEY_VALUE, ACL, GLOBAL_READS, DELETED, POLICY));
}

private static List<String> keys(final String... keyNames) {
Expand All @@ -72,6 +80,16 @@ private static List<String> keys(final String... keyNames) {
private Things() {
throw new AssertionError();
}

/**
* Create a BSON filter for existent policyId.
*
* @return the BSON filter.
*/
private static BsonDocument filterPolicyIdExists() {
return new BsonDocument(FIELD_POLICY_ID, new BsonDocument("$exists", BsonBoolean.TRUE));
}

}

}

0 comments on commit e11d183

Please sign in to comment.