Update specific field on SOLR index

后端 未结 6 1479
-上瘾入骨i
-上瘾入骨i 2020-12-03 05:40

I want to using solr for search on articles

I have 3 table:

  1. Group (id , group name)
  2. ArticleBase (id, groupId, some other field)
  3. Arti
6条回答
  •  孤城傲影
    2020-12-03 05:51

    My Solution was something as below:

    $client = new SolrClient($options);
    $query = new SolrQuery();
    // Find old Document
    $query->setQuery('id:5458');
    $query->setStart(0);
    $query->setRows(1);
    $query_response = $client->query($query);
    // I had to set the parsemode to PARSE_SOLR_DOC
    $query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC);
    $response = $query_response->getResponse();
    $doc = new SolrInputDocument();
    // used the getInputDocument() to get the old document from the query
    $doc = $response->response->docs[0]->getInputDocument();
    if ($response->response->numFound) {
        $second_doc = new SolrInputDocument();
        $second_doc->addField('cat', "category123");
    // Notice I removed the second parameter from the merge()
        $second_doc->merge($doc);
        $updateResponse = $client->addDocument($second_doc);
        $client->commit();
    }
    

提交回复
热议问题