public function testSearchDocumentIsConvertedIntoSolrFormat()
 {
     $documentFieldName = 'foo';
     $documentFieldValue = 'bar';
     $searchDocumentFieldCollection = SearchDocumentFieldCollection::fromArray([$documentFieldName => $documentFieldValue]);
     $contextPartName = 'baz';
     $contextPartValue = 'qux';
     $context = new SelfContainedContext([$contextPartName => $contextPartValue]);
     $productId = new ProductId(uniqid());
     $searchDocument = new SearchDocument($searchDocumentFieldCollection, $context, $productId);
     $documentUniqueId = sprintf('%s_%s:%s', (string) $productId, $contextPartName, $contextPartValue);
     $expectedSolrDocument = [SolrSearchEngine::DOCUMENT_ID_FIELD_NAME => $documentUniqueId, SolrSearchEngine::PRODUCT_ID_FIELD_NAME => (string) $productId, $documentFieldName => [$documentFieldValue], $contextPartName => $contextPartValue];
     $this->assertSame($expectedSolrDocument, SolrDocumentBuilder::fromSearchDocument($searchDocument));
 }
コード例 #2
0
 public function addDocument(SearchDocument $document)
 {
     $solrDocument = SolrDocumentBuilder::fromSearchDocument($document);
     $this->client->update([$solrDocument]);
 }
 public function testUpdateRequestContainingSolrDocumentsIsSentToHttpClient()
 {
     $searchDocumentFieldCollection = SearchDocumentFieldCollection::fromArray(['foo' => 'bar']);
     $context = new SelfContainedContext(['baz' => 'qux']);
     $productId = new ProductId(uniqid());
     $searchDocument = new SearchDocument($searchDocumentFieldCollection, $context, $productId);
     $expectedSolrDocument = SolrDocumentBuilder::fromSearchDocument($searchDocument);
     $this->mockHttpClient->expects($this->once())->method('update')->with([$expectedSolrDocument]);
     $this->searchEngine->addDocument($searchDocument);
 }