1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php $options = array( 'hostname' => '192.168.22.190', 'port' => '8080' ); $client = new SolrClient($options); $doc = new SolrInputDocument(); $doc->addField('id', 123); $doc->addField('cat', 'haha1'); $doc->addField('cat', 'hoho1'); $updateResponse = $client->addDocument($doc); $client->commit(); var_dump($updateResponse->getResponse()); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php $options = array( 'hostname' => '192.168.22.190', 'port' => '8080' ); $client = new SolrClient($options); $query = new SolrQuery(); //开启高亮模式 $query->setHighlight(true); //查询条件 $query->setQuery('haha1');表示从所有字段中匹配haha1 $query->setQuery('cat:haha1 OR title:test'); $query->setStart(0); $query->setRows(50); //需要显示的字段 $query->addField('id')->addField('cat')->addField('title'); //需要高亮的字段 高亮样式在solrconfig.xml中配置 搜索hl. $query->addHighlightField('cat')->addHighlightField('title'); $query_response = $client->query($query); $response = $query_response->getResponse(); echo '<pre>'; print_r($response); |
1 2 3 4 5 6 7 8 9 10 11 |
<?php $options = array( 'hostname' => '192.168.22.190', 'port' => '8080' ); $client = new SolrClient($options); $update_response = $client->optimize(4, false, false); var_dump($update_response); |
php-solr扩展地址:
http://pecl.php.net/package/solr