Search in sources :

Example 6 with Index

use of dev.morphia.annotations.Index in project morphia by mongodb.

the class IndexHelperTest method wildcardTextIndex.

@Test
public void wildcardTextIndex() {
    MongoCollection<Document> indexes = getDatabase().getCollection("indexes");
    EntityModel model = getMapper().getEntityModel(IndexedClass.class);
    Index index = indexBuilder().fields(fieldBuilder().value("$**").type(IndexType.TEXT).build()).build();
    getIndexHelper().createIndex(indexes, model, index);
    List<Document> wildcard = getIndexInfo(IndexedClass.class);
    boolean found = false;
    for (Document document : wildcard) {
        found |= document.get("name").equals("$**_text");
    }
    assertTrue(found, "Should have found the wildcard index");
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Index(dev.morphia.annotations.Index) Document(org.bson.Document) Test(org.testng.annotations.Test)

Example 7 with Index

use of dev.morphia.annotations.Index in project morphia by mongodb.

the class IndexHelperTest method indexPartialFilters.

@Test
public void indexPartialFilters() {
    MongoCollection<Document> collection = getDatabase().getCollection("indexes");
    EntityModel model = getMapper().getEntityModel(IndexedClass.class);
    Index index = indexBuilder().fields(fieldBuilder().value("text").build()).options(indexOptionsBuilder().partialFilter("{ name : { $gt : 13 } }").build()).build();
    getIndexHelper().createIndex(collection, model, index);
    findPartialIndex(Document.parse(index.options().partialFilter()));
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Index(dev.morphia.annotations.Index) Document(org.bson.Document) Test(org.testng.annotations.Test)

Aggregations

Index (dev.morphia.annotations.Index)7 Test (org.testng.annotations.Test)7 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)5 Document (org.bson.Document)4 IndexOptions (dev.morphia.annotations.IndexOptions)1 Indexed (dev.morphia.annotations.Indexed)1 Text (dev.morphia.annotations.Text)1 MappingException (dev.morphia.mapping.MappingException)1