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); } }
ops = ops.weights((org.bson.Document) indexOptions.get("weights"));
ops = ops.weights((org.bson.Document) indexOptions.get("weights"));
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); } }
weights.put("lorem", 15); weights.put("_fulltext.text", 5); options.weights(weights); Document index = new Document(); index.put("$**", "text");
break; case "weights": indexOptions.weights((Bson) value); break; case "languageOverride":
indexOptions.weights( (Bson) options.get( "weights" ) );
indexOptions.weights( (Bson) options.get( "weights" ) );
mongoDbIndexOptions.weights(indexOptions.get("weights", Bson.class));
applyIfTrue(options.containsKey("unique"), () -> indexOptions.unique(options.getBoolean("unique"))); applyIfTrue(options.containsKey("version"), () -> indexOptions.version(options.getInteger("version"))); applyIfTrue(options.containsKey("weights"), () -> indexOptions.weights(options.get("weights", Bson.class)));
ret.weights(options.get("weights") .asDocument());