PHP環境(バージョン5.4以降)
Xunsearch Search Engine Server(ダウンロードしてインストールしてください)
require_once '/path/to/sdk/php/lib/xs.php';
$ xs = new xs( '/path/to/xunsearch/app.ini');
$ search = $ xs-> search; $ search-> setFuzzy(); $ search-> setLimit(10); $ search-> setScwsmulti(3); $ search-> addweight( 'title'、10); $ search-> addweight( 'content'、5);
$ keyword = $ _get ['q']; $ result = $ search-> search($ keyword);
foreach($ result as $ item){ echo $ item->タイトル。 '<br> '; echo $ item-> content。 '<br><br> '; }
require_once '/path/to/sdk/php/lib/xs.php';
$ xs = new xs( '/path/to/xunsearch/app.ini');
$ index = $ xs-> index;
$ pdo = new PDO( 'mysql:host = localhost; dbname = test'、 'username'、 'password'); $ pdo-> setattribute(pdo :: attr_errmode、pdo :: errmode_exception); $ stmt = $ pdo-> prepare( 'select * from article'); $ stmt-> execute(); $ data = $ stmt-> fetchall(pdo :: fetch_assoc);
foreach($ data as $ item){ $ doc = new xsdocument(); $ doc-> setfields($ item); $ index-> update($ doc); }
$ index-> flushindex();