Category: PHP / Tags:
Hyper Estraier を phpからつかってみる(検索のみ)
http://page2.xrea.jp/
に、ノード API の Pure PHP クラスライブラリ EstraierPure があったので、これを利用して
Hyper Estraier をつかってみる。
でだしは、MTの検索が重いので、全文検索のnamazuを利用していたのだけど、つかいこなして
ないこともあって、いまいち検索結果がピンとこない。
てことで、文章ドラフトをつくれる、Hyper Estraierで、やってみようかとというところと,
PHP Namazu モジュールでは、URIを指定しての検索ができない(つまりはブロガー指定の検索ができない)ので、
一応、Cのソースまで見てみたのですが、実装ができてないみたいだったので、できるならごめんなさい。
自分で実装すれば、っていうのも今回はなしで。
P2Pあたりの機能で実装できそうなこちらにチャレンジしてみます。
ブログ登録があると自動で検索対象にしてくれるモジュールがあるのも決めてでした。
namazuだと、毎日indexの更新するcronが動くまでまたないといけなかったので。
下記にドキュメントはあるのですが
http://page2.xrea.jp/doc/all/index.php?package=Services_HyperEstraier
多くの人がとりあえず、indexの生成とかは、サーバーがわのシェルスクリプトとかでやって
検索インターフェイスの実装だけをしたいと思うので、(というかおいらが)その分のメモ書き
現状の検索は
html -> js(ajax) -> api -> namazu -> api -> js -> html
のながれで、jsから、apiにアクセスして、apiが内部でnamazuの検索結果を取得して、XML
に変換して返しているので、この aip の書き直しと namazuを hyper estraier への移行で
対応したいと思います。
Class HyperEstraier_Condition が検索で主に使われるクラスになります。
簡単なながれで、
1.検索のオプション値(検索ワード、表示順、取得数)を設置して、
2.検索メソット(serach)にアクセスして、結果を取得
3.取得したデータを加工して表示
(xmlでも結果を取得できるので上手くいけばいらないかもしれない)
を想定
HyperEstraier_Conditionの初期値(つまりは、検索の初期値)は、下記の通り
//初期値
$this->phrase = null;
$this->attrs = array();
$this->order = null;
$this->max = -1;
$this->skip = 0;
$this->options = 0;
$this->auxiliary = 32;
$this->distinct = null;
$this->mask = 0;
それぞれ、setterとgetterのメソットがあるので、あとはそれらを利用して自由に検索してください。
簡易一覧 – そのうち適当な日本語に置き換える予定
function_name param の順です
//Set the search phrase.
set_phrase($phrase) (string $phrase A search phrase.) void
//Add an expression for an attribute.
add_attr($expr) (string $expr A search expression.) void
//Set the order of a condition object.
set_order($order) (string $order An expression for the order. By default, the order is by score descending.) void
//Set the maximum number of retrieval.
set_max($max) (int $max The maximum number of retrieval. By default, the number of retrieval is not limited.) void
//Set the number of documents to be skipped.
set_skip($skip) (int $skip The number of documents to be skipped. By default, it is 0.) void
//Set options of retrieval.
set_options($options) (int $options Options: * – ESTRAIERPURE_CONDITION_SURE’ specifies that it checks every N-gram key. * – ESTRAIERPURE_CONDITION_USUAL’, which is the default, * specifies that it checks N-gram keys with skipping one key. * – ESTRAIERPURE_CONDITION_FAST’ skips two keys. * – ESTRAIERPURE_CONDITION_AGITO’ skips three keys. * – “ESTRAIERPURE_CONDITION_NOID” F’ specifies not to perform TF-ID F tuning. * – ESTRAIERPURE_CONDITION_SIMPLE’ specifies to use simplified phrase. * – ESTRAIERPURE_CONDITION_ROUGH’ specifies to use rough phrase. * – ESTRAIERPURE_CONDITION_UNION’ specifies to use union phrase. * – ESTRAIERPURE_CONDITION_ISECT’ specifies to use intersection phrase. * Each option can be specified at the same time by bitwise or. * If keys are skipped, though search speed is improved, the relevance ratio grows less.) void
//Set permission to adopt result of the auxiliary index.
set_auxiliary($min) (int $min The minimum hits to adopt result of the auxiliary index. If it is not more than 0, the auxiliary index is not used. By default, it is 32.) void
// Set the attribute distinction filter.
set_distinct($name) (string $name The name of an attribute to be distinct.) void
//Set the mask of targets of meta search.
set_mask($mask) (int $mask A masking number. 1 means the first target, 2 means the second target, 4 means the third target, and power values of 2 and their summation compose the mask.) void
// getter methods
それぞれのgetter methods
function phrase()
function attrs()
function order()
function max()
function skip()
function options()
function auxiliary()
function distinct()
function mask()
–
上記の、設定がおわったら
EstraierPure_Node の search メソットになげれば、検索結果(EstraierPure_NodeResultのobject)が返ってきます。
get_doc
get_doc_attr
get_doc_attr_by_uri
get_doc_by_uri
あたりをつかって、加工すればOK