Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize solr similarity matching

Shulou Source: shulou.com Published: 2022-05-31 17:25:35 10月03日 Update

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!

Tags: Queries similar documents words searches parameters vectors fields results learning keys more links help search photogenic original scary practical big Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information Redmi Apple macOS