zoukankan      html  css  js  c++  java
  • php使用solr基础代码类

    <?php
    
    class solr
    {
        private $client;
        function __construct() {
            $options = array
            (
                'hostname' => "localhost",
                'path'     => 'solr/test',
                'port'     => '8983',
            );
            $this->client = new SolrClient($options);
        }
      
        //添加
        function add(){
            $data = array(
                array(
                'id' => '1',
                'name' => '男士打磨直筒休闲牛仔裤1',
                'brand' => 'ENERGIE',
                'cat' => '牛仔裤',
                'price' => '1870.00'
                ),
                array(
                'id' => '2',
                'name' => '品牌LOGO翻领拉链外套2',
                'brand' => 'ENERGIE',
                'cat' => '外套',
                'price' => '1680.00'
                ),
            );
    
    
            foreach($data as $key => $value) {
                $doc = new SolrInputDocument();
                foreach($value as $key2 =>$value2) {
                  $doc->addField($key2,$value2);
                }
               $client->addDocument($doc); 
    
            }
            $res = $this->client->commit();
    
            var_dump($res);
        }
        
        //查询
        function query(){
            $query = new SolrQuery();
    
            $query->setQuery("打磨");
    
            $query->setStart(0);
    
            $query->setRows(50);
    
            $query->addField('name');
    
            $query_response = $this->client->query($query);
    
            $response = $query_response->getResponse();
    
            print_r($response);
        }
        //删除
        function deleteCcore(){
            $this->client->deleteByQuery('id:EN80922032'); 
            $result = $this->client->commit();
            print_r($result);
            
        }
    }
    $solr = new solr;
    
    $solr->query();
    
    
    ?>
  • 相关阅读:
    哪些人需要学习Python开发?
    爬虫为什么用python
    python序列类型包括哪三种
    学习python的五个特点
    学python安装软件推荐
    怎么用python做网站?
    为什么大家都说,人生苦短我用python
    #专题练习# 搜索
    #专题练习# 网络流
    #专题练习# 强连通分量,缩点
  • 原文地址:https://www.cnblogs.com/wjs2019/p/14043442.html
Copyright © 2011-2022 走看看