/** * Add a document to the index * * @param unique_id str: the song's unique id * @param song_name str: song name * @param artist_name str: artist name * @param artist_name str: album name * @param genre_name str: genre name * @param tags str: any other tags/words to describe the track * @return bol: true on success */ public function doAddDocument($unique_id, $song_name, $artist_name, $album_name, $genre_name, $tags = null) { $boost = false; $doc = new sfLuceneDocument(); $doc->setField('song_name', strtolower($song_name), $boost); $doc->setField('artist_name', strtolower($artist_name), $boost); $doc->setField('album_name', strtolower($album_name), $boost); $doc->setField('genre_name', strtolower($genre_name), $boost); $doc->setField('tags', strtolower($tags), $boost); $doc->setField('sfl_guid', $unique_id); $this->service->addDocument($doc); unset($doc); return true; }
/** * Builds the fields into the document as configured by the parameters. */ protected function configureDocumentFields(sfLuceneDocument $doc) { $properties = $this->getModelProperties(); // loop through each field foreach ($properties->get('fields')->getNames() as $field) { $field_properties = $properties->get('fields')->get($field); $value = $this->getFieldValue($field, $field_properties); // do not index null value if ($value === null || is_array($value) && empty($value)) { continue; } $type = $field_properties->get('type'); $boost = $field_properties->get('boost'); // validate value to make sure we can really index this if (is_object($value) && method_exists($value, '__toString')) { $value = $value->__toString(); } elseif (is_null($value)) { $value = ''; } elseif (is_array($value) && $field_properties->get('multiValued')) { // nothing to do ;) } elseif (!is_scalar($value)) { throw new sfLuceneIndexerException('Field value returned is not a string (got a ' . gettype($value) . ' ) and it could be casted to a string for field ' . $field); } // handle a possible transformation function if ($transform = $field_properties->get('transform')) { if (!is_callable($transform)) { throw new sfLuceneIndexerException('Transformation function ' . $transform . ' does not exist'); } } elseif ($type === 'boolean') { $transform = array($this, 'forceBooleanString'); } if (!is_array($value)) { $value = array($value); } foreach ($value as $pos => $v) { if ($transform) { $value[$pos] = call_user_func($transform, $v); } } $doc->setField($field, $value, $boost); } return $doc; }
/** * Adds a document to the index while attaching a GUID */ protected function addDocument(sfLuceneDocument $document, $guid) { $document->setField('sfl_guid', $guid); $timer = sfTimerManager::getTimer('Solr Search Lucene'); $this->getSearch()->getLucene()->addDocument($document); $timer->addTime(); }