【问题标题】:PHP solr atomic updatePHP solr 原子更新
【发布时间】:2016-03-31 06:26:18
【问题描述】:

我是 solr 的新手,我一直在使用这个线程进行原子更新

How do I update a document in Solr PHP?

基本上我在做一个 mysql 查询然后在 solr 上更新一个文档

问题:如何在特定字段匹配的情况下进行原子更新,应在 if 语句中匹配字段,如下所示:

if(solr(username.field) == 'john'))
{
  //execute atomic update
} 

到目前为止,我的代码是这样的:

$query = "SELECT * from User";

    $options = array
    (
        'hostname' => SOLR_SERVER_HOSTNAME,
        'login'    => SOLR_SERVER_USERNAME,
        'password' => SOLR_SERVER_PASSWORD,
        'port'     => SOLR_SERVER_PORT,
        'path'     => SOLR_SERVER_PATH,
    );

    $result   = $mysqli->query($query);
    if($result->num_rows > 0)
    {
        while($row=mysqli_fetch_assoc($result))
        {

            $querySearch = '+username:*'; //query all user that is on solr
            $query       = new SolrQuery();
            $query->setQuery($querySearch);
            $query->setStart(0);
            $query->setRows(10000);
            $client             = new SolrClient($options);
            $query_response     = $client->query($query);             
            $query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC);
            $response = $query_response->getResponse();
            $doc = new SolrInputDocument();
            $counter = $response->response->numFound;
            for($x = 0; $x < $counter; $x++)
            {
                $doc = $response->response->docs[$x]->getInputDocument(); //this gets the old value (refer to thread)
                $docs  = $query_response->getResponse()->response->docs[$x]->username->values; //how I get the value of users

                $second_doc = new SolrInputDocument();

                if($docs == get_product($row['USERNAME']))
                {
                    $second_doc->addField('points', $row['POINTS']); //this suppose to update my solr document with those username found
                }
                else
                {
                    $second_doc->addField('points', "0");
                }
                    $second_doc->merge($doc);
                    $updateResponse = $client->addDocument($second_doc);
                    $client->commit();
            }    
        }

【问题讨论】:

    标签: php solr


    【解决方案1】:

    应该是的

    if(!empty($response->response->docs[$x]->username->values[$x]) == get_product($row['USERNAME']))
    {
       $doc = $response->response->docs[$x]->getInputDocument();
       $second_doc->addField('point', $row['POINT']);
    }
    else
    {
        //do other update here
    }
    
    //$response->response->docs[$x]->username->values[$x] => get the usernames in the document
    

    【讨论】:

      猜你喜欢
      • 2014-04-07
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 2014-12-18
      • 2014-08-16
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      相关资源
      最近更新 更多