protected function addToSearchQueue(PinholePhoto $photo) { $type = NateGoSearch::getDocumentType($this->app->db, 'photo'); $sql = sprintf('delete from NateGoSearchQueue where document_id = %s and document_type = %s', $this->app->db->quote($photo->id, 'integer'), $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); $sql = sprintf('insert into NateGoSearchQueue (document_id, document_type) values (%s, %s)', $this->app->db->quote($photo->id, 'integer'), $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); }
protected function addToSearchQueue() { $type = NateGoSearch::getDocumentType($this->app->db, 'comment'); if ($type === null) { return; } $sql = sprintf('delete from NateGoSearchQueue where document_id = %s and document_type = %s', $this->app->db->quote($this->comment->id, 'integer'), $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); $sql = sprintf('insert into NateGoSearchQueue (document_id, document_type) values (%s, %s)', $this->app->db->quote($this->comment->id, 'integer'), $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); }
protected function addToSearchQueue($ids) { // this is automatically wrapped in a transaction because it is // called in saveDBData() $type = NateGoSearch::getDocumentType($this->app->db, 'post'); if ($type === null) { return; } $sql = sprintf('delete from NateGoSearchQueue where document_id in (select distinct BlorgComment.post from BlorgComment where BlorgComment.id in (%s)) and document_type = %s', $ids, $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); $sql = sprintf('insert into NateGoSearchQueue (document_id, document_type) select distinct BlorgComment.post, %s from BlorgComment where BlorgComment.id in (%s)', $this->app->db->quote($type, 'integer'), $ids); SwatDB::exec($this->app->db, $sql); }
protected function addToSearchQueue() { // this is automatically wrapped in a transaction because it is // called in saveDBData() $type = NateGoSearch::getDocumentType($this->app->db, 'post'); if ($type === null) { return; } $sql = sprintf('delete from NateGoSearchQueue where document_id = %s and document_type = %s', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); $sql = sprintf('insert into NateGoSearchQueue (document_id, document_type) values (%s, %s)', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote($type, 'integer')); SwatDB::exec($this->app->db, $sql); }
/** * Creates a search indexer with the given document type * * @param string $document_type the shortname of the document type to * index by. * @param MDB2_Driver_Common $db the database connection used by this * indexer. * @param boolean $new if true, this is a new search index and all indexed * words for the given document type are removed. If * false, we are appending to an existing index. * Defaults to false. * @param boolean $append if true, keywords keywords for documents that * are indexed are appended to the keywords that * may already exist for the document in the index. * Defaults to false. * * @see NateGoSearch::createDocumentType() * * @throws NateGoSearchDocumentTypeException if the document type shortname * does not exist. */ public function __construct($document_type, MDB2_Driver_Common $db, $new = false, $append = false) { // cache mb_string overloading status if (self::$use_mb_string === null) { self::$use_mb_string = extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 2) === 2; } $type = NateGoSearch::getDocumentType($db, $document_type); if ($type === null) { throw new NateGoSearchDocumentTypeException("Document type {$document_type} does not exist and cannot be " . "indexed. Document types must be created before being used.", 0, $document_type); } $this->document_type = $type; $this->db = $db; $this->new = $new; $this->append = $append; }
protected function indexComments() { $type_shortname = 'comment'; $spell_checker = new NateGoSearchPSpellSpellChecker('en_US', '', '', $this->getCustomWordList()); $comment_indexer = new NateGoSearchIndexer($type_shortname, $this->db); $comment_indexer->setSpellChecker($spell_checker); $comment_indexer->addTerm(new NateGoSearchTerm('fullname', 30)); $comment_indexer->addTerm(new NateGoSearchTerm('email', 20)); $comment_indexer->addTerm(new NateGoSearchTerm('bodytext', 1)); $comment_indexer->setMaximumWordLength(32); $comment_indexer->addUnindexedWords(NateGoSearchIndexer::getDefaultUnindexedWords()); $type = NateGoSearch::getDocumentType($this->db, $type_shortname); $sql = sprintf('select BlorgComment.* from BlorgComment inner join NateGoSearchQueue on BlorgComment.id = NateGoSearchQueue.document_id and NateGoSearchQueue.document_type = %s order by BlorgComment.id', $this->db->quote($type, 'integer')); $this->debug(Blorg::_('Indexing comments... ') . ' '); $comments = SwatDB::query($this->db, $sql, SwatDBClassMap::get('BlorgCommentWrapper')); $total = count($comments); $count = 0; foreach ($comments as $comment) { $ds = new SwatDetailsStore($comment); if ($count % 10 == 0) { $comment_indexer->commit(); $this->debug(str_repeat(chr(8), 3)); $this->debug(sprintf('%2d%%', $count / $total * 100)); } $document = new NateGoSearchDocument($ds, 'id'); $comment_indexer->index($document); $count++; } $this->debug(str_repeat(chr(8), 3) . Blorg::_('done') . "\n"); $comment_indexer->commit(); unset($comment_indexer); $sql = sprintf('delete from NateGoSearchQueue where document_type = %s', $this->db->quote($type, 'integer')); SwatDB::exec($this->db, $sql); }
protected function indexPhotos() { $spell_checker = new NateGoSearchPSpellSpellChecker('en_US', '', '', $this->getCustomWordList()); $photo_indexer = new NateGoSearchIndexer('photo', $this->db); $photo_indexer->setSpellChecker($spell_checker); $photo_indexer->addTerm(new NateGoSearchTerm('title', 5)); $photo_indexer->addTerm(new NateGoSearchTerm('tags', 2)); $photo_indexer->addTerm(new NateGoSearchTerm('description')); $photo_indexer->setMaximumWordLength(32); $photo_indexer->addUnindexedWords(NateGoSearchIndexer::getDefaultUnindexedWords()); $type = NateGoSearch::getDocumentType($this->db, 'photo'); $sql = sprintf('select PinholePhoto.title, PinholePhoto.id, PinholePhoto.description, PinholePhoto.image_set from PinholePhoto inner join NateGoSearchQueue on PinholePhoto.id = NateGoSearchQueue.document_id and NateGoSearchQueue.document_type = %s order by PinholePhoto.id', $this->db->quote($type, 'integer')); $this->debug(Pinhole::_('Indexing photos ... ') . ' '); $photos = SwatDB::query($this->db, $sql, SwatDBClassMap::get('PinholePhotoWrapper')); $total = count($photos); $count = 0; $current_photo_id = null; foreach ($photos as $photo) { $ds = new SwatDetailsStore($photo); $ds->title = $photo->getTitle(); $tags = ''; foreach ($photo->tags as $tag) { $tags .= ' ' . $tag->title . ' ' . $tag->name; } $ds->tags = $tags; if ($count % 10 == 0) { $photo_indexer->commit(); $this->debug(str_repeat(chr(8), 3)); $this->debug(sprintf('%2d%%', $count / $total * 100)); } $document = new NateGoSearchDocument($ds, 'id'); $photo_indexer->index($document); $current_photo_id = $photo->id; $count++; $sql = sprintf('delete from NateGoSearchQueue where document_type = %s and document_id = %s', $this->db->quote($type, 'integer'), $this->db->quote($photo->id, 'integer')); SwatDB::exec($this->db, $sql); } if (count($photos) > 0 && isset($this->memcache)) { $this->memcache->flushNs('photos'); } $this->debug(str_repeat(chr(8), 3) . Pinhole::_('done') . "\n"); $photo_indexer->commit(); unset($photo_indexer); }
protected function searchPhotos() { $keywords = $this->ui->getWidget('search_keywords')->value; $this->join_clause = ''; $this->order_by_clause = 'PinholePhoto.publish_date desc, PinholePhoto.photo_date asc, PinholePhoto.id'; if (trim($keywords) != '') { $query = new NateGoSearchQuery($this->app->db); $query->addDocumentType('photo'); $query->addBlockedWords(NateGoSearchQuery::getDefaultBlockedWords()); $result = $query->query($keywords); $type = NateGoSearch::getDocumentType($this->app->db, 'photo'); $this->join_clause = sprintf('inner join %1$s on %1$s.document_id = PinholePhoto.id and %1$s.unique_id = %2$s and %1$s.document_type = %3$s', $result->getResultTable(), $this->app->db->quote($result->getUniqueId(), 'text'), $this->app->db->quote($type, 'integer')); $this->order_by_clause = sprintf('%1$s.displayorder1, %1$s.displayorder2, %2$s', $result->getResultTable(), $this->order_by_clause); } }
/** * Adds a document type to be searched by this query * * @param string $type_shortname the shortname of the document type to add. * * @see NateGoSearch::createDocumentType() * * @throws NateGoSearchDocumentTypeException if the document type shortname * does not exist. */ public function addDocumentType($type_shortname) { $type_shortname = (string) $type_shortname; if (!array_key_exists($type_shortname, $this->document_types)) { $type = NateGoSearch::getDocumentType($this->db, $type_shortname); if ($type === null) { throw new NateGoSearchDocumentTypeException("Document type {$type_shortname} does not exist and " . "cannot be added to a query. Document types must be " . "created before being used.", 0, $type_shortname); } $this->document_types[$type_shortname] = $type; } }
/** * Gets the SQL join clauses for this search tag * * If the NateGoSearch feature is enabled, this returns a unique join * statement for the given keyword search results. * * @return array an array of join clauses used by this search tag. */ public function getJoinClauses() { // Ensure joined NateGoSearchResult table is unique even if we have // multiple keyword search tags. static $results_table_id = 1; switch ($this->name) { case 'keywords': $join_clauses = parent::getJoinClauses(); if ($this->value !== null && $this->getPhotoSearchType() !== null) { $query = new NateGoSearchQuery($this->db); $query->addDocumentType($this->getPhotoSearchType()); $query->addBlockedWords(NateGoSearchQuery::getDefaultBlockedWords()); $result = $query->query($this->value); $type = NateGoSearch::getDocumentType($this->db, 'photo'); $join_clauses[] = sprintf('inner join %1$s as %4$s on %4$s.document_id = PinholePhoto.id and %4$s.unique_id = %2$s and %4$s.document_type = %3$s', $result->getResultTable(), $this->db->quote($result->getUniqueId(), 'text'), $this->db->quote($type, 'integer'), $result->getResultTable() . $results_table_id); } $results_table_id++; break; default: $join_clauses = parent::getJoinClauses(); break; } return $join_clauses; }