Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize solr similarity matching

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to achieve solr similar matching". In daily operation, I believe many people have doubts about how to achieve solr similar matching. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to achieve solr similar matching"! Next, please follow the editor to study!

Similar matching

When we use a web search, we will notice that each result contains a "similar page" link, and clicking on that link will issue another search request to find a document similar to the original result. Solr implements the same functionality using MoreLikeThisComponent (MLT) and MoreLikeThisHandler. As mentioned above, MLT is integrated with standard SolrRequestHandler; MoreLikeThisHandler is integrated with MLT and adds some other options, but it requires a single request to be issued. I'll focus on MLT because it's more likely to be used. Fortunately, you can query it without any settings, so you can start querying now.

MLT requires fields to be stored or used to retrieve word vectors, which store information in a document-centric way. MLT calculates the key words in the document from the contents of the document, and then uses the original query words and these new words to create a new query. Submitting a new query returns other query results. All of this can be done by retrieving the word vector: simply add the termVectors= "true" to the declaration in schema.xml.

MoreLikeThisComponent parameters:

Parameters.

Description

Value range

Mlt

Turns the Boolean value of MoreLikeThisComponent on / off when querying.

True | false

Mlt.count

Optional. The number of similar documents to retrieve for each result.

> 0

Mlt.fl

The field used to create the MLT query.

Any field that is stored or contains a retrieval word vector.

Mlt.maxqt

Optional. The maximum number of query words. Because long documents can have many key words, the MLT query can be large, resulting in slow or scary TooManyClausesException, which retains only the key words.

> 0

To use matching similarity, first configure MoreLikeThisHandler in solrconfig.xml

And then I can ask.

Http://localhost:8080/skyCore/mlt?q=id%3A6F398CCD-2DE0-D3B1-9DD6-D4E532FFC531&mlt.true&mlt.fl=content&wt=xml&indent=true

The meaning of the above request is to find the document whose id is 6F398CCD-2DE0-D3B1-9DD6-D4E532FFC531, and then return other document similar to this document in the name field. It should be noted that the termVector=true of field in mlt.fl is effective.

When using SolrJ, you can also add parameters.

SolrQuery query = new SolrQuery ()

Query.set ("qt", "/ mlt")

Query.set ("mlt.fl", "content")

Query.set ("fl", "id,")

Query.set ("Q", "id: 6F398CCD-2DE0-D3B1-9DD6-D4E532FFC531")

Query.setStart (0)

Query.setRows (5)

QueryResponse rsp = server.query (query)

SolrDocumentList list = rsp.getResults ()

At this point, the study of "how to achieve solr similar matching" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report