简体   繁体   English

如何启用“更多”搜索结果?

[英]How to enable “more” search results?

I'm a C# developer for Windows and I know NOT THAT MUCH about web programming. 我是一个用于Windows的C#开发人员,我知道这么多关于Web编程。 I have developed a special search engine in Java. 我用Java开发了一个特殊的搜索引擎。 I want to create a php interface for it. 我想为其创建一个php接口。 For now, I managed to connect php and Java via a Web Service. 现在,我设法通过Web服务连接php和Java。 I watched some tutorials for creating a search engine and I have some slight idea of what should I do but I don't know exactly what to do with some problems. 我看了一些有关创建搜索引擎的教程,并且对应该怎么做略有想法,但是我不知道该如何处理某些问题。 Here's the scenario I want to implement: 这是我要实现的方案:

An Index page with a search box, user types the search query in that page, some results shows, if the user scrolls down, more results shows (like Facebook). 带有搜索框的索引页面,用户在该页面中键入搜索查询,显示一些结果,如果用户向下滚动,则显示更多结果(例如Facebook)。 When user clicks on a result item's link, the browser then opens another page that shows the result (also in my app). 当用户单击结果项的链接时,浏览器将打开另一个显示结果的页面(也在我的应用程序中)。

Now what I know is that the index page should be a HTML file with a Get method to a PHP file. 现在我知道的是,索引页应该是一个HTML文件,并带有PHP文件的Get方法。 What I don't know is How to enable "more" results? 我不知道如何启用“更多”结果? For this, my php should send an array containing the URL of the previous results to my Java service, get the results, add them to the array and wait. 为此,我的php应该将包含先前结果的URL的数组发送到我的Java服务,获取结果,将它们添加到该数组中,然后等待。 The next time it should use this array. 下次应使用此数组。

Please let me know what code structure should I use for my app. 请让我知道我应该为我的应用程序使用什么代码结构。

Thanks in advance. 提前致谢。

Edit: Requested code samples in java server: 编辑:在Java服务器中请求的代码示例:

public String processQuery(String query, List<String> previousURLs);

this will be called for the first time like this: 这将是第一次这样调用:

processQuery("test", null);

suppose it has returned 2 results with urls: 假设它返回了2个带有url的结果:

http://www.bing.com
http://stackoverflow.com

these will be stored in an array and the second time: 这些将存储在数组中,第二次存储:

processQuery("test", previous);

this will return new results which will be added at the end of the page. 这将返回新结果,该结果将添加到页面末尾。

You need to use AJAX (Asynchronous JavaScript and XML) requests. 您需要使用AJAX(异步JavaScript和XML)请求。 Essentially as a user scrolls down the page this triggers a request to get more results. 本质上,当用户向下滚动页面时,这会触发请求以获取更多结果。 You'd probably do something like cache the last result id to know from where to get the next batch of results. 您可能会执行类似缓存最后一个结果ID的操作,以了解从何处获取下一批结果。 You'll need to brush up your javascript and possibly jQuery in order to figure out how to implement all this - ie trigger the request, handle the response and append new elements to the DOM. 您将需要重新整理javascript以及可能的jQuery,以弄清楚如何实现所有这些功能-即触发请求,处理响应并将新元素添加到DOM。

An example website that does this is Duck Duck Go . 一个实现此目的的示例网站是Duck Duck Go Their search results page dynamically appends new results as you scroll. 他们的搜索结果页面在您滚动时会动态添加新结果。 Make sure you have Firefox + Firebug to inspect the page, the network requests that get made and to step through (debug) the running javascript. 确保您有Firefox + Firebug来检查页面,发出的网络请求以及逐步(调试)正在运行的javascript。

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

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