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();
    
    
    ?>
  • 相关阅读:
    卷积神经网络
    TensorFlow线性回归
    TensorFlow常用操作
    TensorFlow基本计算单元——变量
    Pandas基础
    Numpy基础
    Python基础
    Windows下安装TensorFlow教程
    mongodb并列查询,模糊查询
    C#对Mongodb数组对象操作
  • 原文地址:https://www.cnblogs.com/wjs2019/p/14043442.html
Copyright © 2011-2022 走看看