7

More Like This with SolrJ Example

 3 years ago
source link: https://nixmash.com/java/more-like-this-with-solrj-example/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

More Like This with SolrJ Example

At the bottom of each NixMash post you'll see a Solr More Like This List for related posts. Here are the related items for post titled "Returning a Java Object List in RabbitMQ RPC."

mlt0307a.png

I covered creating a More Like This list with Spring Solr in this NixMash post. In that post I also covered the Solr configuration issues to support the More Like This Solr Handler in the Solr Administration Dashboard. Here we'll focus on how to return a More Like This list in Apache SolrJ.

The Code

Without delay here's a @Test Method demonstrating More Like This with SolrJ.

(1) We configure our MoreLikeThis Query. Notice the setShowDebugInfo(true) Query Property. Enabling Debug Info is of course very helpful to learn more about the results of your query when in development.

(2) We're not working directly with our response = client.query(query) as we would normally. That returns only our focal SolrDocument, or document with id:598. Instead we will be working with a SolrDocumentList.

(3) In our application we want to return Post objects so we populate our List<Post> from SolrDocument fields.

(4) For completeness we perform a simple test to confirm that our Post list has 4 items.

mlt0307c.png

Now take a minute to view the More Like This posts shown below for this post about More Like This!

CategoriesJavaTagsJava, Solr


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK