Example #1
0
 /**
  * Create an XML fragment from a {@link Document} instance appropriate for use inside a Solr add call
  *
  * @return string
  */
 protected function _documentToXmlFragment(Document $document)
 {
     $xml = '<doc';
     if ($document->getBoost() !== false) {
         $xml .= ' boost="' . $document->getBoost() . '"';
     }
     $xml .= '>';
     foreach ($document as $key => $item) {
         $key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
         $fieldBoost = $document->getFieldBoost($key);
         if (!is_array($item)) {
             $item = array($item);
         }
         foreach ($item as $multivalue) {
             if (!is_array($multivalue)) {
                 $multivalue = array($multivalue);
             }
             foreach ($multivalue as $value) {
                 $xml .= '<field name="' . $key . '"';
                 if ($fieldBoost !== false) {
                     $xml .= ' boost="' . $fieldBoost . '"';
                     // only set the boost for the first field in the set
                     $fieldBoost = false;
                 }
                 $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);
 }
Example #2
0
 /**
  * Builds the item's index key.
  *
  * Takes the form extension.view.id, E.g. com_content.article.1.
  *
  * The key can be customized by overriding this method but it is not
  * recommended.
  *
  * @param \JSolr\Apache\Solr\Document $document The document to use to build the
  * key.
  *
  * @return string The item's key.
  */
 protected function buildKey($document)
 {
     $type = $document->getField('context');
     $type = JArrayHelper::getValue($type, 'value');
     $type = JArrayHelper::getValue($type, 0);
     $id = $document->getField('id');
     $id = JArrayHelper::getValue($id, 'value');
     $id = JArrayHelper::getValue($id, 0);
     return $type . '.' . $id;
 }