hi guys,
i try write this java code in php using php java bridge:

http://www.lucenetutorial.com/lucene-in-5-minutes.html

when i found this line:

IndexReader reader = DirectoryReader.open(index);

i dont get it how to write it in php.
i've tried but error result.

when it be like this:

Query q = new QueryParser(Version.LUCENE_40, "content", analyzer).parse(querystr);

i write in php like below:

$query = new Query\QueryParser($version->LUCENE_43,'content',$analyzer);
$query->parse($querystr);

it's no error.

so, could you help me how to write it in php??
thanks in advance.

Member Avatar for LastMitch

i dont get it how to write it in php.

@el macho

It's not PHP you are having issue, it's creating a mysql query to connected to the database.

I don't think you have query yet because if you did you would have provided that already.

im using laravel 4,
i have add document, here is my code,

<?php
require_once("http://localhost:8080/lucene/java/Java.inc");

use java\lang\System as SYS;
use java\io as IO;

use org\apache\lucene\util as Util;
//use org\apache\lucene as Lucene;
use org\apache\lucene\analysis\id as Id;
use org\apache\lucene\document as Document;
use org\apache\lucene\index as Index;
use org\apache\lucene\queryparser\classic as Query;
use org\apache\lucene\search as Search;
use org\apache\lucene\store as Store;

class SearchController extends BaseController
{

    function SearchQuery()
    {
        $version = new Util\Version();
        //echo $version->LUCENE_43;

        $analyzer = new Id\IndonesianAnalyzer($version->LUCENE_43);
        $index = new Store\RAMDirectory();
        $config = new Index\IndexWriterConfig($version->LUCENE_43,$analyzer);
        $writer = new Index\IndexWriter($index,$config);

        //create index
        $datadoc = documents::all();
        foreach($datadoc as $dtdoc)
        {
            $this->adddoc($writer,$dtdoc->title,$dtdoc->content);
        }

        //query
        $strquery=Input::get('myquery');
        $query = new Query\QueryParser($version->LUCENE_43,'content',$analyzer);
        $query->parse($strquery);

        //search
        $reader = new Index\IndexReader();
        $reader->DirectoryReader->open($index);
        //$searcher = new Search\IndexSearcher($index);
    }

    function adddoc($writer,$title,$content)
    {
        $doc = new Document\Document();
        $doc->add(new Document\TextField('title',$title,Document\Field::type("Store")->YES));
        $doc->add(new Document\TextField('content',$content,Document\Field::type("Store")->YES));
        $writer->addDocument($doc);
    }
}

i just have obstacle to write this code:

IndexReader reader = DirectoryReader.open(index);

bcoz, all i know is to initiate a object in java, use 'new'.
but i dont find in that code, that's why i dont get it.

Member Avatar for LastMitch

im using laravel 4,

@el macho

Not familiar with Java but since you are using laravel 4, then read this:

http://laravel.com/docs/configuration

That link above explain and show how to configurate in laravel framework.

http://laravel.com/docs/queries

That link above explain and show how to write a query in laravel framework.

You need to used lavavel framework structure tags another words every CMS / frameworks has its own language.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.