/**
  * This indexes something that implements Mixin_ElementText into a Solr Document.
  *
  * @param array                $fields The fields to index.
  * @param Mixin_ElementText    $item   The item containing the element texts.
  * @param Apache_Solr_Document $doc    The document to index everything into.
  * @return void
  * @author Eric Rochester <*****@*****.**>
  **/
 public static function indexItem($fields, $item, $doc)
 {
     foreach ($item->getAllElementTexts() as $text) {
         $field = $fields->findByText($text);
         // Set text field.
         if ($field->is_indexed) {
             $doc->setMultiValue($field->indexKey(), $text->text);
         }
         // Set string field.
         if ($field->is_facet) {
             $doc->setMultiValue($field->facetKey(), $text->text);
         }
     }
 }
Example #2
0
 /**
  * 
  * @param Apache_Solr_Document or Array $parts
  * 
  * @return SP_Controller_Action_Helper_Solr
  */
 public function pushDocuments($parts)
 {
     $this->_setSolrService();
     if ($parts instanceof Apache_Solr_Document) {
         $this->documents[] = $parts;
     } else {
         if (is_array($parts)) {
             foreach ($parts as $item => $fields) {
                 if ($fields instanceof Apache_Solr_Document) {
                     $this->documents[] = $fields;
                 } else {
                     $part = new Apache_Solr_Document();
                     foreach ($fields as $key => $value) {
                         if (is_array($value)) {
                             foreach ($value as $datum) {
                                 $part->setMultiValue($key, $datum);
                             }
                         } else {
                             $part->setField($key, $value);
                         }
                     }
                     $this->documents[] = $part;
                 }
             }
         } else {
             trigger_error("the paramter \$part must be an object of Apache_Solr_Document or an array");
         }
     }
     return $this;
 }
Example #3
0
 public function addDocument($data)
 {
     $document = new Apache_Solr_Document();
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $datum) {
                 if (is_numeric($datum)) {
                     number_format($datum);
                 }
                 $document->setMultiValue($key, $datum);
             }
         } else {
             if (is_numeric($value)) {
                 number_format($value);
             }
             $document->{$key} = $value;
         }
     }
     try {
         $rs = $this->_solrService->addDocument($document);
         // asynchronous commit
         // $this->_solrService->commit(true);
         return $rs;
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Example #4
0
 public function addDocuments($datas)
 {
     $documents = array();
     foreach ($datas as $item => $fields) {
         $part = new Apache_Solr_Document();
         foreach ($fields as $key => $value) {
             if (is_array($value)) {
                 foreach ($value as $datum) {
                     $part->setMultiValue($key, $datum);
                 }
             } else {
                 $part->{$key} = $value;
             }
         }
         $documents[] = $part;
     }
     try {
         $rs = $this->_solrService->addDocuments($documents);
         // asynchronous commit
         //$this->_solrService->commit(true);
         return $rs;
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Example #5
0
 /**
  *	setMultiValue has been deprecated and defers to addField
  *
  *	@deprecated
  */
 public function testSetMultiValueCreatesMultiValueWhenFieldDoesExistAsSingleValue()
 {
     $field = 'field';
     $value1 = 'value1';
     $value2 = 'value2';
     // set first value as singular value
     $this->_fixture->{$field} = $value1;
     // add a second value with addField
     $this->_fixture->setMultiValue($field, $value2);
     // check that value is an array with correct values
     $fieldValue = $this->_fixture->{$field};
     $this->assertTrue(is_array($fieldValue));
     $this->assertEquals(2, count($fieldValue));
     $this->assertEquals($value1, $fieldValue[0]);
     $this->assertEquals($value2, $fieldValue[1]);
 }
 public function cromSolar($id, $caso = null)
 {
     $adapter = $this->tableGateway->getAdapter();
     $sql = new Sql($adapter);
     $selecttot = $sql->select()->from('ta_plato')->join(array('c' => 'ta_comentario'), 'c.ta_plato_in_id=ta_plato.in_id', array('cantidad' => new \Zend\Db\Sql\Expression('COUNT(c.in_id)')), 'left')->join('ta_tipo_plato', 'ta_plato.ta_tipo_plato_in_id=ta_tipo_plato.in_id ', array('tipo_plato_nombre' => 'va_nombre'), 'left')->join(array('pl' => 'ta_plato_has_ta_local'), 'pl.Ta_plato_in_id = ta_plato.in_id', array(), 'left')->join(array('tl' => 'ta_local'), 'tl.in_id = pl.Ta_local_in_id', array('latitud' => 'de_latitud', 'longitud' => 'de_longitud', 'direccion' => 'va_direccion', 'telefono' => 'va_telefono'), 'left')->join(array('tr' => 'ta_restaurante'), 'tr.in_id = tl.ta_restaurante_in_id', array('restaurant_nombre' => 'va_nombre', 'restaurant_estado' => 'en_estado'), 'left')->join(array('tc' => 'ta_tipo_comida'), 'tc.in_id = tr.Ta_tipo_comida_in_id', array('nombre_tipo_comida' => 'va_nombre_tipo'), 'left')->join(array('tu' => 'ta_ubigeo'), 'tu.in_id = tl.ta_ubigeo_in_id', array('distrito' => 'ch_distrito', 'departamento' => 'ch_departamento'), 'left')->where(array('ta_plato.in_id' => $id));
     $selecttot->group('ta_plato.in_id');
     $selectString = $sql->getSqlStringForSqlObject($selecttot);
     $results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
     $plato = $results->toArray();
     $selectto = $sql->select()->from('ta_plato')->join(array('tpt' => 'ta_plato_has_ta_tag'), 'tpt.Ta_plato_in_id = ta_plato.in_id', array('tag_id' => 'ta_tag_in_id'), 'left')->join(array('tt' => 'ta_tag'), 'tt.in_id =tpt.ta_tag_in_id', array('tag' => 'va_nombre'), 'left')->where(array('ta_plato.in_id' => $id));
     $selectStrin = $sql->getSqlStringForSqlObject($selectto);
     $result = $adapter->query($selectStrin, $adapter::QUERY_MODE_EXECUTE);
     $tag = $result->toArray();
     $solr = \Classes\Solr::getInstance()->getSolr();
     if ($solr->ping()) {
         if ($caso !== 1) {
             $solr->deleteByQuery('id:' . $id);
         }
         $document = new \Apache_Solr_Document();
         $document->id = $id;
         $document->name = $plato[0]['va_nombre'];
         $document->tx_descripcion = $plato[0]['tx_descripcion'];
         $document->va_precio = $plato[0]['va_precio'];
         $document->en_estado = $plato[0]['en_estado'];
         $document->plato_tipo = $plato[0]['tipo_plato_nombre'];
         $document->va_direccion = $plato[0]['direccion'];
         $document->restaurante = $plato[0]['restaurant_nombre'];
         $document->tipo_comida = $plato[0]['nombre_tipo_comida'];
         $document->en_destaque = $plato[0]['en_destaque'];
         $document->va_telefono = $plato[0]['telefono'];
         $document->latitud = $plato[0]['latitud'];
         $document->longitud = $plato[0]['longitud'];
         $document->departamento = $plato[0]['departamento'];
         foreach ($tag as $resultado) {
             $document->setMultiValue('tag', $resultado['tag']);
         }
         $document->distrito = $plato[0]['distrito'];
         $document->va_imagen = $plato[0]['va_imagen'];
         $document->comentarios = $plato[0]['cantidad'];
         $document->restaurant_estado = $plato[0]['restaurant_estado'];
         $document->puntuacion = $plato[0]['Ta_puntaje_in_id'];
         $solr->addDocument($document);
         $solr->commit();
     }
 }
Example #7
0
function db_store_article($article, $PageID = 0, $updating = false)
{
    global $db;
    global $config;
    $update = false;
    $id = 0;
    // If we are editing an existing reference then we already know its id
    if (isset($article->reference_id)) {
        $id = $article->reference_id;
    } else {
        $id = db_find_article($article);
    }
    if ($id != 0) {
        if ($updating) {
            $update = true;
        } else {
            return $id;
        }
    }
    // Try and trap empty references
    if ($id == 0) {
        $ok = false;
        if (isset($article->title)) {
            $ok = $article->title != '';
        }
        if (!$ok) {
            return 0;
        }
    }
    if (!isset($article->genre)) {
        $article->genre = 'article';
    }
    $keys = array();
    $values = array();
    // Article metadata
    foreach ($article as $k => $v) {
        switch ($k) {
            // Ignore as it's an array
            case 'authors':
                break;
            case 'date':
                $keys[] = 'date';
                $values[] = $db->qstr($v);
                if (!isset($article->year)) {
                    $keys[] = 'year';
                    $values[] = $db->qstr(year_from_date($v));
                }
                break;
                // Don't store BHL URL here
            // Don't store BHL URL here
            case 'url':
                if (preg_match('/^http:\\/\\/(www\\.)?biodiversitylibrary.org\\/page\\/(?<pageid>[0-9]+)/', $v)) {
                } else {
                    // extract Handle if it exists
                    if (preg_match('/^http:\\/\\/hdl.handle.net\\/(?<hdl>.*)$/', $v, $m)) {
                        $keys[] = 'hdl';
                        $values[] = $db->qstr($m['hdl']);
                    } else {
                        $keys[] = $k;
                        $values[] = $db->qstr($v);
                    }
                }
                break;
                // Things we store as is
            // Things we store as is
            case 'title':
            case 'secondary_title':
            case 'volume':
            case 'series':
            case 'issue':
            case 'spage':
            case 'epage':
            case 'year':
            case 'date':
            case 'issn':
            case 'genre':
            case 'doi':
            case 'hdl':
            case 'lsid':
            case 'oclc':
            case 'pdf':
            case 'abstract':
            case 'pmid':
                $keys[] = $k;
                $values[] = $db->qstr($v);
                break;
                // Things we ignore
            // Things we ignore
            default:
                break;
        }
    }
    // Date
    if (!isset($article->date) && isset($article->year)) {
        $keys[] = 'date';
        $values[] = $db->qstr($article->year . '-00-00');
    }
    // BHL PageID
    if ($PageID != 0) {
        $keys[] = 'PageID';
        $values[] = $PageID;
    }
    // SICI
    $s = new Sici();
    $sici = $s->create($article);
    if ($sici != '') {
        $keys[] = 'sici';
        $values[] = $db->qstr($sici);
    }
    if ($update) {
        // Versioning?
        // Delete links	(author, pages, etc)
        // Don't delete page range as we may loose plates, etc. outside range
        /*
        $sql = 'DELETE FROM rdmp_reference_page_joiner WHERE reference_id=' . $id;
        $result = $db->Execute($sql);
        if ($result == false) die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        */
        $sql = 'DELETE FROM rdmp_author_reference_joiner WHERE reference_id = ' . $id;
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        // update (updated timestamp will be automatically updated)
        $sql = 'UPDATE rdmp_reference SET ';
        $num_values = count($keys);
        for ($i = 0; $i < $num_values; $i++) {
            if ($i > 0) {
                $sql .= ', ';
            }
            $sql .= $keys[$i] . '=' . $values[$i];
        }
        $sql .= ' WHERE reference_id=' . $id;
        /*		$cache_file = @fopen('/tmp/update.sql', "w+") or die("could't open file");
        		@fwrite($cache_file, $sql);
        		fclose($cache_file);
        */
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
    } else {
        // Adding article for first time so add 'created' and 'updated' timestamp
        $keys[] = 'created';
        $values[] = 'NOW()';
        $keys[] = 'updated';
        $values[] = 'NOW()';
        $sql = 'INSERT INTO rdmp_reference (' . implode(",", $keys) . ') VALUES (' . implode(",", $values) . ')';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        $id = $db->Insert_ID();
        // Store reference_cluster_id which we can use to group duplicates, by default
        // reference_cluster_id = reference_id
        $sql = 'UPDATE rdmp_reference SET reference_cluster_id=' . $id . ' WHERE reference_id=' . $id;
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
    }
    // Indexing-------------------------------------------------------------------------------------
    if (1) {
        // solr
        // this code is redundant with code in reference.php but I use different objects
        // here and there (doh!). Also once we've added old stuff to solr this is the only place we
        // should be calling solr
        $solr = new Apache_Solr_Service('localhost', '8983', '/solr');
        if (!$solr->ping()) {
            echo 'Solr service not responding.';
            exit;
        }
        $item = array();
        $item['id'] = 'reference/' . $id;
        $item['title'] = $article->title;
        $item['publication_outlet'] = $article->secondary_title;
        $item['year'] = $article->year;
        $authors = array();
        foreach ($article->authors as $a) {
            $authors[] = $a->forename . ' ' . $a->surname;
        }
        $item['authors'] = $authors;
        $citation = '';
        $citation .= ' ' . $article->year;
        $citation .= ' ' . $article->title;
        $citation .= ' ' . $article->secondary_title;
        $citation .= ' ' . $article->volume;
        if (isset($article->issue)) {
            $citation .= '(' . $article->issue . ')';
        }
        $citation .= ':';
        $citation .= ' ';
        $citation .= $article->spage;
        if (isset($article->epage)) {
            $citation .= '-' . $article->epage;
        }
        $item['citation'] = $citation;
        $text = '';
        $num_authors = count($article->authors);
        $count = 0;
        if ($num_authors > 0) {
            foreach ($article->authors as $author) {
                $text .= $author->forename . ' ' . $author->lastname;
                if (isset($author->suffix)) {
                    $text .= ' ' . $author->suffix;
                }
                $count++;
                if ($count == 2 && $num_authors > 3) {
                    $text .= ' et al.';
                    break;
                }
                if ($count < $num_authors - 1) {
                    $text .= ', ';
                } else {
                    if ($count < $num_authors) {
                        $text .= ' and ';
                    }
                }
            }
        }
        $item['citation'] = $text . ' ' . $citation;
        $parts = array();
        $parts[] = $item;
        //print_r($parts);
        // add to solr
        $documents = array();
        foreach ($parts as $item => $fields) {
            $part = new Apache_Solr_Document();
            foreach ($fields as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $datum) {
                        $part->setMultiValue($key, $datum);
                    }
                } else {
                    $part->{$key} = $value;
                }
            }
            $documents[] = $part;
        }
        //
        //
        // Load the documents into the index
        //
        try {
            $solr->addDocuments($documents);
            $solr->commit();
            $solr->optimize();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    } else {
        $sql = 'DELETE FROM rdmp_text_index WHERE (object_uri=' . $db->qstr($config['web_root'] . 'reference/' . $id) . ')';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        // Only do this if we have a title, as sometimes we don't (e.g. CrossRef lacks metadata)
        if (isset($article->title)) {
            $sql = 'INSERT INTO rdmp_text_index(object_type, object_id, object_uri, object_text)
			VALUES ("title"' . ', ' . $id . ', ' . $db->qstr($config['web_root'] . 'reference/' . $id) . ', ' . $db->qstr($article->title) . ')';
            $result = $db->Execute($sql);
            if ($result == false) {
                die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
            }
        }
    }
    // Versioning-----------------------------------------------------------------------------------
    // Store this object in version table so we can recover it if we overwrite item
    $ip = getip();
    $sql = 'INSERT INTO rdmp_reference_version(reference_id, ip, json) VALUES(' . $id . ', ' . 'INET_ATON(\'' . $ip . '\')' . ',' . $db->qstr(json_encode($article)) . ')';
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    // Author(s)------------------------------------------------------------------------------------
    // Store author as and link to the article
    if (isset($article->authors)) {
        db_store_authors($id, $article->authors);
    }
    // Store page range (only if not updating, otherwise we may loose plates, etc.
    // that aren't in page range)
    if ($PageID != 0 && !$update) {
        $page_range = array();
        if (isset($article->spage) && isset($article->epage)) {
            $page_range = bhl_page_range($PageID, $article->epage - $article->spage + 1);
        } else {
            // No epage, so just get spage (to do: how do we tell user we don't have page range?)
            $page_range = bhl_page_range($PageID, 0);
        }
        //print_r($page_range);
        $count = 0;
        foreach ($page_range as $page) {
            $sql = 'INSERT INTO rdmp_reference_page_joiner (reference_id, PageID, page_order) 
			VALUES (' . $id . ',' . $page . ',' . $count++ . ')';
            $result = $db->Execute($sql);
            if ($result == false) {
                die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
            }
        }
    }
    // Tweet----------------------------------------------------------------------------------------
    if (!$update) {
        if ($config['twitter']) {
            $url = $config['web_root'] . 'reference/' . $id . ' ' . '#bhlib';
            // url + hashtag
            $url_len = strlen($url);
            $status = '';
            if (isset($article->title)) {
                $status = $article->title;
                $status_len = strlen($status);
                $extra = 140 - $status_len - $url_len - 1;
                if ($extra < 0) {
                    $status_len += $extra;
                    $status_len -= 1;
                    $status = substr($status, 0, $status_len);
                    $status .= '…';
                }
            }
            $status .= ' ' . $url;
            tweet($status);
        }
    }
    return $id;
}
<?php

require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(2, limeade_output::get());
$t->diag('document format a document');
$document = new Apache_Solr_Document();
$document->setBoost(10);
$document->setField('sfl_guid', 'GUID_1234');
$document->setField('name', 'Thomas Rabaix', 1);
$document->setMultiValue('skills', 'php');
$document->setMultiValue('skills', 'symfony');
$document->addField('skills', 'objective-c');
$expected = array('name' => 'skills', 'value' => array(0 => 'php', 1 => 'symfony', 2 => 'objective-c'), 'boost' => false);
$t->cmp_ok($document->getField('skills'), '==', $expected, '::getField test multivalue setter');
$expected = array('name' => 'name', 'value' => 'Thomas Rabaix', 'boost' => 1);
$t->cmp_ok($document->getField('name'), '==', $expected, '::getField test setter');
Example #9
0
     			$item['citation'] = reference_authors_to_text_string($reference)
     				. ' ' . $reference->year 
     				. ' ' . $reference->title
     				. ' ' . reference_to_citation_text_string($reference);
     */
     print_r($item);
     $parts[] = $item;
 }
 print_r($parts);
 $documents = array();
 foreach ($parts as $item => $fields) {
     $part = new Apache_Solr_Document();
     foreach ($fields as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $datum) {
                 $part->setMultiValue($key, $datum);
             }
         } else {
             $part->{$key} = $value;
         }
     }
     $documents[] = $part;
 }
 //
 //
 // Load the documents into the index
 //
 try {
     $solr->addDocuments($documents);
     $solr->commit();
     $solr->optimize();
 /**
  * This indexes something that implements Mixin_ElementText into a Solr Document.
  *
  * @param array                $fields The fields to index.
  * @param Mixin_ElementText    $item   The item containing the element texts.
  * @param Apache_Solr_Document $doc    The document to index everything into.
  * @return void
  * @author Eric Rochester <*****@*****.**>
  **/
 public static function indexItem($fields, $item, $doc)
 {
     foreach ($item->getAllElementTexts() as $text) {
         $field = $fields->findByText($text);
         // MAKE SURE EVERYTHING IS INDEXED! AND THAT ALL DATA IS FACETED, BUT NOT SHOWN AS A FACET
         if ($field->element_id == '39') {
             if (self::get_elements_private_status_by_value($text->text, "Title", 4)) {
                 //                    _log("ANONIMOUS VERTELLER: " . $text->text);
                 $doc->setMultiValue($field->indexKey(), "anoniem");
                 //anonymous for public
                 $doc->setMultiValue($field->facetKey(), "anoniem");
                 $doc->setMultiValue($field->indexKey() . "_admin", $text->text);
                 $doc->setMultiValue($field->facetKey() . "_admin", $text->text);
             } else {
                 $doc->setMultiValue($field->indexKey(), $text->text);
                 $doc->setMultiValue($field->facetKey(), $text->text);
                 $doc->setMultiValue($field->indexKey() . "_admin", $text->text);
                 $doc->setMultiValue($field->facetKey() . "_admin", $text->text);
             }
         } elseif ($field->element_id == '60') {
             if (self::get_elements_private_status_by_value($text->text, "Title", 9) || self::get_elements_private_status_by_value($text->text, "Title", 4)) {
                 //                    _log("ANONIMOUS VERZAMELAAR: " . $text->text);
                 $doc->setMultiValue($field->indexKey(), "anoniem");
                 //anonymous for public
                 $doc->setMultiValue($field->facetKey(), "anoniem");
                 $doc->setMultiValue($field->indexKey() . "_admin", $text->text);
                 $doc->setMultiValue($field->facetKey() . "_admin", $text->text);
             } else {
                 $doc->setMultiValue($field->indexKey(), $text->text);
                 $doc->setMultiValue($field->facetKey(), $text->text);
                 $doc->setMultiValue($field->indexKey() . "_admin", $text->text);
                 $doc->setMultiValue($field->facetKey() . "_admin", $text->text);
             }
         } else {
             //if there are no special privacy problems:
             // Set text field.
             if ($field->is_indexed) {
                 $doc->setMultiValue($field->indexKey(), $text->text);
             }
             // Set string field.
             // ADJUST: MAKE AN EXTRA SETTING FOR SHOWING FACETS IN SEQUENCE ->SET ALL TO IS_FACET
             if ($field->is_facet) {
                 $doc->setMultiValue($field->facetKey(), $text->text);
             }
         }
     }
 }
Example #11
0
 /**
  * Полностью подготавливаем документ книги для solr, с жанрами, авторами и всем прочим.
  * Ресурсоемко, использовать только демоном
  * @param Book $book
  */
 public function prepareBookFull(Book $book)
 {
     $fields = array("id" => '', "id_main_file" => '', "quality" => '', "year" => '', "mark" => '', "rating" => '', "book_type" => '', "download_count" => '', "title" => '', "subtitle" => '', "keywords" => '', "is_cover" => 'bool', "is_duplicate" => 'bool', "is_deleted" => 'bool', "is_blocked" => 'bool', "is_public" => 'bool');
     if (!$book->loaded) {
         return false;
     }
     $document = new Apache_Solr_Document();
     foreach ($fields as $name => $type) {
         if (isset($book->data[$name])) {
             if ($type == 'bool') {
                 $document->{$name} = $book->data[$name] > 0 ? 1 : 0;
             } else {
                 $document->{$name} = $book->data[$name];
             }
         }
     }
     // правообладатели - списочком
     if ($this->rightHolders === null) {
         $this->loadRightHolders();
     }
     $document->rightholder = $this->rightHolders[$book->data['id_rightholder']]['title'];
     // авторы
     $authors = $book->getAuthors();
     foreach ($authors as $author) {
         $document->setMultiValue("author", $author['first_name'] . ' ' . $author['last_name'] . ' ' . $author['middle_name'] . ' ');
     }
     // жанры
     $genres = $book->getGenres();
     foreach ($genres as $genre) {
         $document->setMultiValue("genre", $genre['title']);
     }
     // серии
     $series = $book->getSeries();
     foreach ($series as $serie) {
         $document->setMultiValue("serie", $serie['title']);
     }
     return $document;
 }
     } elseif ($col == 'approvedByCounselDate') {
         $recordsArray[$col] = $value;
     } elseif ($col == 'recordCode') {
         $recordsArray[$col] = $value;
     }
 }
 // place record set into 'records' array
 $solrData['records'] = $recordsArray;
 // build solr XML using recordsArray values
 $documents = array();
 foreach ($solrData as $item => $fields) {
     $record = new Apache_Solr_Document();
     foreach ($fields as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $datum) {
                 $record->setMultiValue($key, $datum);
             }
         } else {
             $record->{$key} = $value;
         }
     }
     $documents[] = $record;
 }
 //
 //
 // Load the documents into the solr index
 //
 try {
     $solr->addDocuments($documents);
     $solr->commit();
     $solr->optimize();
Example #13
0
  public function solrStore($contact) {

    $doc = new Apache_Solr_Document();

    $doc->setField('id', $contact->id);
    $doc->setField('timecreate', $contact->timecreate->format('Y-m-d\TH:i:s\Z'));
    $doc->setField('timeupdate', $contact->timeupdate->format('Y-m-d\TH:i:s\Z'));
    $doc->setField('usercreate', $contact->usercreate);
    $doc->setField('userupdate', $contact->userupdate);
    $doc->setField('datasource', $contact->datasource_id);
    $doc->setField('domain', $GLOBALS['obm']['domain_id']);
    $doc->setField('in', $contact->addressbook);
    $doc->setField('addressbookId', $contact->addressbook_id);
    $doc->setField('company', $contact->company);
    $doc->setField('companyId', $contact->company_id);
    $doc->setField('commonname', $contact->commonname);
    $doc->setField('lastname', $contact->lastname);
    $doc->setField('firstname', $contact->firstname);
    $doc->setField('middlename', $contact->mname);
    $doc->setField('sortable', $contact->lastname." ".$contact->firstname);
    $doc->setField('suffix', $contact->suffix);
    $doc->setField('aka', $contact->aka);
    $doc->setField('kind', $contact->kind);
    //$doc->setField('kind', $db->f('kind_header'));
    $doc->setField('manager', $contact->manager);
    $doc->setField('assistant', $contact->assistant);
    $doc->setField('spouse', $contact->spouse);
    $doc->setField('birthdayId', $contact->birthday_event);
    $doc->setField('anniversaryId', $contact->anniversary_event);
    if($contact->birthday) $doc->setField('birthday', $contact->birthday->format('Y-m-d\TH:i:s\Z'));
    if($contact->anniversary) $doc->setField('anniversary', $contact->anniversary->format('Y-m-d\TH:i:s\Z'));
    $doc->setField('category', $contact->category);
    foreach($contact->categories as $category) {
      foreach($category as $c) {
        $doc->setMultiValue('categoryId', $c['id']);
      }
    }
    $doc->setField('service', $contact->service);
    $doc->setField('function', $contact->function);
    $doc->setField('title', $contact->title);
    if ($contact->archive) {
      $doc->setField('is', 'archive');
    }
    if ($contact->collected) {
      $doc->setField('is', 'collected');
    }
    if ($contact->mailok) {
      $doc->setField('is', 'mailing');
    }        
    if ($contact->newsletter) {
      $doc->setField('is', 'newsletter');
    }
    if($contact->date) $doc->setField('date', $contact->date->format('Y-m-d\TH:i:s\Z'));
    $doc->setField('comment', $contact->comment);
    $doc->setField('comment2', $contact->comment2);
    $doc->setField('comment3', $contact->comment3);
    $doc->setField('from', $contact->origin);

    foreach($contact->email as $email) {
      $doc->setMultiValue('email', $email['address']);
    }

    foreach($contact->phone as $phone) {
      $doc->setMultiValue('phone', $phone['number']);
    }

    foreach($contact->im as $im) {
      $doc->setMultiValue('jabber', $im['address']);
    }

    foreach($contact->address as $address) {
      $doc->setMultiValue('street', $address['street']);
      $doc->setMultiValue('zipcode', $address['zipcode']);
      $doc->setMultiValue('expresspostal', $address['expresspostal']);
      $doc->setMultiValue('town', $address['town']);
      $doc->setMultiValue('country', $address['country']);
    }

    if($contact->hasACalendarUrl()){
      $doc->setField('hasACalendar', "true");
    }
    else {
      $doc->setField('hasACalendar', "false");
    }

    OBM_IndexingService::store('contact', array($doc));
  }