echo "indexing ... "; /* Create an index */ $cwd = getcwd(); /* create the index files in the tmp dir */ $tmp = create_index_dir(); $analyzer = new java("org.apache.lucene.analysis.standard.StandardAnalyzer"); $writer = new java("org.apache.lucene.index.IndexWriter", $tmp, $analyzer, true); $file = new java("java.io.File", $cwd); $files = $file->listFiles(); assert(!java_is_null($files)); foreach ($files as $f) { $doc = new java("org.apache.lucene.document.Document"); $doc->add(new java("org.apache.lucene.document.Field", "name", $f->getName(), java('org.apache.lucene.document.Field$Store')->YES, java('org.apache.lucene.document.Field$Index')->UN_TOKENIZED)); $writer->addDocument($doc); } $writer->optimize(); $writer->close(); echo "done\n"; echo "searching... "; /* Search */ $searcher = new java("org.apache.lucene.search.IndexSearcher", $tmp); $phrase = new java("org.apache.lucene.search.MatchAllDocsQuery"); $hits = $searcher->search($phrase); /* Print result */ $iter = $hits->iterator(); $n = java_values($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 using java_values():