public IndexOptionsBuilder(final IndexOptions original, final String prefix) { super(original); if(!"".equals(original.partialFilter())) { final Document parse = Document.parse(original.partialFilter()); final Document filter = new Document(); for (final Entry<String, Object> entry : parse.entrySet()) { filter.put(prefix + "." + entry.getKey(), entry.getValue()); } partialFilter(filter.toJson()); } }
@Test public void indexedPartialFilters() { MongoCollection<Document> collection = getDatabase().getCollection("indexes"); MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class); Indexed indexed = new IndexedBuilder() .options(new IndexOptionsBuilder() .partialFilter("{ name : { $gt : 13 } }")); indexHelper.createIndex(collection, mappedClass, indexHelper.convert(indexed, "text"), false); findPartialIndex(BasicDBObject.parse(indexed.options().partialFilter())); }
@Test public void textPartialFilters() { MongoCollection<Document> collection = getDatabase().getCollection("indexes"); MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class); Text text = new TextBuilder() .value(4) .options(new IndexOptionsBuilder() .partialFilter("{ name : { $gt : 13 } }")); indexHelper.createIndex(collection, mappedClass, indexHelper.convert(text, "text"), false); findPartialIndex(BasicDBObject.parse(text.options().partialFilter())); }
@Test public void indexPartialFilters() { MongoCollection<Document> collection = getDatabase().getCollection("indexes"); MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class); Index index = new IndexBuilder() .fields(new FieldBuilder().value("text")) .options(new IndexOptionsBuilder() .partialFilter("{ name : { $gt : 13 } }")); indexHelper.createIndex(collection, mappedClass, index, false); findPartialIndex(BasicDBObject.parse(index.options().partialFilter())); } @Test