Search in sources :

Example 1 with PostDoc

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;
}
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 PostDoc

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";
    }
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDoc(com.nixmash.blog.solr.model.PostDoc)

Example 3 with PostDoc

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("");
}
Also used : MessageFormat(java.text.MessageFormat) PostDoc(com.nixmash.blog.solr.model.PostDoc)

Example 4 with PostDoc

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();
}
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) Post(com.nixmash.blog.jpa.model.Post) SimpleStringCriteria(org.springframework.data.solr.core.query.SimpleStringCriteria) PostDoc(com.nixmash.blog.solr.model.PostDoc) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PostDoc

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);
}
Also used : PostQueryDTO(com.nixmash.blog.jpa.dto.PostQueryDTO) PostDoc(com.nixmash.blog.solr.model.PostDoc) Test(org.junit.Test)

Aggregations

PostDoc (com.nixmash.blog.solr.model.PostDoc)26 Test (org.junit.Test)13 Post (com.nixmash.blog.jpa.model.Post)8 Query (org.springframework.data.solr.core.query.Query)8 SimpleQuery (org.springframework.data.solr.core.query.SimpleQuery)8 IPostDoc (com.nixmash.blog.solr.model.IPostDoc)5 PostQueryDTO (com.nixmash.blog.jpa.dto.PostQueryDTO)4 ArrayList (java.util.ArrayList)3 Criteria (org.springframework.data.solr.core.query.Criteria)3 SimpleStringCriteria (org.springframework.data.solr.core.query.SimpleStringCriteria)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PostNotFoundException (com.nixmash.blog.jpa.exceptions.PostNotFoundException)1 JsonRequestMapping (com.nixmash.blog.mvc.annotations.JsonRequestMapping)1 GeoLocationException (com.nixmash.blog.solr.exceptions.GeoLocationException)1 Product (com.nixmash.blog.solr.model.Product)1 MessageFormat (java.text.MessageFormat)1 Ignore (org.junit.Ignore)1 PageRequest (org.springframework.data.domain.PageRequest)1 UncategorizedSolrException (org.springframework.data.solr.UncategorizedSolrException)1 FacetFieldEntry (org.springframework.data.solr.core.query.result.FacetFieldEntry)1