本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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]);
}
示例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]);
}
示例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]);
}
示例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);
}
示例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);
}
}
示例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())));
}
示例10: type
import org.mongodb.morphia.utils.IndexType; //导入依赖的package包/类
@Override
public IndexType type() {
return get("type");
}