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 milu07 <lo...@gmail.com> on 2008/03/21 21:24:37 UTC

Call Lucene default command line Search from PHP script

Hello,

My machine is Ubuntu 7.10. I am working with Apache Lucene. I have done with
indexer and tried with command line Searcher (the default command line
included in Lucene package: http://lucene.apache.org/java/2_3_1/demo2.html).
When I use this at command line:

java Searcher -query algorithm

it works and returns a list of results to me. Here 'algorithm' is the
keyword to search.

However, I want to have a web search interface written in PHP, I use PHP
exec() to call this Searcher from my PHP script:

exec("java Searcher -query algorithm ", $arr, $retVal);
[I also tried: exec("java Searcher -query 'algorithm' ", $arr, $retVal)]

It does not work. I print the value of $retVal, it is 1.

I come back and try: exec("java Searcher -query algorithm 2>&1 ", $arr,
$retVal);
I receive: 
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/lucene/analysis/Analyzer  
and $retVal is 1

In the command line Searcher.java of Lucene, it imports many libraries, is
this the problem?
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyz er;
....

I guess this is the problem of path. However, I do not know how to fix it
because it works in command line ($CLASSPATH points to the .jar file of
Lucene library). May be PHP does not know $CLASSPATH. So, I add Lucene lib
to $PATH:

export PATH=$PATH:/usr/lib/lucene-core-2.3.1.jar:/usr/lib

However, I get the same error message when I try: exec("java Searcher -query
algorithm 2>&1 ", $arr, $retVal);
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/lucene/analysis/Analyzer

Could you please help?

Thank you,
-- 
View this message in context: http://www.nabble.com/Call-Lucene-default-command-line-Search-from-PHP-script-tp16207418p16207418.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


Re: Call Lucene default command line Search from PHP script

Posted by Paul Elschot <pa...@xs4all.nl>.
Op Saturday 22 March 2008 00:32:32 schreef Paul Elschot:
> Milu,
>
> This is a PHP problem, not a Lucene one, so you might get better
> response at a PHP mailing list.
>
> The easy way around your problem is probably by invoking a shell
> script from php that exports the class path as you indicated,
> so that java can see the correct classes.

I meant a shell script that exports the class path, and invokes
java from the same shell.

Regards,
Paul Elschot

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


Re: Call Lucene default command line Search from PHP script

Posted by Paul Elschot <pa...@xs4all.nl>.
Milu,

This is a PHP problem, not a Lucene one, so you might get better
response at a PHP mailing list.

The easy way around your problem is probably by invoking a shell
script from php that exports the class path as you indicated,
so that java can see the correct classes.

Having said that, you'll probably want to use the PHP/Java extension
to avoid initializing a JVM for each call to lucene.  Try this:
http://www.google.nl/search?q=php+java+org+apache+lucene&ie=UTF-8&oe=UTF-8

This was one of the results:
http://www.idimmu.net/index.php?blog%5Bpagenum%5D=3


Regards,
Paul Elschot


Op Friday 21 March 2008 21:24:37 schreef milu07:
> Hello,
>
> My machine is Ubuntu 7.10. I am working with Apache Lucene. I have
> done with indexer and tried with command line Searcher (the default
> command line included in Lucene package:
> http://lucene.apache.org/java/2_3_1/demo2.html). When I use this at
> command line:
>
> java Searcher -query algorithm
>
> it works and returns a list of results to me. Here 'algorithm' is the
> keyword to search.
>
> However, I want to have a web search interface written in PHP, I use
> PHP exec() to call this Searcher from my PHP script:
>
> exec("java Searcher -query algorithm ", $arr, $retVal);
> [I also tried: exec("java Searcher -query 'algorithm' ", $arr,
> $retVal)]
>
> It does not work. I print the value of $retVal, it is 1.
>
> I come back and try: exec("java Searcher -query algorithm 2>&1 ",
> $arr, $retVal);
> I receive:
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/lucene/analysis/Analyzer
> and $retVal is 1
>
> In the command line Searcher.java of Lucene, it imports many
> libraries, is this the problem?
> import org.apache.lucene.analysis.Analyzer;
> import org.apache.lucene.analysis.standard.StandardAnalyz er;
> ....
>
> I guess this is the problem of path. However, I do not know how to
> fix it because it works in command line ($CLASSPATH points to the
> .jar file of Lucene library). May be PHP does not know $CLASSPATH.
> So, I add Lucene lib to $PATH:
>
> export PATH=$PATH:/usr/lib/lucene-core-2.3.1.jar:/usr/lib
>
> However, I get the same error message when I try: exec("java Searcher
> -query algorithm 2>&1 ", $arr, $retVal);
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/lucene/analysis/Analyzer
>
> Could you please help?
>
> Thank you,



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


Re: Call Lucene default command line Search from PHP script

Posted by Raghu Ram <ra...@gmail.com>.
try using php java bridge
http://php-java-bridge.sourceforge.net/
Its a way for using java objects directly in php.

2008/3/25 Mathieu Lecarme <ma...@garambrogne.net>:

> milu07 a écrit :
>
>  Hello,
> >
> > My machine is Ubuntu 7.10. I am working with Apache Lucene. I have done
> > with
> > indexer and tried with command line Searcher (the default command line
> > included in Lucene package:
> > http://lucene.apache.org/java/2_3_1/demo2.html).
> > When I use this at command line:
> >
> > java Searcher -query algorithm
> >
> > it works and returns a list of results to me. Here 'algorithm' is the
> > keyword to search.
> >
> > However, I want to have a web search interface written in PHP, I use PHP
> > exec() to call this Searcher from my PHP script:
> >
> > exec("java Searcher -query algorithm ", $arr, $retVal);
> > [I also tried: exec("java Searcher -query 'algorithm' ", $arr, $retVal)]
> >
> > It does not work. I print the value of $retVal, it is 1.
> >
> > I come back and try: exec("java Searcher -query algorithm 2>&1 ", $arr,
> > $retVal);
> > I receive: Exception in thread "main" java.lang.NoClassDefFoundError:
> > org/apache/lucene/analysis/Analyzer  and $retVal is 1
> >
> > In the command line Searcher.java of Lucene, it imports many libraries,
> > is
> > this the problem?
> > import org.apache.lucene.analysis.Analyzer;
> > import org.apache.lucene.analysis.standard.StandardAnalyz er;
> > ....
> >
> > I guess this is the problem of path. However, I do not know how to fix
> > it
> > because it works in command line ($CLASSPATH points to the .jar file of
> > Lucene library). May be PHP does not know $CLASSPATH. So, I add Lucene
> > lib
> > to $PATH:
> >
> > export PATH=$PATH:/usr/lib/lucene-core-2.3.1.jar:/usr/lib
> >
> > However, I get the same error message when I try: exec("java Searcher
> > -query
> > algorithm 2>&1 ", $arr, $retVal);
> > Exception in thread "main" java.lang.NoClassDefFoundError:
> > org/apache/lucene/analysis/Analyzer
> >
> > Could you please help?
> >
> > Thank you,
> >
> >
> using command line from PHP is a bad idea.
> socket is a better way :
> https://admin.garambrogne.net/projets/passerelle/browser/trunk/goniometre
>
>
> M.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Call Lucene default command line Search from PHP script

Posted by Mathieu Lecarme <ma...@garambrogne.net>.
milu07 a écrit :
> Hello,
>
> My machine is Ubuntu 7.10. I am working with Apache Lucene. I have done with
> indexer and tried with command line Searcher (the default command line
> included in Lucene package: http://lucene.apache.org/java/2_3_1/demo2.html).
> When I use this at command line:
>
> java Searcher -query algorithm
>
> it works and returns a list of results to me. Here 'algorithm' is the
> keyword to search.
>
> However, I want to have a web search interface written in PHP, I use PHP
> exec() to call this Searcher from my PHP script:
>
> exec("java Searcher -query algorithm ", $arr, $retVal);
> [I also tried: exec("java Searcher -query 'algorithm' ", $arr, $retVal)]
>
> It does not work. I print the value of $retVal, it is 1.
>
> I come back and try: exec("java Searcher -query algorithm 2>&1 ", $arr,
> $retVal);
> I receive: 
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/lucene/analysis/Analyzer  
> and $retVal is 1
>
> In the command line Searcher.java of Lucene, it imports many libraries, is
> this the problem?
> import org.apache.lucene.analysis.Analyzer;
> import org.apache.lucene.analysis.standard.StandardAnalyz er;
> ....
>
> I guess this is the problem of path. However, I do not know how to fix it
> because it works in command line ($CLASSPATH points to the .jar file of
> Lucene library). May be PHP does not know $CLASSPATH. So, I add Lucene lib
> to $PATH:
>
> export PATH=$PATH:/usr/lib/lucene-core-2.3.1.jar:/usr/lib
>
> However, I get the same error message when I try: exec("java Searcher -query
> algorithm 2>&1 ", $arr, $retVal);
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/lucene/analysis/Analyzer
>
> Could you please help?
>
> Thank you,
>   
using command line from PHP is a bad idea.
socket is a better way :
https://admin.garambrogne.net/projets/passerelle/browser/trunk/goniometre

M.

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