コード例 #1
0
ファイル: DocumentTest.php プロジェクト: nubs/solarium
 public function testNoEscapeAddField()
 {
     $this->doc->setFilterControlCharacters(false);
     $this->doc->setField('foo', $value1 = 'bar' . chr(15));
     $this->doc->addField('foo', $value2 = 'bar' . chr(15) . chr(8));
     $this->assertEquals(array($value1, $value2), $this->doc->foo);
 }
コード例 #2
0
 public function testSetAndGetFieldsUsingModifiersWithoutKey()
 {
     $this->doc->clear();
     $this->doc->setField('id', 1);
     $this->doc->setField('name', 'newname', null, Document::MODIFIER_SET);
     $this->setExpectedException('Solarium\\Exception\\RuntimeException');
     $this->doc->getFields();
 }
コード例 #3
0
 /**
  * @test
  */
 public function adapterPrepareUpdateReturnsSolariumDocument()
 {
     $object = new SolariumUpdateDocument();
     $object->setField('id', 5);
     $object->setField('type', $this->type);
     /* @var $preparedObject SolariumUpdateDocument */
     $preparedObject = $this->adapter->prepareUpdate($object);
     $this->assertInstanceOf(SolariumUpdateDocument::class, $preparedObject);
     $this->assertEquals(5, $preparedObject->offsetGet('id'));
     $this->assertEquals($this->type, $preparedObject->offsetGet('type'));
 }
コード例 #4
0
 public function testBuildAddXmlWithFieldModifiersAndMultivalueFields()
 {
     $doc = new Document();
     $doc->setKey('id', 1);
     $doc->addField('category', 123, null, Document::MODIFIER_ADD);
     $doc->addField('category', 234, null, Document::MODIFIER_ADD);
     $doc->addField('name', 'test', 2.3, Document::MODIFIER_SET);
     $doc->setField('stock', 2, null, Document::MODIFIER_INC);
     $command = new AddCommand();
     $command->addDocument($doc);
     $this->assertEquals('<add>' . '<doc>' . '<field name="id">1</field>' . '<field name="category" update="add">123</field>' . '<field name="category" update="add">234</field>' . '<field name="name" boost="2.3" update="set">test</field>' . '<field name="stock" update="inc">2</field>' . '</doc>' . '</add>', $this->builder->buildAddXml($command));
 }
コード例 #5
0
 /**
  * Helper method for indexing.
  *
  * Adds $value with field name $key to the document $doc. The format of $value
  * is the same as specified in
  * \Drupal\search_api\Backend\BackendSpecificInterface::indexItems().
  */
 protected function addIndexField(Document $doc, $key, $key_single, $values, $type)
 {
     // Don't index empty values (i.e., when field is missing).
     if (!isset($values)) {
         return;
     }
     // All fields.
     foreach ($values as $value) {
         switch ($type) {
             case 'boolean':
                 $value = $value ? 'true' : 'false';
                 break;
             case 'date':
                 $value = is_numeric($value) ? (int) $value : strtotime($value);
                 if ($value === FALSE) {
                     return;
                 }
                 $value = format_date($value, 'custom', self::SOLR_DATE_FORMAT, 'UTC');
                 break;
             case 'integer':
                 $value = (int) $value;
                 break;
             case 'decimal':
                 $value = (double) $value;
                 break;
         }
         // For tokenized text, add each word separately.
         if ($type == 'tokenized_text' && is_array($value)) {
             foreach ($value as $tokenizd_value) {
                 // @todo Score is tracked by key, not for each value, how to handle
                 //   this?
                 $doc->addField($key, $tokenizd_value['value'], $tokenizd_value['score']);
             }
         } else {
             $doc->addField($key, $value);
         }
     }
     $field_value = $doc->{$key};
     $first_value = is_array($field_value) ? reset($field_value) : $field_value;
     if ($type == 'tokenized_text' && is_array($first_value) && isset($first_value['value'])) {
         $first_value = $first_value['value'];
     }
     $doc->setField($key_single, $first_value);
 }