I am developing a search engine in java.It works fine but all results are displayed in one page.How can I display results in separate pages like google. If I have 100 results then the results will be displayed in say 10 pages 10 results each. I am not using MySQL. My data is stored in files.
-
Just curious as to why you choose to store your data in files. If you don't want a separate server process for your database, you could consider using a self-contained, serverless database like SQLite.Mr. 14– Mr. 142012-10-06 07:41:45 +00:00Commented Oct 6, 2012 at 7:41
-
I don't need a database,there is no concurrency problem or any other problems, what I need is to read data from file no writing is needed.Accessing directly from file is faster for my system.alienCoder– alienCoder2012-10-06 07:53:39 +00:00Commented Oct 6, 2012 at 7:53
-
Parse the file and put the items in an array/list. Use the solution proposed by enhzflep to locate the range of items to be displayed on each page.Mr. 14– Mr. 142012-10-06 08:12:09 +00:00Commented Oct 6, 2012 at 8:12
Add a comment
|
1 Answer
So you need to take the specified page number and use that to work out which result to display first in that page.
say your URL looked like this
www.yoursite.com?search=JSP&page=3
Then, you'd extract the search term and find the results. You'd also get the requested page and use it.
firstResultNum = page * resultsPerPage
for (i=firstResultNum; i<firstResultNum+resultsPerPage; i++)
{
displayCurSearchResult(i);
}