----- Original Message ----- From: "Terence Lai" <[EMAIL PROTECTED]> To: "'Lucene Users List'" <[EMAIL PROTECTED]> Sent: Friday, May 14, 2004 2:12 PM Subject: Question on QueryParser.parse()
> I am trying to create a query object using the QueryParser for the search word "A+". However, it always returns a Null object back. My code is stated below: > > Query q = QueryParser.parse("A\+", "myIndex", new StandardAnalyzer()); > > I've also tried the following query strings, but none of them returns the query object back. > > myIndex: A\+ > myIndex: "A\+" > myIndex: "A+" > > Does anyone know the solution? StandardAnalyzer is what's stopping you. It will discard the letter "A" because of its StopFilter, and it will discard the "+" because it considers that character to be noise. You have a few choices: 1. Build the query manually. Query q = new TermQuery(new Term("myIndex", "A+"); This will only work if you actually indexed the term "A+" (i.e. if you did not use StandardAnalyzer when you indexed the docs). 2. Use a different analyzer. In this case, the only stock analyzer that will work is the WhitespaceAnalyzer. Bear in mind that if you switch analyzers you will have to reindex your content with your new choice of analyzer. If you need to search unusual terms like this, you might want to make your own Analyzer out of a WhitespaceTokenizer and a LowerCaseFilter, as follows: class LcWsAnalyzer extends Analyzer { public TokenStream tokenStream(String fieldName, Reader reader) { return new LowerCaseFilter(new WhitespaceTokenizer(reader)); } } When the above Analyzer is used, QueryParser.parse() returns myIndex:a+ as the term it will search for. > By the way, I am using Lucence 1.4 RC3. > > Thanks, > Terence > > > > > > > ---------------------------------------------------------- > Get your free email account from http://www.trekspace.com > Your Internet Virtual Desktop! > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]