Solr grinding cursor paging

Author: Fighting nation is doing

Please indicate the address for reprint: http://www.cnblogs.com/prayers/p/8986498.html

  

Normal paging

  When deep paging is required, such as querying the 10,000th page of data and displaying 10 entries per page, it means that the data of the first 10,000 x 10 pages needs to be extracted, and the 100,000 pieces of data are cached in memory, and then sorted in memory. Finally, the last 10 items are returned, that is, the 100,000th page of data that the user wants.

  shortcoming:

  1. First, 100,000 pieces of data need to be cached in memory, which takes up a lot of memory

  2, and sorting 100,000 pieces of data in memory is also very CPU-intensive

  Therefore, the normal paging method is more suitable for returning TOPN data. The more you turn the page, the worse the paging query performance is, even if you enable resultQueryCache

Cursor pagination

  The cursor in Solr is a logical concept, it does not store any information on the server, but returns a "Mark" mark value of the starting position of the next page data to the user, which indicates that the starting position of the current paging is in the query matching The absolute index position of the entire indexed result set of .

  To use a cursor in Solr, you need to specify a cursorMark parameter such as: cursorMark=*, you can understand that it is similar to start=0. At this time, Solr will not only return a TopN result set, but also return a nextCursorMark value. nextCursorMark indicates the starting position of the cursor's next traversal, that is, the next page will be returned from the nextCursorMark position. The nextCursorMark value is the encoded value of the data index position in the query matching result set. Each paging query needs to bring the cursorMark parameter, that is, the cursorMark=nextCursorMark value (except the first page). You can repeat this process until the nextCursorMark=cursorMark returned by Solr , then it means that there is no next page at this time

  Note :

    1. The cursorMark and start parameters are mutually exclusive. You cannot specify these two parameters at the same time, or you can specify these two parameters at the same time, but the start parameter must be equal to zero at this time.

    2. The sort statement must contain a unique primary key field. If id is your primary key field, the sort parameter can be set like this: sort=idasc,name asc. But you can't set sort=name desc

    Because the cursor mark is calculated based on the sorting value of each indexed document in the result set, which means that if the sorting value of two documents is the same, then the cursor value generated by them is also the same, which is the requirement that the sort statement must contain the primary key. reason

  The use case is as follows: the first paging must use cursorMark=*

http://localhost:8080/solr/b2b/select?q=cmmdtyName:手机&sort=id asc&fl=id,cmmdtyCode&wt=json&indent=true&cursorMark=*&rows=1

  The returned result set is as follows: 

{
responseHeader: {
status: 0,
QTime: 2
},
response: {
  numFound: 484 ,
  start: 0,
  docs: [
  {
    id: "P2_000000010207451749_0070173948",
    cmmdtyCode: "000000010207451749"
  }
  ]
},
  nextCursorMark: "AoE/AVAyXzAwMDAwMDAxMDIwNzQ1MTc0OV8wMDcwMTczOTQ4"
}

  Use case for querying the next page:  

http://localhost:8080/solr/b2b/select?q=cmmdtyName:手机&sort=id asc&fl=id,cmmdtyCode&wt=json&indent=true&cursorMark=AoE/AVAyXzAwMDAwMDAxMDIwNzQ1MTc0OV8wMDcwMTczOTQ4&rows=1

  The value of the cursorMark parameter here needs to be consistent with the value of the nextCursorMark attribute returned in the result set of the last paging query, until the returned nextCursorMark is equal to the current cursorMark, which means that the paging is complete.

  Since each request to the next page requires the nextCursonMark cursor returned by the previous page query, the query request for the specified page cannot be implemented, and it can only be turned down page by page, similar to a linked list

  

 

 

  

 

 

  

 

 

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325279113&siteId=291194637