public function getDocument($id) { if ($id instanceof Zend_Search_Lucene_Search_QueryHit) { /* @var $id Zend_Search_Lucene_Search_QueryHit */ $id = $id->id; } if ($id >= $this->_docCount) { require_once 'Zend/Search/Lucene/Exception.php'; throw new Zend_Search_Lucene_Exception('Document id is out of the range.'); } $segmentStartId = 0; foreach ($this->_segmentInfos as $segmentInfo) { if ($segmentStartId + $segmentInfo->count() > $id) { break; } $segmentStartId += $segmentInfo->count(); } $fdxFile = $segmentInfo->openCompoundFile('.fdx'); $fdxFile->seek(($id - $segmentStartId) * 8, SEEK_CUR); $fieldValuesPosition = $fdxFile->readLong(); $fdtFile = $segmentInfo->openCompoundFile('.fdt'); $fdtFile->seek($fieldValuesPosition, SEEK_CUR); $fieldCount = $fdtFile->readVInt(); $doc = new Search_Document(); for ($count = 0; $count < $fieldCount; $count++) { $fieldNum = $fdtFile->readVInt(); $bits = $fdtFile->readByte(); $fieldInfo = $segmentInfo->getField($fieldNum); if (!($bits & 2)) { // Text data $field = new Zend_Search_Lucene_Field($fieldInfo->name, $fdtFile->readString(), 'UTF-8', true, $fieldInfo->isIndexed, $bits & 1); } else { // Binary data $field = new Zend_Search_Lucene_Field($fieldInfo->name, $fdtFile->readBinary(), '', true, $fieldInfo->isIndexed, $bits & 1, true); } $doc->addField($field); } return $doc; }
public function updateSolrData() { $searchClient = new Search_SearchClient('http://10.10.6.51:8983/jp-property-v4/'); try { $doc1 = new Search_Document(); $doc1->setUniqueKey('id', 382515); $doc1->setField('match_name', '贸祥大厦1'); $doc1->setField('district_id', 217); $doc1->setField('block_id', 2435); $doc1->setField('address', '东明路与商城路交汇处'); $doc1->setField('is_road', 0); $documents = array($doc1); $result = $searchClient->saveDocuments($documents, true); $b = $searchClient->getRequestUrl(); print_r($b); return $result; } catch (Exception $e) { return $e->__toString() . PHP_EOL; } }
private function updateSolrBuildingData($id, $dataInfo) { $solrApi = APF::get_instance()->get_config('solrJpBuilding', 'service'); $searchClient = new Search_SearchClient($solrApi); try { $doc1 = new Search_Document(); $doc1->setUniqueKey('id', $id); foreach ($dataInfo as $key => $val) { $doc1->setField($key, $val); } $documents = array($doc1); $result = $searchClient->saveDocuments($documents, true); // $b = $searchClient->getRequestUrl(); // print_r($b); return $result; } catch (Exception $e) { return $e->__toString() . PHP_EOL; } }