Search in sources :

Example 11 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 12 with PostDoc

use of com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.

the class CustomPostDocRepositoryImpl method findPostsBySimpleQuery.

@Override
public List<PostDoc> findPostsBySimpleQuery(String userQuery) {
    Query query = new SimpleQuery(userQuery);
    query.addFilterQuery(new SimpleQuery(new Criteria(IPostDoc.DOCTYPE).is(SolrDocType.POST)));
    query.setRows(1000);
    Page<PostDoc> results = solrTemplate.queryForPage(query, PostDoc.class);
    return results.getContent();
}
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) Criteria(org.springframework.data.solr.core.query.Criteria) IPostDoc(com.nixmash.blog.solr.model.IPostDoc) PostDoc(com.nixmash.blog.solr.model.PostDoc)

Example 13 with PostDoc

use of com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.

the class AdminSolrPostsControllerTests method updatingPostUpdatesItsSolrPostDocument.

@Test
public void updatingPostUpdatesItsSolrPostDocument() throws Exception {
    List<PostDoc> postDocs = postDocService.getAllPostDocuments();
    int postDocCount = postDocs.size();
    Post post = postService.getPostById(1L);
    String originalTitle = post.getPostTitle();
    String newTitle = "updatingPostUpdatesItsSolrPostDocument";
    mvc.perform(post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", newTitle).param("twitterCardType", TWITTER_SUMMARY).param("tags", "removingTag1").with(csrf()));
    // size of PostDocuments in Solr Index Unchanged
    assertEquals(postDocCount, postDocService.getAllPostDocuments().size());
    Post verifyPost = postService.getPostById(1L);
    assertEquals(verifyPost.getPostTitle(), newTitle);
    List<PostDoc> verifyPostDocs = postDocService.getPostsWithUserQuery(newTitle);
    assertEquals(verifyPostDocs.size(), 1);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDoc(com.nixmash.blog.solr.model.PostDoc) Test(org.junit.Test)

Example 14 with PostDoc

use of com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.

the class PostDocServiceImpl method getMoreLikeThisPostsFromPostDocs.

@Transactional(readOnly = true)
@Override
public List<Post> getMoreLikeThisPostsFromPostDocs(List<PostDoc> postDocs) {
    List<Post> posts = new ArrayList<>();
    String result = StringUtils.EMPTY;
    for (int i = 0; i < applicationSettings.getMoreLikeThisNum(); i++) {
        try {
            PostDoc postDoc = postDocs.get(i);
            posts.add(postService.getPostById(Long.parseLong(postDoc.getPostId())));
        } catch (PostNotFoundException | IndexOutOfBoundsException e) {
            if (e.getClass().equals(PostNotFoundException.class))
                logger.info("MoreLikeThis PostDoc {} to Post with title \"{}\" NOT FOUND", postDocs.get(i).getPostId(), postDocs.get(i).getPostTitle());
            else {
                logger.info("EXCEPTION: AppSetting.MoreLikeThisNum > post count");
                return null;
            }
        }
    }
    return posts;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostNotFoundException(com.nixmash.blog.jpa.exceptions.PostNotFoundException) ArrayList(java.util.ArrayList) PostDoc(com.nixmash.blog.solr.model.PostDoc) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with PostDoc

use of com.nixmash.blog.solr.model.PostDoc in project nixmash-blog by mintster.

the class SolrPostTests method addPostWithAddToIndexService.

@Test
public void addPostWithAddToIndexService() throws Exception {
    // using postId 10 which is "Solr Rama"
    Post post = postService.getPostById(10L);
    postDocService.addToIndex(post);
    PostDoc found = customPostDocRepository.findOne("10");
    assertEquals(found.getPostName(), "solr-rama");
}
Also used : Post(com.nixmash.blog.jpa.model.Post) 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