use of org.springframework.data.mongodb.core.query.TextQuery in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method shouldParseNestedKeywordWithArgumentMatchingTheSourceEntitiesConstructorCorrectly.
// DATAMONGO-2517
@Test
void shouldParseNestedKeywordWithArgumentMatchingTheSourceEntitiesConstructorCorrectly() {
TextQuery source = new TextQuery("test");
org.bson.Document target = mapper.getMappedObject(source.getQueryObject(), context.getPersistentEntity(WithSingleStringArgConstructor.class));
assertThat(target).isEqualTo(org.bson.Document.parse("{\"$text\" : { \"$search\" : \"test\" }}"));
}
use of org.springframework.data.mongodb.core.query.TextQuery in project main by JohnPeng739.
the class GeneralAccessorImpl method search.
/**
* {@inheritDoc}
*
* @see GeneralTextSearchAccessor#search(Pagination, List, boolean, Class)
*/
@Override
public <T extends Base> List<T> search(Pagination pagination, List<String> contents, boolean valid, Class<T> clazz) {
try {
if (clazz.isInterface()) {
clazz = EntityFactory.getEntityClass(clazz);
}
Query query = new TextQuery(new TextCriteria().matchingAny(contents.toArray(new String[0])));
if (valid) {
query.addCriteria(where("valid").is(true));
}
if (pagination != null) {
pagination.setTotal((int) template.count(query, clazz));
query.skip((pagination.getPage() - 1) * pagination.getSize());
query.limit(pagination.getSize());
}
return template.find(query, clazz);
} catch (ClassNotFoundException ex) {
if (logger.isErrorEnabled()) {
logger.error(String.format("Text search entity[%s] fail, condition: %s.", clazz.getName(), StringUtils.merge(contents, ",")), ex);
}
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.ENTITY_INSTANCE_FAIL);
}
}
Aggregations