use of com.nixmash.blog.solr.model.PostDoc 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 com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.
the class AdminPostsController method updatePost.
@RequestMapping(value = "/update", method = POST)
public String updatePost(@Valid PostDTO postDTO, BindingResult result, Model model, RedirectAttributes attributes, HttpServletRequest request) throws PostNotFoundException {
if (result.hasErrors()) {
model.addAttribute("postDTO", postDTO);
model.addAllAttributes(getPostLinkAttributes(request, postDTO.getPostType()));
return ADMIN_POSTLINK_UPDATE_VIEW;
} else {
postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));
Post post = postService.update(postDTO);
PostDoc postDoc = postDocService.getPostDocByPostId(post.getPostId());
boolean postIsIndexed = postDoc != null;
if (post.getIsPublished()) {
post.setPostMeta(jsoupService.updatePostMeta(postDTO));
if (applicationSettings.getSolrEnabled()) {
if (postIsIndexed)
postDocService.updatePostDocument(post);
else
postDocService.addToIndex(post);
}
fmService.createPostAtoZs();
} else {
// remove postDocument from Solr Index if previously marked "Published", now marked "Draft"
if (postIsIndexed)
if (applicationSettings.getSolrEnabled()) {
postDocService.removeFromIndex(postDoc);
}
}
webUI.addFeedbackMessage(attributes, FEEDBACK_POST_UPDATED);
return "redirect:/admin/posts";
}
}
use of com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.
the class SolrUI method printPosts.
private void printPosts(Iterable<? extends PostDoc> posts) {
int i = 0;
System.out.println("More Like This Posts -------------------------- */\n");
for (PostDoc postDoc : posts) {
MessageFormat mf = new MessageFormat("{0} | Post: {1}");
Object[] items = { postDoc.getPostId(), postDoc.getPostTitle() };
System.out.println(mf.format(items));
i++;
}
System.out.println("");
}
use of com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.
the class SolrPostReindexTests method cleanAndReindexPostDocuments_AddIndividually.
@Test
@Ignore(value = "It works, no need to wait for it to run each time")
public void cleanAndReindexPostDocuments_AddIndividually() throws Exception {
posts = postService.getAllPublishedPosts();
postCount = posts.size();
for (Post post : posts) {
postDocService.addToIndex(post);
}
List<PostDoc> postDocs = postDocService.getAllPostDocuments();
assertEquals(postDocs.size(), postCount);
postDocs = postDocService.getPostsWithUserQuery("bootstrap");
assertEquals(BOOTSTRAP_POST_COUNT, postDocs.size());
Query query = new SimpleQuery(new SimpleStringCriteria("doctype:post"));
solrOperations.delete(query);
solrOperations.commit();
}
use of com.nixmash.blog.solr.model.PostDoc 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);
}
Aggregations