How to display the result of Lucene indexsearcher pagewise in JSP -


i have built web interface in jsp user can type query , interface records user's query along present location , these passed lucene index searcher searchdb parameters. want display result of search pagewise in same jsp. code of jsp , lucene index searcher, have written taking of other posts, follows:

result.jsp

 <%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8" import="java.util.*,java.io.*,parser.searchdb,org.apache.lucene.analysis.*" %>  <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">   <%! string myquery; string city; string latitude; string longitude; %>   <%       myquery=request.getparameter("myquery");       city=request.getparameter("city");       latitude=request.getparameter("latitude");       longitude=request.getparameter("longitude");       cookie cookies [] = request.getcookies();       cookie mycity=null;       cookie mylat=null;       cookie mylong=null;       if(city!=null)        {          mycity=new cookie("city",city);          mycity.setmaxage(365*24*60*60);          response.addcookie(mycity);          mylat=new cookie("latitude",latitude);          mylat.setmaxage(365*24*60*60);          response.addcookie(mylat);          mylong=new cookie("longitude",longitude);          mylong.setmaxage(365*24*60*60);          response.addcookie(mylong);        }     else        {           (int = 0; < cookies.length; i++)           {                   if (cookies[i].getname().equals("city"))                   {                     mycity=cookies[i];                     city=mycity.getvalue();                   }               else                 if(cookies[i].getname().equals("latitude"))                  {                       mylat=cookies[i];                       latitude=mylat.getvalue();                  }                 else                   if(cookies[i].getname().equals("longitude"))                    {                        mylong=cookies[i];                        longitude=mylong.getvalue();                    }              }     }   searchdb s = new searchdb();   system.out.println("query="+myquery+" , city="+city);   s.searchdb(myquery, city); %>   <form name="frm" method="post" action="result.jsp">  <table width="100%" border="0" cellspacing="0" cellpadding="0">    <tr>    <td width="22%">&nbsp;</td>    <td width="78%">&nbsp;</td>    </tr>    <tr>    <td>&nbsp; </td>    <td><input type="text" name="myquery" placeholder="type here"></td>    </tr>    <tr>    <td>&nbsp;</td>    <td><input type="submit" name="submit" value="submit"></td>    </tr>    <tr>    <td>&nbsp;</td>    <td>&nbsp;</td>    </tr>    </table>    </form>    <html>    <head>    <meta http-equiv="content-type" content="text/html; charset=utf-8">    <title>insert title here</title>    </head>    <body>    <p>query phrase : <%=myquery%></p>    <p>user's city : <%=city%></p>    <p>user's latitude : <%=latitude%></p>    <p>user's longitude : <%=longitude%></p>    </body>   </html> 

searchdb.java

package parser;   public class searchdb {  public void searchdb(string myquery, string mycity) throws exception {     system.out.println("searching in database ...");     standardanalyzer analyzer = new standardanalyzer(version.lucene_current);      queryparser cityqp = new queryparser(version.lucene_current, "city", analyzer);     query cityquery = cityqp.parse(mycity);      queryparser titleqp = new queryparser(version.lucene_current, "title", analyzer);     query titlequery = titleqp.parse(myquery);      booleanquery finalquery = new booleanquery();     finalquery.add(cityquery, occur.must); must occur.     finalquery.add(titlequery, occur.must);       system.out.println("final query="+finalquery.tostring());      directory dir=fsdirectory.open(new file(path of index directory"));     indexsearcher searcher = new indexsearcher(dir, true);     topdocs hits = searcher.search(finalquery, 20);      system.out.println("number of hits="+hits.totalhits);     for(scoredoc match : hits.scoredocs)     {         system.out.println(searcher.doc(match.doc).get("title")+" score="+match.score);        system.out.println("_______");     }     searcher.close();     dir.close(); } 

}

i new both lucene , jsp. don't have idea changes should done above java , jsp code results displayed pagwise. appreciated. thank you.

you can pass in last scoredoc obtained indexsearcher.searchafter, next set of documents. so, value of match after youu've completed loop should scoredoc pass searchafter.

such as:

topdocs hits = searcher.search(finalquery, 20); system.out.println("number of hits="+hits.totalhits);  while(not done paging...) {     scoredoc last;     for(scoredoc match : hits.scoredocs)     {          system.out.println(searcher.doc(match.doc).get("title")+" score="+match.score);         system.out.println("_______");         last = match;     }     hits = searcher.searchafter(last, finalquery, 20); } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -