Search in sources :

Example 1 with Criteria

use of org.springframework.data.solr.core.query.Criteria in project nixmash-blog by mintster.

the class CustomPostDocRepositoryImpl method findPostsBySimpleQuery.

@Override
public List<PostDoc> findPostsBySimpleQuery(String userQuery) {
    Query query = new SimpleQuery(userQuery);
    query.addFilterQuery(new SimpleQuery(new Criteria(IPostDoc.DOCTYPE).is(SolrDocType.POST)));
    query.setRows(1000);
    Page<PostDoc> results = solrTemplate.queryForPage(query, PostDoc.class);
    return results.getContent();
}
Also used : SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Query(org.springframework.data.solr.core.query.Query) SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Criteria(org.springframework.data.solr.core.query.Criteria) IPostDoc(com.nixmash.blog.solr.model.IPostDoc) PostDoc(com.nixmash.blog.solr.model.PostDoc)

Example 2 with Criteria

use of org.springframework.data.solr.core.query.Criteria in project nixmash-blog by mintster.

the class SolrLocationTests method testFindByLocationCriteria.

@Test
public void testFindByLocationCriteria() {
    Point location = new Point(22.15, -90.85);
    Criteria criteria = new Criteria("store").near(location, new Distance(5));
    Page<Product> result = solrOperations.queryForPage(new SimpleQuery(criteria), Product.class);
    Assert.assertEquals(1, result.getTotalElements());
    Assert.assertEquals(locatedInYonkers.getId(), result.getContent().get(0).getId());
}
Also used : SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Product(com.nixmash.blog.solr.model.Product) Point(org.springframework.data.geo.Point) SimpleStringCriteria(org.springframework.data.solr.core.query.SimpleStringCriteria) Criteria(org.springframework.data.solr.core.query.Criteria) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 3 with Criteria

use of org.springframework.data.solr.core.query.Criteria in project nixmash-blog by mintster.

the class CustomPostDocRepositoryImpl method fullSearch.

@Override
public List<PostDoc> fullSearch(PostQueryDTO postQueryDTO) {
    Query query = new SimpleQuery(postQueryDTO.getQuery());
    if (!postQueryDTO.getPostType().equals(PostType.UNDEFINED)) {
        query.addFilterQuery(new SimpleQuery(new Criteria(IPostDoc.POST_TYPE).is(postQueryDTO.getPostType())));
    }
    query.addFilterQuery(new SimpleQuery(new Criteria(IPostDoc.DOCTYPE).is(SolrDocType.POST)));
    query.setRows(1000);
    Page<PostDoc> results = solrTemplate.queryForPage(query, PostDoc.class);
    return results.getContent();
}
Also used : SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Query(org.springframework.data.solr.core.query.Query) SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Criteria(org.springframework.data.solr.core.query.Criteria) IPostDoc(com.nixmash.blog.solr.model.IPostDoc) PostDoc(com.nixmash.blog.solr.model.PostDoc)

Example 4 with Criteria

use of org.springframework.data.solr.core.query.Criteria in project nixmash-blog by mintster.

the class CustomPostDocRepositoryImpl method titleAndBodyCriteria.

private Criteria titleAndBodyCriteria(String searchTerms) {
    String[] words = searchTerms.split(" ");
    Criteria criteria = new Criteria();
    for (String word : words) {
        criteria = criteria.and(new Criteria(PostDoc.POST_TITLE).contains(word).or(PostDoc.POST_TEXT).contains(word));
    }
    return criteria.and(new Criteria(PostDoc.DOCTYPE).is("post"));
}
Also used : Criteria(org.springframework.data.solr.core.query.Criteria)

Example 5 with Criteria

use of org.springframework.data.solr.core.query.Criteria in project nixmash-blog by mintster.

the class CustomPostDocRepositoryImpl method pagedFullSearch.

@Override
public Page<PostDoc> pagedFullSearch(PostQueryDTO postQueryDTO, PageRequest pageRequest) {
    Query query = new SimpleQuery(postQueryDTO.getQuery());
    if (!postQueryDTO.getPostType().equals(PostType.UNDEFINED)) {
        query.addFilterQuery(new SimpleQuery(new Criteria(IPostDoc.POST_TYPE).is(postQueryDTO.getPostType())));
    }
    query.addFilterQuery(new SimpleQuery(new Criteria(IPostDoc.DOCTYPE).is(SolrDocType.POST)));
    query.setRows(1000);
    query.setPageRequest(pageRequest);
    Page<PostDoc> results = solrTemplate.queryForPage(query, PostDoc.class);
    return results;
}
Also used : SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Query(org.springframework.data.solr.core.query.Query) SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Criteria(org.springframework.data.solr.core.query.Criteria) IPostDoc(com.nixmash.blog.solr.model.IPostDoc) PostDoc(com.nixmash.blog.solr.model.PostDoc)

Aggregations

Criteria (org.springframework.data.solr.core.query.Criteria)5 SimpleQuery (org.springframework.data.solr.core.query.SimpleQuery)4 IPostDoc (com.nixmash.blog.solr.model.IPostDoc)3 PostDoc (com.nixmash.blog.solr.model.PostDoc)3 Query (org.springframework.data.solr.core.query.Query)3 Product (com.nixmash.blog.solr.model.Product)1 Test (org.junit.Test)1 Distance (org.springframework.data.geo.Distance)1 Point (org.springframework.data.geo.Point)1 SimpleStringCriteria (org.springframework.data.solr.core.query.SimpleStringCriteria)1