当前位置: 首页>>代码示例>>Java>>正文


Java IndexType类代码示例

本文整理汇总了Java中org.mongodb.morphia.utils.IndexType的典型用法代码示例。如果您正苦于以下问题:Java IndexType类的具体用法?Java IndexType怎么用?Java IndexType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IndexType类属于org.mongodb.morphia.utils包,在下文中一共展示了IndexType类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseFieldsString

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
private List<Field> parseFieldsString(final String str) {
    List<Field> fields = new ArrayList<Field>();
    final String[] parts = str.split(",");
    for (String s : parts) {
        s = s.trim();
        IndexType dir = IndexType.ASC;

        if (s.startsWith("-")) {
            dir = IndexType.DESC;
            s = s.substring(1).trim();
        }

        fields.add(new FieldBuilder()
                       .value(s)
                       .type(dir));
    }
    return fields;
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:19,代码来源:IndexBuilder.java

示例2: calculateBadKeys

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Test
public void calculateBadKeys() {
    MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
    IndexBuilder index = new IndexBuilder()
        .fields(new FieldBuilder()
                    .value("texting")
                    .type(IndexType.TEXT)
                    .weight(1),
                new FieldBuilder()
                    .value("nest")
                    .type(IndexType.DESC));
    try {
        indexHelper.calculateKeys(mappedClass, index);
        fail("Validation should have failed on the bad key");
    } catch (MappingException e) {
        // all good
    }

    index.options(new IndexOptionsBuilder().disableValidation(true));
    indexHelper.calculateKeys(mappedClass, index);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:IndexHelperTest.java

示例3: calculateKeys

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Test
public void calculateKeys() {
    MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
    BsonDocument keys = indexHelper.calculateKeys(mappedClass, new IndexBuilder()
        .fields(new FieldBuilder()
                    .value("text")
                    .type(IndexType.TEXT)
                    .weight(1),
                new FieldBuilder()
                    .value("nest")
                    .type(IndexType.DESC)));
    assertEquals(new BsonDocument()
                     .append("text", new BsonString("text"))
                     .append("nest", new BsonInt32(-1)),
                 keys);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:17,代码来源:IndexHelperTest.java

示例4: oldIndexedForm

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void oldIndexedForm() {
    Indexed indexed = new IndexedBuilder()
        .name("index_name")
        .background(true)
        .dropDups(true)
        .expireAfterSeconds(42)
        .sparse(true)
        .unique(true)
        .value(IndexDirection.DESC);
    assertEquals(indexed.options().name(), "");

    Index converted = indexHelper.convert(indexed, "oldstyle");
    assertEquals(converted.options().name(), "index_name");
    assertTrue(converted.options().background());
    assertTrue(converted.options().dropDups());
    assertTrue(converted.options().sparse());
    assertTrue(converted.options().unique());
    assertEquals(new FieldBuilder().value("oldstyle").type(IndexType.DESC), converted.fields()[0]);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:IndexHelperTest.java

示例5: convertTextIndex

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void convertTextIndex() {
    TextBuilder text = new TextBuilder()
        .value(4)
        .options(new IndexOptionsBuilder()
                     .name("index_name")
                     .background(true)
                     .dropDups(true)
                     .expireAfterSeconds(42)
                     .sparse(true)
                     .unique(true));

    Index index = indexHelper.convert(text, "search_field");
    assertEquals(index.options().name(), "index_name");
    assertTrue(index.options().background());
    assertTrue(index.options().dropDups());
    assertTrue(index.options().sparse());
    assertTrue(index.options().unique());
    assertEquals(new FieldBuilder()
                     .value("search_field")
                     .type(IndexType.TEXT)
                     .weight(4),
                 index.fields()[0]);

}
 
开发者ID:mongodb,项目名称:morphia,代码行数:27,代码来源:IndexHelperTest.java

示例6: normalizeIndexed

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void normalizeIndexed() {
    Indexed indexed = new IndexedBuilder()
        .value(IndexDirection.DESC)
        .options(new IndexOptionsBuilder().name("index_name")
                                          .background(true)
                                          .dropDups(true)
                                          .expireAfterSeconds(42)
                                          .sparse(true)
                                          .unique(true));

    Index converted = indexHelper.convert(indexed, "oldstyle");
    assertEquals(converted.options().name(), "index_name");
    assertTrue(converted.options().background());
    assertTrue(converted.options().dropDups());
    assertTrue(converted.options().sparse());
    assertTrue(converted.options().unique());
    assertEquals(new FieldBuilder().value("oldstyle").type(IndexType.DESC), converted.fields()[0]);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:21,代码来源:IndexHelperTest.java

示例7: wildcardTextIndex

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Test
public void wildcardTextIndex() {
    MongoCollection<Document> indexes = getDatabase().getCollection("indexes");
    MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);

    IndexBuilder index = new IndexBuilder()
        .fields(new FieldBuilder()
                    .value("$**")
                    .type(IndexType.TEXT));

    indexHelper.createIndex(indexes, mappedClass, index, false);

    List<DBObject> wildcard = getDb().getCollection("indexes").getIndexInfo();
    boolean found = false;
    for (DBObject dbObject : wildcard) {
        found |= dbObject.get("name").equals("$**_text");
    }
    assertTrue("Should have found the wildcard index", found);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:20,代码来源:IndexHelperTest.java

示例8: calculateWeights

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
private void calculateWeights(final Index index, final com.mongodb.client.model.IndexOptions indexOptions) {
    Document weights = new Document();
    for (Field field : index.fields()) {
        if (field.weight() != -1) {
            if (field.type() != IndexType.TEXT) {
                throw new MappingException("Weight values only apply to text indexes: " + Arrays.toString(index.fields()));
            }
            weights.put(field.value(), field.weight());
        }
    }
    if (!weights.isEmpty()) {
        indexOptions.weights(weights);
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:15,代码来源:IndexHelper.java

示例9: convert

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
Index convert(final Text text, final String nameToStore) {
    return new IndexBuilder()
        .options(text.options())
        .fields(Collections.<Field>singletonList(new FieldBuilder()
                                                     .value(nameToStore)
                                                     .type(IndexType.TEXT)
                                                     .weight(text.value())));
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:9,代码来源:IndexHelper.java

示例10: type

import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Override
public IndexType type() {
    return get("type");
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:5,代码来源:FieldBuilder.java


注:本文中的org.mongodb.morphia.utils.IndexType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。