Search in sources :

Example 1 with PostQueryDTO

use of com.nixmash.blog.jpa.dto.PostQueryDTO in project nixmash-blog by mintster.

the class PostsRestController method getFullSearchPosts.

// endregion
// region Full Search
@RequestMapping(value = "/search/page/{pageNumber}", produces = "text/html;charset=UTF-8")
public String getFullSearchPosts(@PathVariable int pageNumber, HttpServletRequest request, CurrentUser currentUser) {
    PostQueryDTO postQueryDTO = (PostQueryDTO) WebUtils.getSessionAttribute(request, SESSION_POSTQUERYDTO);
    String result = null;
    List<PostDoc> postDocs = null;
    if (postQueryDTO != null) {
        try {
            postDocs = postDocService.doFullSearch(postQueryDTO);
        } catch (UncategorizedSolrException ex) {
            logger.info(MessageFormat.format("Bad Query: {0}", postQueryDTO.getQuery()));
            return fmService.getNoResultsMessage(postQueryDTO.getQuery());
        }
        if (postDocs.size() == 0) {
            result = fmService.getNoResultsMessage(postQueryDTO.getQuery());
        } else {
            Slice<PostDoc> postDocSlice = postDocService.doPagedFullSearch(postQueryDTO, pageNumber, POST_PAGING_SIZE);
            result = populatePostDocStream(postDocSlice.getContent(), currentUser);
            WebUtils.setSessionAttribute(request, SESSION_ATTRIBUTE_FULLSEARCH_POSTS, postDocSlice.getContent());
        }
    }
    return result;
}
Also used : UncategorizedSolrException(org.springframework.data.solr.UncategorizedSolrException) PostQueryDTO(com.nixmash.blog.jpa.dto.PostQueryDTO) PostDoc(com.nixmash.blog.solr.model.PostDoc) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) JsonRequestMapping(com.nixmash.blog.mvc.annotations.JsonRequestMapping)

Example 2 with PostQueryDTO

use of com.nixmash.blog.jpa.dto.PostQueryDTO in project nixmash-blog by mintster.

the class SolrPostTests method badSimpleQueryThrowsUncategorizedSolrException.

@Test
public void badSimpleQueryThrowsUncategorizedSolrException() {
    int i = 0;
    try {
        postDocService.doFullSearch(new PostQueryDTO("bad:field"));
    } catch (Exception ex) {
        i++;
        Assert.assertTrue(ex instanceof UncategorizedSolrException);
    }
    try {
        postDocService.doFullSearch(new PostQueryDTO("bad::format"));
    } catch (Exception ex) {
        i++;
        Assert.assertTrue(ex instanceof UncategorizedSolrException);
    }
    try {
        postDocService.doFullSearch(new PostQueryDTO("title:goodquery"));
    } catch (UncategorizedSolrException ex) {
        i++;
    }
    Assert.assertEquals(2, i);
}
Also used : UncategorizedSolrException(org.springframework.data.solr.UncategorizedSolrException) PostQueryDTO(com.nixmash.blog.jpa.dto.PostQueryDTO) PostNotFoundException(com.nixmash.blog.jpa.exceptions.PostNotFoundException) UncategorizedSolrException(org.springframework.data.solr.UncategorizedSolrException) Test(org.junit.Test)

Example 3 with PostQueryDTO

use of com.nixmash.blog.jpa.dto.PostQueryDTO in project nixmash-blog by mintster.

the class SolrPostTests method fullSearchWithPostType_LINK_ReturnsNone.

@Test
public void fullSearchWithPostType_LINK_ReturnsNone() throws Exception {
    PostQueryDTO postQueryDTO = new PostQueryDTO("body:begins", PostType.LINK);
    List<PostDoc> postDocs = postDocService.doFullSearch(postQueryDTO);
    assertEquals(postDocs.size(), 0);
}
Also used : PostQueryDTO(com.nixmash.blog.jpa.dto.PostQueryDTO) PostDoc(com.nixmash.blog.solr.model.PostDoc) Test(org.junit.Test)

Example 4 with PostQueryDTO

use of com.nixmash.blog.jpa.dto.PostQueryDTO in project nixmash-blog by mintster.

the class SolrPostTests method fullSearchWithPostType_POST_ReturnsAll.

@Test
public void fullSearchWithPostType_POST_ReturnsAll() throws Exception {
    PostQueryDTO postQueryDTO = new PostQueryDTO("body:begins", PostType.POST);
    List<PostDoc> postDocs = postDocService.doFullSearch(postQueryDTO);
    assertEquals(postDocs.size(), 3);
}
Also used : PostQueryDTO(com.nixmash.blog.jpa.dto.PostQueryDTO) PostDoc(com.nixmash.blog.solr.model.PostDoc) Test(org.junit.Test)

Example 5 with PostQueryDTO

use of com.nixmash.blog.jpa.dto.PostQueryDTO in project nixmash-blog by mintster.

the class SolrPostTests method fullSearch.

// region fullSearch tests
// fullSearch tests use the following PostDocument objects
// 100 Ways To Title Something
// This post title begins with 100 : POST
// ------------------------
// 200 Ways To Title Something
// This post title begins with 200 : POST
// ------------------------
// 1000 Ways To Title Something
// This post title begins with 1000 : POST
@Test
public void fullSearch() throws Exception {
    PostQueryDTO postQueryDTO = new PostQueryDTO("body:begins", PostType.UNDEFINED);
    List<PostDoc> postDocs = postDocService.doFullSearch(postQueryDTO);
    assertEquals(postDocs.size(), 3);
}
Also used : PostQueryDTO(com.nixmash.blog.jpa.dto.PostQueryDTO) PostDoc(com.nixmash.blog.solr.model.PostDoc) Test(org.junit.Test)

Aggregations

PostQueryDTO (com.nixmash.blog.jpa.dto.PostQueryDTO)6 PostDoc (com.nixmash.blog.solr.model.PostDoc)4 Test (org.junit.Test)4 UncategorizedSolrException (org.springframework.data.solr.UncategorizedSolrException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 PostNotFoundException (com.nixmash.blog.jpa.exceptions.PostNotFoundException)1 JsonRequestMapping (com.nixmash.blog.mvc.annotations.JsonRequestMapping)1