国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

PHP擴(kuò)展之針對(duì)搜索引擎的擴(kuò)展(一)——Apache Solr

瀏覽:38日期:2022-09-15 18:09:28
簡(jiǎn)介及安裝

Solr擴(kuò)展允許你在PHP5中有效的和Apache Solr服務(wù)器通話。

Solr擴(kuò)展快速, 輕量級(jí), 有允許PHP開發(fā)者和Solr服務(wù)器實(shí)例有效通話的特性豐富的庫(kù)。

兼容APache Solr 1.3 和 1.4。

有內(nèi)置工具添加文檔和更新到solr服務(wù)器,還有工具允許你在搜索文檔時(shí)構(gòu)建高級(jí)查詢。

需要PHP5.2.11及以上版本。

需要安裝libxml及curl擴(kuò)展。

使用示例

Example #1 啟動(dòng)文件的內(nèi)容

<?php/*?Solr服務(wù)器的主機(jī)域名*/define(’SOLR_SERVER_HOSTNAME’,?’solr.example.com’);/*?是否以安全模式運(yùn)行?*/define(’SOLR_SECURE’,?true);/*?連接到的HTTP端口?*/define(’SOLR_SERVER_PORT’,?((SOLR_SECURE)???8443?:?8983));/*?HTTP?基本認(rèn)證名?*/define(’SOLR_SERVER_USERNAME’,?’admin’);/*?HTTP?基本認(rèn)證密碼?*/define(’SOLR_SERVER_PASSWORD’,?’changeit’);/*?HTTP?連接超時(shí)?*//*?http數(shù)據(jù)傳輸操作時(shí)有一個(gè)最大執(zhí)行時(shí)間(秒),默認(rèn)是30秒?*/define(’SOLR_SERVER_TIMEOUT’,?10);/*?File?name?to?a?PEM-formatted?private?key?+?private?certificate?*/define(’SOLR_SSL_CERT’,?’certs/combo.pem’);/*?File?name?to?a?PEM-formatted?private?certificate?only?*/define(’SOLR_SSL_CERT_ONLY’,?’certs/solr.crt’);/*?File?name?to?a?PEM-formatted?private?key?*/define(’SOLR_SSL_KEY’,?’certs/solr.key’);/*?Password?for?PEM-formatted?private?key?file?*/define(’SOLR_SSL_KEYPASSWORD’,?’StrongAndSecurePassword’);/*?Name?of?file?holding?one?or?more?CA?certificates?to?verify?peer?with*/define(’SOLR_SSL_CAINFO’,?’certs/cacert.crt’);/*?Name?of?directory?holding?multiple?CA?certificates?to?verify?peer?with?*/define(’SOLR_SSL_CAPATH’,?’certs/’);?>

Example #2 添加文檔到索引

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$doc?=?new?SolrInputDocument();$doc->addField(’id’,?334455);$doc->addField(’cat’,?’Software’);$doc->addField(’cat’,?’Lucene’);$updateResponse?=?$client->addDocument($doc);print_r($updateResponse->getResponse());?>

以上例程的輸出類似于:

SolrObject Object( [responseHeader] => SolrObject Object( [status] => 0 [QTime] => 446))

Example #3 合并一個(gè)文檔到另一個(gè)文檔

<?phpinclude?'bootstrap.php';$doc?=?new?SolrDocument();$second_doc?=?new?SolrDocument();$doc->addField(’id’,?1123);$doc->features?=?'PHP?Client?Side';$doc->features?=?'Fast?development?cycles';$doc[’cat’]?=?’Software’;$doc[’cat’]?=?’Custom?Search’;$doc->cat???=?’Information?Technology’;$second_doc->addField(’cat’,?’Lucene?Search’);$second_doc->merge($doc,?true);print_r($second_doc->toArray());?>

以上例程的輸出類似于:

Array( [document_boost] => 0 [field_count] => 3 [fields] => Array( [0] => SolrDocumentField Object( [name] => cat [boost] => 0 [values] => Array( [0] => Software [1] => Custom Search [2] => Information Technology)) [1] => SolrDocumentField Object( [name] => id [boost] => 0 [values] => Array( [0] => 1123)) [2] => SolrDocumentField Object( [name] => features [boost] => 0 [values] => Array( [0] => PHP Client Side [1] => Fast development cycles))))

Example #4 搜索文檔 - SolrObject響應(yīng)

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery();$query->setQuery(’lucene’);$query->setStart(0);$query->setRows(50);$query->addField(’cat’)->addField(’features’)->addField(’id’)->addField(’timestamp’);$query_response?=?$client->query($query);$response?=?$query_response->getResponse();print_r($response);?>

以上例程的輸出類似于:

SolrObject Object( [responseHeader] => SolrObject Object( [status] => 0 [QTime] => 1 [params] => SolrObject Object( [wt] => xml [rows] => 50 [start] => 0 [indent] => on [q] => lucene [fl] => cat,features,id,timestamp [version] => 2.2)) [response] => SolrObject Object( [numFound] => 3 [start] => 0 [docs] => Array( [0] => SolrObject Object( [cat] => Array( [0] => Software [1] => Lucene) [id] => 334456) [1] => SolrObject Object( [cat] => Array( [0] => Software [1] => Lucene) [id] => 334455) [2] => SolrObject Object( [cat] => Array( [0] => software [1] => search) [features] => Array( [0] => Advanced Full-Text Search Capabilities using Lucene [1] => Optimized for High Volume Web Traffic [2] => Standards Based Open Interfaces - XML and HTTP [3] => Comprehensive HTML Administration Interfaces [4] => Scalability - Efficient Replication to other Solr Search Servers [5] => Flexible and Adaptable with XML configuration and Schema [6] => Good unicode support: héllo (hello with an accent over the e)) [id] => SOLR1000 [timestamp] => 2009-09-04T20:38:55.906))))

Example #5 搜索文檔 - SolrDocument響應(yīng)

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery();$query->setQuery(’lucene’);$query->setStart(0);$query->setRows(50);$query->addField(’cat’)->addField(’features’)->addField(’id’)->addField(’timestamp’);$query_response?=?$client->query($query);$query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC);$response?=?$query_response->getResponse();print_r($response);?>

以上例程的輸出類似于:

SolrObject Object( [responseHeader] => SolrObject Object( [status] => 0 [QTime] => 1 [params] => SolrObject Object( [wt] => xml [rows] => 50 [start] => 0 [indent] => on [q] => lucene [fl] => cat,features,id,timestamp [version] => 2.2)) [response] => SolrObject Object( [numFound] => 3 [start] => 0 [docs] => Array( [0] => SolrDocument Object( [_hashtable_index:SolrDocument:private] => 19740) [1] => SolrDocument Object( [_hashtable_index:SolrDocument:private] => 25485) [2] => SolrDocument Object( [_hashtable_index:SolrDocument:private] => 25052))))

Example #6 簡(jiǎn)單 TermsComponent 實(shí)例 - 基本

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery();$query->setTerms(true);$query->setTermsField(’cat’);$updateResponse?=?$client->query($query);print_r($updateResponse->getResponse());?>

以上例程的輸出類似于:

SolrObject Object( [responseHeader] => SolrObject Object( [status] => 0 [QTime] => 2) [terms] => SolrObject Object( [cat] => SolrObject Object( [electronics] => 14 [Lucene] => 4 [Software] => 4 [memory] => 3 [card] => 2 [connector] => 2 [drive] => 2 [graphics] => 2 [hard] => 2 [monitor] => 2)))

Example #7 簡(jiǎn)單 TermsComponent 實(shí)例 - 使用前綴

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery();$query->setTerms(true);/*?Return?only?terms?starting?with?$prefix?*/$prefix?=?’c’;$query->setTermsField(’cat’)->setTermsPrefix($prefix);$updateResponse?=?$client->query($query);print_r($updateResponse->getResponse());?>

以上例程的輸出類似于:

SolrObject Object( [responseHeader] => SolrObject Object( [status] => 0 [QTime] => 1) [terms] => SolrObject Object( [cat] => SolrObject Object( [card] => 2 [connector] => 2 [camera] => 1 [copier] => 1)))

Example #8 簡(jiǎn)單 TermsComponent 實(shí)例 - 指定最小頻率

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery();$query->setTerms(true);/*?Return?only?terms?starting?with?$prefix?*/$prefix?=?’c’;/*?Return?only?terms?with?a?frequency?of?2?or?greater?*/$min_frequency?=?2;$query->setTermsField(’cat’)->setTermsPrefix($prefix)->setTermsMinCount($min_frequency);$updateResponse?=?$client->query($query);print_r($updateResponse->getResponse());?>

以上例程的輸出類似于:

SolrObject Object( [responseHeader] => SolrObject Object( [status] => 0 [QTime] => 0) [terms] => SolrObject Object( [cat] => SolrObject Object( [card] => 2 [connector] => 2)))

Example #9 簡(jiǎn)單 Facet 實(shí)例

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery(’*:*’);$query->setFacet(true);$query->addFacetField(’cat’)->addFacetField(’name’)->setFacetMinCount(2);$updateResponse?=?$client->query($query);$response_array?=?$updateResponse->getResponse();$facet_data?=?$response_array->facet_counts->facet_fields;print_r($facet_data);?>

以上例程的輸出類似于:

SolrObject Object( [cat] => SolrObject Object( [electronics] => 14 [memory] => 3 [Lucene] => 2 [Software] => 2 [card] => 2 [connector] => 2 [drive] => 2 [graphics] => 2 [hard] => 2 [monitor] => 2 [search] => 2 [software] => 2) [name] => SolrObject Object( [gb] => 6 [1] => 3 [184] => 3 [2] => 3 [3200] => 3 [400] => 3 [500] => 3 [ddr] => 3 [i] => 3 [ipod] => 3 [memori] => 3 [pc] => 3 [pin] => 3 [pod] => 3 [sdram] => 3 [system] => 3 [unbuff] => 3 [canon] => 2 [corsair] => 2 [drive] => 2 [hard] => 2 [mb] => 2 [n] => 2 [power] => 2 [retail] => 2 [video] => 2 [x] => 2))

Example #10 簡(jiǎn)單 Facet 實(shí)例 - 使用可選字段重寫 mincount

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery(’*:*’);$query->setFacet(true);$query->addFacetField(’cat’)->addFacetField(’name’)->setFacetMinCount(2)->setFacetMinCount(4,?’name’);$updateResponse?=?$client->query($query);$response_array?=?$updateResponse->getResponse();$facet_data?=?$response_array->facet_counts->facet_fields;print_r($facet_data);?>

以上例程的輸出類似于:

SolrObject Object( [cat] => SolrObject Object( [electronics] => 14 [memory] => 3 [Lucene] => 2 [Software] => 2 [card] => 2 [connector] => 2 [drive] => 2 [graphics] => 2 [hard] => 2 [monitor] => 2 [search] => 2 [software] => 2) [name] => SolrObject Object( [gb] => 6))

Example #11 連接到 SSL-Enabled 服務(wù)器

<?phpinclude?'bootstrap.php';$options?=?array( ’hostname’?=>?SOLR_SERVER_HOSTNAME, ’login’????=>?SOLR_SERVER_USERNAME, ’password’?=>?SOLR_SERVER_PASSWORD, ’port’?????=>?SOLR_SERVER_PORT, ’timeout’??=>?SOLR_SERVER_TIMEOUT, ’secure’???=>?SOLR_SECURE, ’ssl_cert’?=>?SOLR_SSL_CERT_ONLY, ’ssl_key’??=>?SOLR_SSL_KEY, ’ssl_keypassword’?=>?SOLR_SSL_KEYPASSWORD, ’ssl_cainfo’?=>?SOLR_SSL_CAINFO,);$client?=?new?SolrClient($options);$query?=?new?SolrQuery(’*:*’);$query->setFacet(true);$query->addFacetField(’cat’)->addFacetField(’name’)->setFacetMinCount(2)->setFacetMinCount(4,?’name’);$updateResponse?=?$client->query($query);$response_array?=?$updateResponse->getResponse();$facet_data?=?$response_array->facet_counts->facet_fields;print_r($facet_data);?>

以上例程的輸出類似于:

SolrObject Object( [cat] => SolrObject Object( [electronics] => 14 [memory] => 3 [Lucene] => 2 [Software] => 2 [card] => 2 [connector] => 2 [drive] => 2 [graphics] => 2 [hard] => 2 [monitor] => 2 [search] => 2 [software] => 2) [name] => SolrObject Object( [gb] => 6))

更多類及方法的使用詳見http://www.php.net/manual/zh/book.solr.php

標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 97免费在线观看视频 | 欧美一级毛片免费高清aa | 亚洲人成网站在线在线 | 国产乱码一区二区三区四川人 | 一级片高清 | 欧美日韩一区二区三区免费不卡 | 日本美女视频韩国视频网站免费 | 欧美日韩亚洲v在线观看 | 久草免费新视频 | 亚洲欧美日韩国产精品久久 | 精品无码久久久久久国产 | 极品美女一级毛片 | 99免费观看视频 | 久久欧美精品 | 一区二区三区不卡在线观看 | 欧美午夜免费一级毛片 | 99久久精品免费看国产一区二区 | 国内精品久久久久久久久 | 日本亚州视频在线八a | 日本aa毛片a级毛片免费观看 | 成人欧美一区二区三区 | 免费国产成人 | 日本特级黄毛片毛片视频 | u影一族亚洲精品欧美激情 va欧美 | 久久不见久久见免费影院www日本 | 国产成人黄网在线免 | 免费国产高清精品一区在线 | 久操视频免费在线观看 | 亚洲黄视频在线观看 | 看真人一级毛片 | 亚洲第一免费播放区 | 国产欧美精品三区 | 九九国产精品 | 久久狠狠一本精品综合网 | 97在线视频免费观看费观看 | 男人天堂网在线观看 | 国产一区二区在线视频播放 | 和老外3p爽粗大免费视频 | 久久精品视 | 九九爱精品 | 日韩黄色一级片 |