简体   繁体   中英

Get previous cursor on AWS Cloudsearch

I'm doing a search for our website which is accessed by thousands of users. I love CloudSearch as it's super fast and relieves the burdens on my RDS. We've got about 30k documents so in order for me to paginate the results, I'll need to use the cursors. The documents are constantly being updated (added, modified or removed). This issue I'm having now is to get the previous cursor.

My ideal situation would be

{Prev} {...} {3} {4} {5} {6} {7} {...} {Next}

But I noticed that this is very difficult to do because I can't get all cursors everytime a query is being done. So I'm thinking of just doing

{Prev} {Next}

How I'm doing this is by passing the current cursor & the next cursor to an AJAX script to load new results. This works perfectly when a user is just moving forward and getting the next page. It breaks when the user is going back and retrieving the previous page. They can go back one page, to the current (previous) cursor, but they can't go back more than 1 page. Which is ridiculous in view of the users.

I've tried storing the cursors but this will break again if new documents comes in or older documents are removed. My cursor will return 0 results. If I were to fetch new cursors, I'll only see the next one and not the previous one.

Example:

Page 2 have the cursor ???? Page 3 have the cursor ???? Page 4 (the current page) have the cursor VWXabc123 Page 5 (the next page) have the cursor VUTdef456

So the question is, how do I get previous cursors before page 4? I can't store the results or get it from a query which means I can't even do a simple "Prev" and "Next" button.

Thank you all so much for this!

You can use the 'start' and 'size' parameters instead of the 'cursor': this lets you random-access read into the results. But CloudSearch limits you to 10,000 results in the entire set.

To let the client do infinite 'back' with cursors, you'll need to track them. If you've only got one app server they talk to and track client sessions, you could store these on your app server, associating prev/next and/or page=# to those.

Our app has multiple EC2 servers so we can't track there. But we can have the client store a "stack" of cursors they've been on as they move through the pages each cursor provides. When they go back, pop the old cursor off the stack and go there. When they go forward, add the new cursor to the stack. We'll do this in our client's Angular code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM