lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jitender ahuja" <>
Subject customising reults.jsp to display results for a searcher calling IndexSearcher class??
Date Wed, 14 Apr 2004 05:15:33 GMT
      In lucene 1.2 demo, the results.jsp file has to be put in a container to run on a web
server. I am using Tomcat for the same, but the IndexSearcher has to be called by a seperate
class, i.e. SearchDB, that searches for the appropriate data fields of an XML database stored
in the Index directory. Now, this is causing problems as the index is not picked up by the
results.jsp that directly calls the IndexSearcher class, at line nos. 35/44. Can anyone tell
how to circumvent this issue by calling the SearchDB class instead, at line nos. 35/44 of

Also, the code picks up the desired term containing documents at the command line perfectly.

The code for the SearchDB file is also attached for understanding of the class functioning:

import java.util.*;

import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*;
import org.apache.lucene.queryParser.*;
import org.apache.lucene.queryParser.ParseException;

public class SearchDB {

  public static void main(String[] args) {

    // search for a single term only
    String searchStr = args[0];

  //search the database for a given search string and return the primary key(s)
  public static String[] searchDB(String searchStr)
    ArrayList results = new ArrayList();
    String arrType[]= new String[0];
    try {
      //search on index directory
      Searcher indexSrch = new IndexSearcher("C:\\Temp\\DBDEX_GT1111");
      Analyzer analyzer = new StandardAnalyzer();

      //create a query to search for the target string in the description field
      Query query = QueryParser.parse(searchStr, "OBJECT_XML", analyzer);

      Hits hits =;

      System.out.println(hits.length() + "total matching documents");

      for (int i = 0; i < hits.length(); i++) {

        // get the lucene document for each hit and then get field details
        Document doc = hits.doc(i);

        String id = doc.get("OBJECT_ID");


        String data = doc.get("OBJECT_XML");

        //we need only OBJECT_ID as it serves the purpose of id'ing the row to be returned
        System.out.println("\nResult "+i+"\nOBJECT_ID " + id);

        System.out.println("\nOBJECT_XML " + data);
        // no need to write sql code, to retrieve the contents of the text field, seperately
        // as the data is stored verbatim in the index

    catch (ParseException ex1) {
      return (String[]) results.toArray(new String[0]);
    catch (IOException ex) {
      return (String[]) results.toArray(new String[0]);

    return (String[]) results.toArray(new String[0]);


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message