Search in sources :

Example 1 with Text

use of org.mongodb.morphia.annotations.Text in project morphia by mongodb.

the class IndexHelper method collectFieldIndexes.

@SuppressWarnings("deprecation")
private List<Index> collectFieldIndexes(final MappedClass mc) {
    List<Index> list = new ArrayList<Index>();
    for (final MappedField mf : mc.getPersistenceFields()) {
        if (mf.hasAnnotation(Indexed.class)) {
            final Indexed indexed = mf.getAnnotation(Indexed.class);
            list.add(convert(indexed, mf.getNameToStore()));
        } else if (mf.hasAnnotation(Text.class)) {
            final Text text = mf.getAnnotation(Text.class);
            list.add(convert(text, mf.getNameToStore()));
        }
    }
    return list;
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) ArrayList(java.util.ArrayList) Index(org.mongodb.morphia.annotations.Index) Text(org.mongodb.morphia.annotations.Text) Indexed(org.mongodb.morphia.annotations.Indexed)

Example 2 with Text

use of org.mongodb.morphia.annotations.Text in project morphia by mongodb.

the class IndexHelperTest method textPartialFilters.

@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()));
}
Also used : Text(org.mongodb.morphia.annotations.Text) MappedClass(org.mongodb.morphia.mapping.MappedClass) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) Test(org.junit.Test)

Aggregations

Text (org.mongodb.morphia.annotations.Text)2 ArrayList (java.util.ArrayList)1 BsonDocument (org.bson.BsonDocument)1 Document (org.bson.Document)1 Test (org.junit.Test)1 Index (org.mongodb.morphia.annotations.Index)1 Indexed (org.mongodb.morphia.annotations.Indexed)1 MappedClass (org.mongodb.morphia.mapping.MappedClass)1 MappedField (org.mongodb.morphia.mapping.MappedField)1