1

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.

3
  • 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. Commented 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. Commented 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. Commented Oct 6, 2012 at 8:12

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.