简体   繁体   English

在AWS Cloudsearch上获取上一个光标

[英]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. 我喜欢CloudSearch,因为它超级快并且可以减轻RDS的负担。 We've got about 30k documents so in order for me to paginate the results, I'll need to use the cursors. 我们大约有3万个文档,因此为了使结果分页,我需要使用游标。 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} {上一页} {...} {3} {4} {5} {6} {7} {...} {下一页}

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. 我这样做的方法是将当前光标和下一个光标传递给AJAX脚本以加载新结果。 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. 我的光标将返回0个结果。 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 ???? 第2页有光标??? Page 3 have the cursor ???? 第3页有光标??? Page 4 (the current page) have the cursor VWXabc123 Page 5 (the next page) have the cursor VUTdef456 第4页(当前页)具有光标VWXabc123第5页(下一页)具有光标VUTdef456

So the question is, how do I get previous cursors before page 4? 因此,问题是,如何在第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. 但是CloudSearch在整个集合中将您限制为10,000个结果。

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. 如果只有一台应用服务器与他们对话并跟踪客户端会话,则可以将它们存储在您的应用服务器上,从而将prev / next和/或page =#与它们关联。

Our app has multiple EC2 servers so we can't track there. 我们的应用程序有多个EC2服务器,因此我们无法在其中跟踪。 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. 我们将在客户的Angular代码中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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