How PHP calls lucene (java class)

Source: Internet
Author: User
PHP calls lucene (java class). recently, php + lucene is used to construct a retrieval page. The basic idea is to allow users to input information in php, then, the php page calls lucene to search and return the result to php. php then presents the result to the user.

Currently, winXP + PHP5.3 + apache2.2 + mysql and lucene 3.5 are supported.

My idea is to use java to write a class that calls the lucene API and implement basic retrieval functions. Then, php calls this java class for retrieval.

After checking the relevant documents, php5 has no php_java.dll extension. you need to use php_java_bridge.
Then, go to php_java_bridge5.4 and install and configure php_java_bridge5.4 based on the information found on the Internet. During testing:
1. java built-in classes can be called.
2. customize the java class (if only the built-in java class is used), compile it into a class file, package it into a jar file, and use java_require ("... ") after the import, you can call the custom class.

But now the problem is:
If the lucene class is imported in the custom java class (which is my current practice), it will fail to be called in php. View javaBridge. jar log file vmbridge. log, the error is mainly similar:
Java. lang. ClassNotFoundException: Unresolved external reference: java. lang. NoClassDefFoundError: org/apache/lucene/store/Directory. -- Unable to call constructor
In my personal understanding, it seems that the class in lucene API cannot be found, and the object cannot be created.


Now we can think of using php to directly call lucene's API interface. I don't know if it is feasible or not, but it is quite troublesome.

I am comparing dishes. I am not very clear about the mechanism of php calling the java class to coordinate work. I 've been depressed for a whole day. please give me some advice...


Reply to discussion (solution)

You can use http. The java interface is called to return json data. Then php will present the results accordingly. There is no need to collaborate with java through extensions

The main post is progressing. After I package lucene. jar together, the above problems will not occur.
However, in php, the user-defined class method is called to retrieve documents, which does not seem to hit the document... The code is similar:
$ Lucene = new Java ("testLucene. TestLucene ");
Echo 'path = '. $ lucene-> search (new Java ("java. lang. string "," beauty "), new Java (" java. lang. string "," D:/test/index /"));
?>
The same code (also called the search method after the custom class is instantiated) can correctly retrieve the document that best matches the word "beauty" in the Test class written in java...

----------------------------------- Split ------------------------------------------------

You can use http. The java interface is called to return json data. Then php will present the results accordingly. There is no need to collaborate with java through extensions

Finally, I will wait for the reply. thank you first ~

Can this be explained in detail or a simple example?

I also encountered this problem. can you contact me if the landlord or others have a solution? QQ784718085 or send an email?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.