What is even more confusing is why you would take a perfectly good Query object, convert it to a String, and then parse it back to get a Query object. You've already got a Query, just hand it to the search method and forget about QueryParser altogether in the code you have.

The whole point of QueryParser it to take a string expression and turn it into a Query - which you've already got.

Going back and forth from Query.toString and QueryParser is going to be problematic in most cases due to analysis. It can be a lossy conversion from String->QueryParser->toString

Erik

On Apr 17, 2004, at 4:23 AM, jitender ahuja wrote:


// kindly take my earlier mail as invalid as the Query object is shown in the attached code without conversion


Hi all,
I intend to convert Query object to a String object for the purpose of passing it to the parse method of the QueryParser class i.e.,
Query query = QueryParser.parse(searchStr.toString(), field name , analyzer); // searchStr is the query string passed
but, it retrieves nothing as output , whatsoever.


I am quite confused as how to usefully convert a Query object to a String.

Even the Hits object, i.e. , hits = indexSrch.search(query), returned by a searcher object of my own class Searcher yields nothing.

Regards,
Jitender

////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ///////////////////////////
My searcher class is stated below :



public class Searcher {


public static void main(String[] args) {

}

public static Hits searchDB(Query searchStr) // it has to be a query type parameter as the
//results.jsp has stmt. : Hits hits = searcher.searchDB(query)
{
ArrayList results = new ArrayList();
Hits hits = null;


try {
//search on index directory
Searcher indexSrch = new IndexSearcher("C:\\Temp\\DBDEX_GT"); // index already delivers by a seperate code
Analyzer analyzer = new StandardAnalyzer();


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


hits = indexSrch.search(query); // returns nothing and no output is displayed for the next two print stmts.
System.out.println(hits); // displays nothing
System.out.println(hits.length() + " total matching documents"); // displays nothing


    }
      catch (ParseException ex1) {
      ex1.printStackTrace();

    }
    catch (IOException ex) {
      ex.printStackTrace();

    }catch(Exception e){
    e.printStackTrace();
  }
     return hits;
  }
 }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to