You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Mag Gam <ma...@gmail.com> on 2006/08/24 01:24:18 UTC

Query parser.parse (line);

Hi All,

I am trying to do a Query parse line in a doGET method (J2EE).

I keep getting this type of message;
unreported exception org.apache.lucene.queryParser.ParseException; must be
caught or declared to be thrown

Anyone have an example of a Class being thrown an exception?

I would kindly appreciate it.

tia

Re: Query parser.parse (line);

Posted by Mag Gam <ma...@gmail.com>.
Very good advice!

With the previous code you gave me, I was able to get everything for 2.0!
good call!



On 8/23/06, Erik Hatcher <er...@ehatchersolutions.com> wrote:
>
>
> On Aug 23, 2006, at 8:45 PM, Mag Gam wrote:
> > I am looking at this page
> > http://today.java.net/pub/a/today/2003/11/07/QueryParserRules.html
> >
> > Any chance there is a new version for 2.0? Or are there any 2.0
> > examples
> > (other than the stock example)?
>
> No, that article has not been updated for the 2.0 API.
>
> The main things that changed from the version of Lucene used in that
> article are:
>
>         * QueryParser must now be instantiated and the instance .parse()
> must be used instead of the previous QueryParser.parse() static method.
>
>         * BooleanQuery.add() now uses the Occur enumeration rather than
> the
> boolean flags.
>
> You can reference the javadocs for the 2.0 QueryParser and
> BooleanQuery APIs here: <http://lucene.apache.org/java/docs/api/
> index.html> and that will help you resolve any compilation issues you
> get when using code examples for previous versions.
>
> Given the nature of your questions I recommend you download Lucene
> 1.9 and use it for the time being (at least for the javadocs to see
> the deprecation messages with upgrade details), while you become
> familiar with Lucene.  All the examples you'll find online and in
> Lucene in Action are 1.9 compatible, and the main change between 1.9
> and 2.0 is that all the deprecated methods have been removed.  Once
> you have a working system and understand Lucene's API in more detail,
> you can tidy up any deprecation warnings you get and upgrade to 2.0.
>
>         Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Query parser.parse (line);

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Aug 23, 2006, at 8:45 PM, Mag Gam wrote:
> I am looking at this page
> http://today.java.net/pub/a/today/2003/11/07/QueryParserRules.html
>
> Any chance there is a new version for 2.0? Or are there any 2.0  
> examples
> (other than the stock example)?

No, that article has not been updated for the 2.0 API.

The main things that changed from the version of Lucene used in that  
article are:

	* QueryParser must now be instantiated and the instance .parse()  
must be used instead of the previous QueryParser.parse() static method.

	* BooleanQuery.add() now uses the Occur enumeration rather than the  
boolean flags.

You can reference the javadocs for the 2.0 QueryParser and  
BooleanQuery APIs here: <http://lucene.apache.org/java/docs/api/ 
index.html> and that will help you resolve any compilation issues you  
get when using code examples for previous versions.

Given the nature of your questions I recommend you download Lucene  
1.9 and use it for the time being (at least for the javadocs to see  
the deprecation messages with upgrade details), while you become  
familiar with Lucene.  All the examples you'll find online and in  
Lucene in Action are 1.9 compatible, and the main change between 1.9  
and 2.0 is that all the deprecated methods have been removed.  Once  
you have a working system and understand Lucene's API in more detail,  
you can tidy up any deprecation warnings you get and upgrade to 2.0.

	Erik


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


Re: Query parser.parse (line);

Posted by Mag Gam <ma...@gmail.com>.
Hi Erik, thanks for the quick reply

I am looking at this page
http://today.java.net/pub/a/today/2003/11/07/QueryParserRules.html

Any chance there is a new version for 2.0? Or are there any 2.0 examples
(other than the stock example)?



On 8/23/06, Erik Hatcher <er...@ehatchersolutions.com> wrote:
>
>
> On Aug 23, 2006, at 7:24 PM, Mag Gam wrote:
> > I am trying to do a Query parse line in a doGET method (J2EE).
> >
> > I keep getting this type of message;
> > unreported exception org.apache.lucene.queryParser.ParseException;
> > must be
> > caught or declared to be thrown
> >
> > Anyone have an example of a Class being thrown an exception?
> >
> > I would kindly appreciate it.
>
> The simplest thing would be something like this in a servlet:
>
> try {
>    Query query = parser.parse(...);
> }
> catch (ParseException pe) {
>    throw new IOException(pe.getMessage());
> }
>
> But you may not want the user to see that harsh of an error from your
> servlet when an unparsable expression is used.  Typically that
> exception is caught and a friendlier message is provided to the user.
>
>         Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Query parser.parse (line);

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Aug 23, 2006, at 7:24 PM, Mag Gam wrote:
> I am trying to do a Query parse line in a doGET method (J2EE).
>
> I keep getting this type of message;
> unreported exception org.apache.lucene.queryParser.ParseException;  
> must be
> caught or declared to be thrown
>
> Anyone have an example of a Class being thrown an exception?
>
> I would kindly appreciate it.

The simplest thing would be something like this in a servlet:

try {
   Query query = parser.parse(...);
}
catch (ParseException pe) {
   throw new IOException(pe.getMessage());
}

But you may not want the user to see that harsh of an error from your  
servlet when an unparsable expression is used.  Typically that  
exception is caught and a friendlier message is provided to the user.

	Erik


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