Search in sources :

Example 1 with UncategorizedSolrException

use of org.springframework.data.solr.UncategorizedSolrException 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 UncategorizedSolrException

use of org.springframework.data.solr.UncategorizedSolrException in project nixmash-blog by mintster.

the class SolrController method processFindForm.

@RequestMapping(value = "/products/list", method = RequestMethod.GET)
public String processFindForm(UserQuery userQuery, BindingResult result, Model model, HttpServletRequest request) {
    List<Product> results = null;
    Boolean isSimpleTermQuery = userQuery.getQuery().matches("[a-zA-Z_0-9 ]*");
    if (StringUtils.isEmpty(userQuery.getQuery())) {
        return "redirect:/products/search";
    } else
        try {
            if (isSimpleTermQuery) {
                HighlightPage<Product> highlightedResults = productService.findByHighlightedNameCriteria(userQuery.getQuery());
                results = SolrUtils.highlightPagesToList(highlightedResults);
            } else {
                results = productService.getProductsWithUserQuery(userQuery.getQuery());
            }
        } catch (UncategorizedSolrException ex) {
            logger.info(MessageFormat.format("Bad Query: {0}", userQuery.getQuery()));
            result.rejectValue("query", "product.search.error", new Object[] { userQuery.getQuery() }, "not found");
            return PRODUCT_SEARCH_VIEW;
        }
    if (results.size() < 1) {
        result.rejectValue("query", "product.search.noresults", new Object[] { userQuery.getQuery() }, "not found");
        return PRODUCT_SEARCH_VIEW;
    }
    if (results.size() > 1) {
        PagedListHolder<Product> pagedListHolder = new PagedListHolder<Product>(results);
        pagedListHolder.setPageSize(PRODUCT_LIST_PAGE_SIZE);
        request.getSession().setAttribute(SESSION_ATTRIBUTE_PRODUCTLIST, pagedListHolder);
        return "redirect:/products/page/1";
    } else {
        Product product = results.iterator().next();
        return "redirect:/products/" + product.getId();
    }
}
Also used : UncategorizedSolrException(org.springframework.data.solr.UncategorizedSolrException) Product(com.nixmash.blog.solr.model.Product) PagedListHolder(org.springframework.beans.support.PagedListHolder) HighlightPage(org.springframework.data.solr.core.query.result.HighlightPage)

Example 3 with UncategorizedSolrException

use of org.springframework.data.solr.UncategorizedSolrException 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)

Aggregations

UncategorizedSolrException (org.springframework.data.solr.UncategorizedSolrException)3 PostQueryDTO (com.nixmash.blog.jpa.dto.PostQueryDTO)2 PostNotFoundException (com.nixmash.blog.jpa.exceptions.PostNotFoundException)1 JsonRequestMapping (com.nixmash.blog.mvc.annotations.JsonRequestMapping)1 PostDoc (com.nixmash.blog.solr.model.PostDoc)1 Product (com.nixmash.blog.solr.model.Product)1 Test (org.junit.Test)1 PagedListHolder (org.springframework.beans.support.PagedListHolder)1 HighlightPage (org.springframework.data.solr.core.query.result.HighlightPage)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1