Grokbase Groups Lucene dev April 2004
FAQ
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, field name, 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;
}
}
}

Search Discussions

  • Jitender ahuja at Apr 17, 2004 at 8:27 am
    // 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;
    }
    }
    }
  • Erik Hatcher at Apr 17, 2004 at 10:38 am
    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: lucene-dev-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
  • Terry Steichen at Apr 17, 2004 at 10:43 am
    I suspect he's confused that the "query expression" is a string, whereas a
    Query is a special kind of object.

    Regards,

    Terry

    ----- Original Message -----
    From: "Erik Hatcher" <erik@ehatchersolutions.com>
    To: "Lucene Developers List" <lucene-dev@jakarta.apache.org>
    Sent: Saturday, April 17, 2004 6:38 AM
    Subject: Re: Conversion of Query object to a String object in 1.2 ver.

    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: lucene-dev-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-dev-help@jakarta.apache.org

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
  • Jitender ahuja at Apr 17, 2004 at 11:02 am
    Hi Erik,

    Thanks for your detailed response. It works now in a jsp page.

    Regards,
    Jitender

    ----- Original Message -----
    From: "Erik Hatcher" <erik@ehatchersolutions.com>
    To: "Lucene Developers List" <lucene-dev@jakarta.apache.org>
    Sent: Saturday, April 17, 2004 4:08 PM
    Subject: Re: Conversion of Query object to a String object in 1.2 ver.

    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: lucene-dev-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-dev-help@jakarta.apache.org

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-dev-help@jakarta.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categorieslucene
postedApr 17, '04 at 8:21a
activeApr 17, '04 at 11:02a
posts5
users3
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase