Exemple #1
0
 public function testAddFieldWithBoostMultipliesWithAPreexistingBoost()
 {
     $field = 'field';
     $boost = 0.5;
     // set a field with a boost
     $this->_fixture->setField($field, 'value1', $boost);
     // now add another value with the same boost
     $this->_fixture->addField($field, 'value2', $boost);
     // new boost should be $boost * $boost
     $this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field));
 }
Exemple #2
0
 /**
  * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
  *
  * @return string
  */
 protected function _documentToXmlFragment(Apache_Solr_Document $document)
 {
     $xml = '<doc';
     if ($document->getBoost() !== false) {
         $xml .= ' boost="' . $document->getBoost() . '"';
     }
     $xml .= '>';
     foreach ($document as $key => $value) {
         $key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
         $fieldBoost = $document->getFieldBoost($key);
         if (is_array($value)) {
             foreach ($value as $multivalue) {
                 $xml .= '<field name="' . $key . '"';
                 if ($fieldBoost !== false) {
                     $xml .= ' boost="' . $fieldBoost . '"';
                     // only set the boost for the first field in the set
                     $fieldBoost = false;
                 }
                 $multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
                 $xml .= '>' . $multivalue . '</field>';
             }
         } else {
             $xml .= '<field name="' . $key . '"';
             if ($fieldBoost !== false) {
                 $xml .= ' boost="' . $fieldBoost . '"';
             }
             $value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
             $xml .= '>' . $value . '</field>';
         }
     }
     $xml .= '</doc>';
     // replace any control characters to avoid Solr XML parser exception
     return $this->_stripCtrlChars($xml);
 }
 /**
  * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
  *
  * @return string
  */
 protected function _documentToXmlFragment(Apache_Solr_Document $document)
 {
     $xml = '<doc';
     if ($document->getBoost() !== false) {
         $xml .= ' boost="' . $document->getBoost() . '"';
     }
     $xml .= '>';
     foreach ($document as $key => $value) {
         $key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
         $fieldBoost = $document->getFieldBoost($key);
         if ($key) {
             if (is_array($value)) {
                 foreach ($value as $multivalue) {
                     $xml .= '<field name="' . $key . '"';
                     if ($fieldBoost !== false) {
                         $xml .= ' boost="' . $fieldBoost . '"';
                         // only set the boost for the first field in the set
                         $fieldBoost = false;
                     }
                     if (!mb_check_encoding($multivalue, 'UTF-8')) {
                         $multivalue = utf8_encode($multivalue);
                     }
                     $multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
                     $xml .= '>' . $multivalue . '</field>';
                 }
             } else {
                 $xml .= '<field name="' . $key . '"';
                 if ($fieldBoost !== false) {
                     $xml .= ' boost="' . $fieldBoost . '"';
                 }
                 if (!mb_check_encoding($value, 'UTF-8')) {
                     $value = utf8_encode($value);
                 }
                 $value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
                 $xml .= '>' . $value . '</field>';
             }
         }
     }
     $xml .= '</doc>';
     return $xml;
 }