I add a field to a document using:

doc.add(Field.Text("path", "d=100&a=102"));


When I search for the document using "d=100&a=102" as the query using:

    public static void main(String[] args){

        String indexDir = args[0];
        String queryStr = args[1];

        System.out.println("indexDir = " + indexDir);
        System.out.println("query    = " + queryStr);

        IndexSearcher searcher = new IndexSearcher(indexDir);
        
        Term term = new Term("path", queryStr);
        TermQuery query = new TermQuery(term);
        
        Hits hits = searcher.search(query);
        
        
        if (hits.length() == 0){
            System.out.println("length = 0");
        }
        
    }


it returns nothing. If I use "SearchFiles" (the search example that
comes with the Lucene dist) I get:

Query: d=100&a=102
Exception in thread "main" org.apache.lucene.queryParser.TokenMgrError: Lexical error 
at line 1, column 7.  Encountered: "a" (97), after : "&"
        at org.apache.lucene.queryParser.QueryParserTokenManager.getNextToken(Unknown 
Source)
        at org.apache.lucene.queryParser.QueryParser.jj_scan_token(Unknown Source)
        at org.apache.lucene.queryParser.QueryParser.jj_3_1(Unknown Source)
        at org.apache.lucene.queryParser.QueryParser.jj_2_1(Unknown Source)
        at org.apache.lucene.queryParser.QueryParser.Clause(Unknown Source)
        at org.apache.lucene.queryParser.QueryParser.Query(Unknown Source)
        at org.apache.lucene.queryParser.QueryParser.parse(Unknown Source)
        at org.apache.lucene.queryParser.QueryParser.parse(Unknown Source)
        at Lucsearch.main(Lucsearch.java:36)


How do I format the query in order to keep the parser satisfied? I
have tried the usual \-escaping of difficult characters, but that
doesn't work either. Is there a way to set which characters are
allowed in a query or something similar?

/Stefan Bergstrand

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

Reply via email to