For this assignment, you will add a cache of query results to your search engine. This speeds up the execution of queries by using the cached results of previous queries. You can also optionally integrate your search engine into your web browser.
Build a class called StringToStringMap that uses a
hash table to map one string to another. (The intended goal for this
hash map is for the key string to be a query, and the value string to
be the search results.) You should not use any of the built-in
Set or Map classes for this
assignment. Write a main method to test your code appropriately.
Modify ProcessQueries from your previous assignment so
that instead of just printing query results to the screen, it creates
a String out them and adds them to the StringToStringMap
associated with a particular query. When the user types in a query,
you will first check the cache to see if you have processed a similar
request in the past.
Enter a query or -1 to quit. Search for: computer query not found in cache Time: xxx seconds Relevant pages: /Accounts/courses/cs127/dmusican/dept-web-site/GuidetoMath.html (priority = x) /Accounts/courses/cs127/dmusican/dept-web-site/summaries.html (priority = y) /Accounts/courses/cs127/dmusican/dept-web-site/contact.html (priority = z) Search for: computer science query not found in cache Time: xxx seconds Relevant pages: /Accounts/courses/cs127/dmusican/dept-web-site/GuidetoMath.html (priority = a) /Accounts/courses/cs127/dmusican/dept-web-site/summaries.html (priority = b) /Accounts/courses/cs127/dmusican/dept-web-site/contact.html (priority = c) Search for: science query not found in cache Time: xxx seconds Relevant pages: /Accounts/courses/cs127/dmusican/dept-web-site/GuidetoMath.html (priority = m) /Accounts/courses/cs127/dmusican/dept-web-site/summaries.html (priority = n) Search for: computer query found in cache Time: xxx seconds Relevant pages: /Accounts/courses/cs127/dmusican/dept-web-site/GuidetoMath.html (priority = x) /Accounts/courses/cs127/dmusican/dept-web-site/summaries.html (priority = y) /Accounts/courses/cs127/dmusican/dept-web-site/contact.html (priority = z) Search for: -1
Notice that the first time the user asks about "computer" we cannot find anything in the cache. But when the user asks about "computer" again later, we can grab the stored information and just output it again. To see the difference in running time, use the method System.curentTimeMillis() to get the time in milliseconds before and after determining the results for your query. You should see a considerable difference in running time depending on whether or not the results are cached.
Completion of the caching described above, if done correctly, is sufficient for full credit on this assignment. However, you may find the assignment much more exciting if you can integrate the results with your Minibrowse code. Here is how to do so:
Modify your Minibrowse code so that the URL list and the ignore list are input as command-line arguments. This information should then be passed off to ProcessQueries as necessary.
Add a text box to Minibrowse where the user will type in a query, and a "Search" button to trigger the search.
Modify ProcessQueries so that it works by calling a method which determines the search results, and returns them as a String instead of printing the results to the terminal window.
In Minibrowse, run your method from ProcessQueries to generate search results.
In Minibrowse, instead of using the setPage method of JEditorPane for showing a web page, use the setText method which takes an HTML string as a parameter. Your string will thus have to be in HTML format.
Have fun, and good luck!
Many thanks to Tia Newhall and Lisa Meeden at Swarthmore College.