You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Joe Tang <jo...@workmetro.com> on 2007/01/27 00:48:31 UTC

QueryParser Strips "++" out of my word "c++"

I am working  on lucene 2.0.0 trying to parse a query with my word "c++" as a
keywords but unfortunately it strips out my word as "c". 

How can I parse a query like "c++" and "c#"?

Here are the codes

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;

class QueryTest {
	public static void main (String [ ] args){
		
		String keywords = "java c++";
		QueryParser qp = new QueryParser("keywords", new StandardAnalyzer());
		try {

		     System.err.println("Query - "+qp.parse(keywords).toString());		

		}catch (ParseException pe){
			System.err.println("Error Caught: "+pe);
		}
	}
	
}
-- 
View this message in context: http://www.nabble.com/QueryParser-Strips-%22%2B%2B%22-out-of-my-word-%22c%2B%2B%22-tf3125890.html#a8660921
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.


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


Re: QueryParser Strips "++" out of my word "c++"

Posted by Mike Klaas <mi...@gmail.com>.
On 1/26/07, Joe Tang <jo...@workmetro.com> wrote:
>
> Thanks for you reply Doron. It works partly on me.
>
> How should I customize the Analyzer so as to have the functionality of
> StandardAnalyzer as well as not stripping out some of the charactors?

Joe,

See nutch's version of StandardAnalyzer: it adds a few rules to
special case C++ and C#.
(nutch-trunk/src/java/org/apache/nutch/analysis/NutchAnalysis.jj).
You may be able to pluck those rules and insert them into Lucene's
StandardAnalyzer (after recompiling with javaCC).

-Mike

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


Re: QueryParser Strips "++" out of my word "c++"

Posted by Joe Tang <jo...@workmetro.com>.
Thanks for you reply Doron. It works partly on me.

How should I customize the Analyzer so as to have the functionality of
StandardAnalyzer as well as not stripping out some of the charactors?

Regards,
Joe



Doron Cohen wrote:
> 
> Hi Joe,
> 
> It must be the standard analyzer's work - try like this:
>     new QueryParser("keywords", new WhitespaceAnalyzer())
> 
> Regards,
> Doron
> 
> Joe Tang <jo...@workmetro.com> wrote on 26/01/2007 15:48:31:
> 
>>
>> I am working  on lucene 2.0.0 trying to parse a query with my word "c++"
> as a
>> keywords but unfortunately it strips out my word as "c".
>>
>> How can I parse a query like "c++" and "c#"?
>>
>> Here are the codes
>>
>> import org.apache.lucene.analysis.standard.StandardAnalyzer;
>> import org.apache.lucene.queryParser.ParseException;
>> import org.apache.lucene.queryParser.QueryParser;
>> import org.apache.lucene.search.Query;
>>
>> class QueryTest {
>>    public static void main (String [ ] args){
>>
>>       String keywords = "java c++";
>>       QueryParser qp = new QueryParser("keywords", new
> StandardAnalyzer());
>>       try {
>>
>>            System.err.println("Query - "+qp.parse(keywords).toString());
> 
>>
>>       }catch (ParseException pe){
>>          System.err.println("Error Caught: "+pe);
>>       }
>>    }
>>
>> }
>> --
>> View this message in context: http://www.nabble.com/QueryParser-
>> Strips-%22%2B%2B%22-out-of-my-word-%22c%2B%2B%22-tf3125890.html#a8660921
>> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-dev-help@lucene.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/QueryParser-Strips-%22%2B%2B%22-out-of-my-word-%22c%2B%2B%22-tf3125890.html#a8661841
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.


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


Re: QueryParser Strips "++" out of my word "c++"

Posted by Doron Cohen <DO...@il.ibm.com>.
Hi Joe,

It must be the standard analyzer's work - try like this:
    new QueryParser("keywords", new WhitespaceAnalyzer())

Regards,
Doron

Joe Tang <jo...@workmetro.com> wrote on 26/01/2007 15:48:31:

>
> I am working  on lucene 2.0.0 trying to parse a query with my word "c++"
as a
> keywords but unfortunately it strips out my word as "c".
>
> How can I parse a query like "c++" and "c#"?
>
> Here are the codes
>
> import org.apache.lucene.analysis.standard.StandardAnalyzer;
> import org.apache.lucene.queryParser.ParseException;
> import org.apache.lucene.queryParser.QueryParser;
> import org.apache.lucene.search.Query;
>
> class QueryTest {
>    public static void main (String [ ] args){
>
>       String keywords = "java c++";
>       QueryParser qp = new QueryParser("keywords", new
StandardAnalyzer());
>       try {
>
>            System.err.println("Query - "+qp.parse(keywords).toString());

>
>       }catch (ParseException pe){
>          System.err.println("Error Caught: "+pe);
>       }
>    }
>
> }
> --
> View this message in context: http://www.nabble.com/QueryParser-
> Strips-%22%2B%2B%22-out-of-my-word-%22c%2B%2B%22-tf3125890.html#a8660921
> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>


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