lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dian puma <>
Subject Need Help: Lucene with PHP/Java Bridge
Date Sat, 23 Oct 2010 16:01:17 GMT
Dear All,

Currently, I'm using PHP/Java Bridge to have Lucene in my PHP web
application, and also using the java extension for PHP.

FYI, I'd setup lucene on my PC several months ago and my code below worked well.

But, Today I try to setup lucene on another PC, and I get an error message:

indexing ... Exception occured: [[o:Exception]:"java.lang.Exception:
CreateInstance failed: new
(o:IndexWriter$MaxFieldLength)[o:Boolean]). Cause:
java.lang.ClassCastException@18a992f Responsible VM:
1.6.0_20@" at: #-8
sun.reflect.GeneratedConstructorAccessor2.newInstance(Unknown Source)
#-7 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
#-6 java.lang.reflect.Constructor.newInstance( #0 java_ThrowExceptionProxyFactory->getProxy(6, false) #1 java_Arg->getResult(false) #2
java_Client->getWrappedResult(false) #3
java_Client->getInternalResult() #4
java_Client->createObject('org.apache.luce...', Array, true) #5 java_create(Array, true) #6
java_create(Array, true) #7
Java->Java(Array) #8 /var/www/html/DLL/lucene/lucene_search.php(14):
Object(org_apache_lucene_analysis_standard_StandardAnalyzer), true) #9

Here is the code:

try {
  echo "indexing ... ";
  /* Create an index */
  /* create the index files in the tmp dir */
  $tmp = create_index_dir();
  $analyzer = new org_apache_lucene_analysis_standard_StandardAnalyzer();
  $writer = new org_apache_lucene_index_IndexWriter($tmp, $analyzer, true);
  $file = new java_io_File($cwd);
  $files = $file->listFiles();
  if(is_null($files)) {
    $user = java_lang_System()->getProperty("");
    echo("$cwd does not exist or is not readable.\n");
    echo("The directory must be readable by the user $user and it must not\n");
    echo("be protected by a SEL rule.\n");
  foreach($files as $f) {
    $doc = new org_apache_lucene_document_Document();
    $doc->add(new org_apache_lucene_document_Field(
  echo "done\n";

  echo "searching... ";
  /* Search */
  $searcher = new org_apache_lucene_search_IndexSearcher($tmp);
  $phrase = new org_apache_lucene_search_MatchAllDocsQuery();
  $hits = $searcher->search($phrase);

  /* Print result */
  $iter = $hits->iterator();
  $n = $hits->length();
  echo "done\n";
  echo "Hits: $n\n";

  /* Instead of retrieving the values one-by-one, we store them into a
   * LinkedList on the server side and then retrieve the list in one
   * query:
  $resultList = new java_util_LinkedList();

// create an XML document from the
// following PHP code, ...
  while($n--) {
    $next = $iter->next();
    $name = $next->get("name");
//  ... execute the XML document on
//  the server side, ...

// .. retrieve the result, ...
  $result = java_lang_System::javaValues($resultList);
// ... print the result array

} catch (JavaException $e) {
  echo "Exception occured: {$e->__toString()}<br>\n";

/** helper functions */
/** create a temporary directory for the lucene index files. Make sure
 * to create the tmpdir from Java so that the directory has
 * javabridge_tmp_t Security Enhanced Linux permission. Note that PHP
 * does not have access to tempfiles with java_bridge_tmp_t: PHP
 * inherits the rights from the HTTPD, usually httpd_tmp_t.
function create_index_dir() {
  global $tmp_file, $tmp_dir;
  $javaTmpdir = java_lang_System()->getProperty("");
  $tmpdir = java_values($javaTmpdir);
  $tmp_file=tempnam($tmpdir, "idx");
  $tmp_dir=new java_io_File("${tmp_file}.d");
  return java_values($tmp_dir->toString());

/** delete the lucene index files */
function delete_index_dir() {
  global $tmp_file, $tmp_dir;
  $files = $tmp_dir->listFiles();
  foreach($files as $f) {


If my code above works well on the 1st PC, why it doesn't work on my
other PC? Maybe I got wrong on its setting, but I have no idea where
it is.

Thanks in advance

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message