Wednesday, October 18, 2006

FreeBsd6 estraierpure.php

pear にestraierのパッケージがないか探していましたが、
えらいお方が、pear規約でお作りになられていました。

http://page2.xrea.jp/

使用させて頂きます。
簡易ですが、コネクションpoolとID管理周りを実装した
らっぱーを作成してみました。

//使用方法
# 登録
$est = & EST::getObj("hoge");
$val['colm' ] = "name";
$val['id' ] = "20";
$val['title' ] = "name";
$val['body' ] = "あいうえお#かきくけこ";
$est->put($val);

#検索
$est = & EST::getObj("hoge");;
$val['phrase'] = "あいうえお";
$val['max' ] = 10;
$val['skip' ] = 0;
$rs = $est->get($val);

//disp
Array
(
[0] => Array
(
[id] => 20
[colm] => name
[snippet] => あいうえお #かきくけこ
)


//ソース
require_once(PEAR_DIR . 'EstraierPure/estraierpure.php');

class EST
{
  var $mNode;
  var $mCond;
  var $mDoc;

  function EST( $node )
  {
    $this->connect( $node );
  }

  function connect( $node )
  {

    // node
    $this->mNode = &new EstraierPure_Node;
    $this->mNode->set_url('http://localhost:1978/node/'.$node );
    $this->mNode->set_auth('hoge', 'hogehoge');

    // condition
    $this->mCond = &new EstraierPure_Condition;

    // document
    $this->mDoc = &new EstraierPure_Document;
  }

  function get( $val )
  {

    // set condition
    if ( isset($val['phrase']) ){ $this->mCond->set_phrase($val['phrase']);}
    if ( isset($val['max' ]) ){ $this->mCond->set_max($val['max']); }
    if ( isset($val['skip' ]) ){ $this->mCond->set_skip($val['skip']); }

    // search
    $nres = &$this->mNode->search($this->mCond, 0 );

    // get result
    if ($nres) {

      for ($i = 0; $i < $nres->doc_num(); $i++) {

        $rdoc = &$nres->get_doc($i);
        list($rs[$i]['colm'] , $rs[$i]['id']) = split("-",$rdoc->attr('@uri'));
        //$rs[$i]['uri' ] = $rdoc->attr('@uri');
        //$rs[$i]['title' ] = $rdoc->attr('@title');
        //$rs[$i]['author' ] = $rdoc->attr('@author');
        $rs[$i]['snippet'] = $rdoc->snippet();
      }
    }

    return $rs;
  }

  function put( $val )
  {

    $this->mDoc->add_attr('@uri' , $val['colm']."-".$val['id']);
    $this->mDoc->add_attr('@title', $val['title']);
    $this->mDoc->add_text( $val['body'] );

    $this->mNode->put_doc($this->mDoc);
  }


  //singleton
  function &getObj( $node )
  {
    static $myselfESTObj;

    if($myselfESTObj == NULL)
    {
        $myselfESTObj = new EST( $node );

        //destruct
        register_shutdown_function("destroyEST");
    }
    return $myselfESTObj;
  }
}

/*==============================================================================X
X Function Name : destroyConnect
X===============================================================================*/
function destroyEST()
{
  $objdb =& EST::getObj();
  if (is_object( $objdb )){
    //$objdb->close();
    unset($objdb);
  }
}
?>

 

3 Comments:

Anonymous Anonymous said...

Hello,

I am regular visitor of this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]cereman.blogspot.com really contains lot of useful information. Do you pay attention towards your health?. In plain english I must warn you that, you are not serious about your health. Recent Scientific Research points that nearly 70% of all U.S. adults are either fat or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Hence if you're one of these people, you're not alone. Its true that we all can't be like Brad Pitt, Angelina Jolie, Megan Fox, and have sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? You can easily lose with with little effort. Some improvement in of daily activity can help us in losing weight quickly.

About me: I am author of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also mentor who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for quick weight loss.

9:50 AM  
Anonymous Anonymous said...

You could easily be making money online in the underground world of [URL=http://www.www.blackhatmoneymaker.com]blackhat download[/URL], Don’t feel silly if you haven’t heard of it before. Blackhat marketing uses alternative or not-so-known methods to generate an income online.

6:52 AM  
Anonymous Anonymous said...

top [url=http://www.001casino.com/]casino online[/url] hinder the latest [url=http://www.casinolasvegass.com/]free casino[/url] autonomous no consign bonus at the leading [url=http://www.baywatchcasino.com/]online casinos
[/url].

11:02 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home