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;
}
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();
}
}
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);
}
Aggregations