[pLog-svn] r4679 - in plog/branches/lifetype-1.2/class: dao dao/customfields gallery/dao
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Fri Feb 2 18:31:42 EST 2007
Author: oscar
Date: 2007-02-02 18:31:42 -0500 (Fri, 02 Feb 2007)
New Revision: 4679
Modified:
plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
plog/branches/lifetype-1.2/class/dao/customfields/customfieldsvalues.class.php
plog/branches/lifetype-1.2/class/gallery/dao/galleryalbums.class.php
plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php
Log:
added a fastpath using the FULLTEXT index to all classes that were using LIKE to perform their searches, except the Articles class (it's a bit more complicated and I need some time to look at it)
Modified: plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/commentscommon.class.php 2007-02-02 23:07:45 UTC (rev 4678)
+++ plog/branches/lifetype-1.2/class/dao/commentscommon.class.php 2007-02-02 23:31:42 UTC (rev 4679)
@@ -3,7 +3,7 @@
lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
- lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );
+ lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );
/**
* different orders that comments can have
@@ -18,10 +18,10 @@
define( "COMMENT_TYPE_TRACKBACK", 2 );
define( "COMMENT_TYPE_ANY", -1 );
- /**
+ /**
* \ingroup DAO
*
- * Since comments and trackbacks are now in the same table, this class contains all the
+ * Since comments and trackbacks are now in the same table, this class contains all the
* common code needed to deal with these items. Most of the methods are exactly the same in both
* ArticleComments and Trackbacks except that they take an additional parameter called 'status'
* which can either be
@@ -31,7 +31,7 @@
* - COMMENT_TYPE_ANY
*
* Depending on whether we'd like to retrieve a trackback or a comment.
- */
+ */
class CommentsCommon extends Model
{
@@ -39,55 +39,55 @@
var $blogSettings;
var $timeDiff;
- function CommentsCommon()
- {
- $this->Model();
+ function CommentsCommon()
+ {
+ $this->Model();
$this->table = $this->getPrefix()."articles_comments";
- }
+ }
- /**
- * Adds a comment to an article
+ /**
+ * Adds a comment to an article
*
* @param comment the UserComment object that we're going to add.
* @return Returns true if successful or false if error. Also in case of success, it will modify the UserComment
* object passed by reference and include its new id.
- */
+ */
function addComment( &$comment )
- {
- if(( $result = $this->add( $comment ))) {
- lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ {
+ if(( $result = $this->add( $comment ))) {
+ lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
// update the article comments
$article = $comment->getArticle();
$blog = $article->getBlogInfo();
if( $comment->getType() == COMMENT_TYPE_COMMENT ) {
- $article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().
- ' AND status = '.COMMENT_STATUS_NONSPAM.
- ' AND type = '.$comment->getType()));
- $article->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
+ $article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().
+ ' AND status = '.COMMENT_STATUS_NONSPAM.
+ ' AND type = '.$comment->getType()));
+ $article->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
$blog->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments',
- 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
+ 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
}
else {
- $article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().
- ' AND status = '.COMMENT_STATUS_NONSPAM.
- ' AND type = '.$comment->getType()));
- $article->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
+ $article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().
+ ' AND status = '.COMMENT_STATUS_NONSPAM.
+ ' AND type = '.$comment->getType()));
+ $article->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
$blog->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
- 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
+ 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
}
$articles = new Articles();
$articles->updateArticle( $article );
$blogs = new Blogs();
$blogs->updateBlog( $blog );
- }
- return( $result );
- }
+ }
+ return( $result );
+ }
/**
* Retrieves all the comments for a post
@@ -101,30 +101,30 @@
* @return False if error or an array of ArticleComments objects
*/
function getPostComments( $artid,
- $order = COMMENT_ORDER_NEWEST_FIRST,
- $status = COMMENT_STATUS_ALL,
- $type = COMMENT_TYPE_ANY,
- $page = -1,
- $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+ $order = COMMENT_ORDER_NEWEST_FIRST,
+ $status = COMMENT_STATUS_ALL,
+ $type = COMMENT_TYPE_ANY,
+ $page = -1,
+ $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
if( $order == COMMENT_ORDER_NEWEST_FIRST ){
$order = Array( "date" => "DESC" );
- $cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST;
- }
+ $cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST;
+ }
else{
$order = Array( "date" => "ASC" );
- $cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST;
- }
+ $cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST;
+ }
$comments = $this->getMany( "article_id",
- $artid,
- $cache_item,
- Array(),
- $order,
+ $artid,
+ $cache_item,
+ Array(),
+ $order,
"",
- $page,
- $itemsPerPage );
-
+ $page,
+ $itemsPerPage );
+
$result = Array();
if( $comments ) {
@@ -145,7 +145,7 @@
$result = Array();
- return( $result );
+ return( $result );
}
/**
@@ -169,23 +169,23 @@
return( true );
}
- /**
- * Returns the total number of comments for a post
+ /**
+ * Returns the total number of comments for a post
*
* @param artId the post id
* @param status
* @return The number of comments
- */
- function getNumPostComments( $artId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
- {
- lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
- $numComments = 0;
+ */
+ function getNumPostComments( $artId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
+ {
+ lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ $numComments = 0;
$articles = new Articles();
- $article = $articles->getArticle( $artId );
+ $article = $articles->getArticle( $artId );
- if(!$article)
- return 0;
-
+ if(!$article)
+ return 0;
+
if( $type == COMMENT_TYPE_COMMENT ) {
if( $status == COMMENT_STATUS_ALL ) {
$numComments = $article->getTotalComments();
@@ -197,7 +197,7 @@
$numComments = $article->getTotalComments() - $article->getNumComments();
}
else {
- $numComments = 0;
+ $numComments = 0;
}
}
else if($type == COMMENT_TYPE_TRACKBACK) {
@@ -208,46 +208,46 @@
$numComments = $article->getNumTrackBacks();
}
elseif( $status == COMMENT_STATUS_SPAM ) {
- $numComments = $article->getTotalTrackbacks() - $article->getNumTrackbacks();
+ $numComments = $article->getTotalTrackbacks() - $article->getNumTrackbacks();
}
else {
- $numComments = 0;
+ $numComments = 0;
}
}
- else{
- $numComments = $this->getNumPostComments($artId, $status, COMMENT_TYPE_COMMENT) +
- $this->getNumPostComments($artId, $status, COMMENT_TYPE_TRACKBACK);
- }
+ else{
+ $numComments = $this->getNumPostComments($artId, $status, COMMENT_TYPE_COMMENT) +
+ $this->getNumPostComments($artId, $status, COMMENT_TYPE_TRACKBACK);
+ }
return( $numComments );
- }
-
- /**
- * returns the number of comments that a blog has
- *
- * @param blogId
- * @param status
- * @param type
+ }
+
+ /**
+ * returns the number of comments that a blog has
+ *
+ * @param blogId
+ * @param status
+ * @param type
* @param searchTerms
- * @return The number of comments, or 0 if error or no comments
- */
- function getNumBlogComments( $blogId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY, $searchTerms = "" )
- {
- if( $status == COMMENT_STATUS_ALL && $type != COMMENT_TYPE_ANY && $searchTerms == "" ) {
- // fast case, we can load the blog and query one of its intrinsic fields
- lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
- $blogs = new Blogs();
- $blogInfo = $blogs->getBlogInfo( $blogId );
- if( !$blogInfo )
- $numComments = 0;
- else {
- if( $type == COMMENT_TYPE_COMMENT )
- $numComments = $blogInfo->getTotalComments();
- else
- $numComments = $blogInfo->getTotalTrackbacks();
- }
- }
- else {
+ * @return The number of comments, or 0 if error or no comments
+ */
+ function getNumBlogComments( $blogId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY, $searchTerms = "" )
+ {
+ if( $status == COMMENT_STATUS_ALL && $type != COMMENT_TYPE_ANY && $searchTerms == "" ) {
+ // fast case, we can load the blog and query one of its intrinsic fields
+ lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+ $blogs = new Blogs();
+ $blogInfo = $blogs->getBlogInfo( $blogId );
+ if( !$blogInfo )
+ $numComments = 0;
+ else {
+ if( $type == COMMENT_TYPE_COMMENT )
+ $numComments = $blogInfo->getTotalComments();
+ else
+ $numComments = $blogInfo->getTotalTrackbacks();
+ }
+ }
+ else {
// create the table name
$prefix = $this->getPrefix();
$table = "{$prefix}articles_comments c";
@@ -257,66 +257,66 @@
$cond .= " AND c.status = '".Db::qstr($status)."'";
if( $type != COMMENT_TYPE_ANY )
$cond .= " AND c.type = '".Db::qstr($type)."'";
- if( $searchTerms != "" )
- $cond .= " AND ".$this->getSearchConditions( $searchTerms );
- //print("type = ".$type." - cond = $cond");
+ if( $searchTerms != "" )
+ $cond .= " AND ".$this->getSearchConditions( $searchTerms );
+ //print("type = ".$type." - cond = $cond");
$numComments = $this->getNumItems( $table, $cond );
- }
-
- return( $numComments );
- }
+ }
+
+ return( $numComments );
+ }
/**
* Removes a comment from a post. It also updates all the other posts that
- * have this one as the parent and makes them look as if they were 'top level'
- * comments with no parent.
- *
- * @param artid The article identifier.
- * @param commentid The comment identifier.
+ * have this one as the parent and makes them look as if they were 'top level'
+ * comments with no parent.
+ *
+ * @param artid The article identifier.
+ * @param commentid The comment identifier.
*/
function deleteComment( $commentid )
{
$comment = $this->getComment( $commentid );
- if( $comment ) {
+ if( $comment ) {
$this->delete( "id", $commentid );
- // update all the other posts
- $query = "UPDATE ".$this->getPrefix()."articles_comments SET parent_id = 0 WHERE parent_id = '".
- Db::qstr($commentid)."' AND article_id = '".
+ // update all the other posts
+ $query = "UPDATE ".$this->getPrefix()."articles_comments SET parent_id = 0 WHERE parent_id = '".
+ Db::qstr($commentid)."' AND article_id = '".
Db::qstr( $comment->getArticleId())."'";
- $result = $this->Execute( $query );
- $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
- $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
- $this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
-
- // update the blog and the article counters
- lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
- lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ $result = $this->Execute( $query );
+ $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
+ $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
+ $this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
+
+ // update the blog and the article counters
+ lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
- $article = $comment->getArticle();
- $blog = $article->getBlogInfo();
- $type = $comment->getType();
- if( $type == COMMENT_TYPE_COMMENT ) {
- $article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
- ' AND type = '.$comment->getType()));
- $article->setTotalComments( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
+ $article = $comment->getArticle();
+ $blog = $article->getBlogInfo();
+ $type = $comment->getType();
+ if( $type == COMMENT_TYPE_COMMENT ) {
+ $article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
+ ' AND type = '.$comment->getType()));
+ $article->setTotalComments( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
$blog->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments',
- 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
- }
- else {
- $article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
- ' AND type = '.$comment->getType()));
- $article->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
+ 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
+ }
+ else {
+ $article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
+ ' AND type = '.$comment->getType()));
+ $article->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
$blog->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
- 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
- }
- $blogs = new Blogs();
- $blogs->updateBlog( $blog );
- $articles = new Articles();
- $articles->updateArticle( $article );
+ 'blog_id = '.$blog->getId().' AND type = '.$comment->getType()));
+ }
+ $blogs = new Blogs();
+ $blogs->updateBlog( $blog );
+ $articles = new Articles();
+ $articles->updateArticle( $article );
}
else {
return false;
@@ -325,15 +325,15 @@
return( true );
}
- /**
- * Updates a comment. It also takes into account status changes and updates counters in
- * the blogs and articles table accordingly.
- *
- * @param comment An UserComment object
- * @return true if update successful or false otherwise.
- */
- function updateComment( $comment )
- {
+ /**
+ * Updates a comment. It also takes into account status changes and updates counters in
+ * the blogs and articles table accordingly.
+ *
+ * @param comment An UserComment object
+ * @return true if update successful or false otherwise.
+ */
+ function updateComment( $comment )
+ {
// we need to undo the time offset before updating the comment, or else the comment will be saved
// with the time offset applied
$blogInfo = $comment->getBlogInfo();
@@ -344,41 +344,41 @@
$comment->setDate( $newDate );
}
- if(($result = $this->update( $comment ))) {
- // reset the cache
- $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
- $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
- $this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
- // update counters in the articles table according to the status
- lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
- $articles = new Articles();
- // load the article
- $article = $comment->getArticle();
- if( $comment->getType() == COMMENT_TYPE_COMMENT ) {
- $article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
- ' AND type = '.$comment->getType()));
- $article->setTotalComments( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
- }
- elseif( $comment->getType() == COMMENT_TYPE_TRACKBACK ) {
- $article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
- ' AND type = '.$comment->getType()));
- $article->setTotalTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
- 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
- }
- $articles->updateArticle( $article );
- }
+ if(($result = $this->update( $comment ))) {
+ // reset the cache
+ $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
+ $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
+ $this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
+ // update counters in the articles table according to the status
+ lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ $articles = new Articles();
+ // load the article
+ $article = $comment->getArticle();
+ if( $comment->getType() == COMMENT_TYPE_COMMENT ) {
+ $article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
+ ' AND type = '.$comment->getType()));
+ $article->setTotalComments( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
+ }
+ elseif( $comment->getType() == COMMENT_TYPE_TRACKBACK ) {
+ $article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
+ ' AND type = '.$comment->getType()));
+ $article->setTotalTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments',
+ 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
+ }
+ $articles->updateArticle( $article );
+ }
// this is not the cleanest solution but it will do the trick for now...
if( $blogOffset != 0 ) {
$newDate = Timestamp::getDateWithOffset( $comment->getDate(), $blogOffset );
$comment->setDate( $newDate );
}
-
- return( $result );
- }
+
+ return( $result );
+ }
/**
* returns a single comment, identified by its identifier
@@ -412,7 +412,7 @@
* @return An array of ArticleComment objects
*/
function getBlogComments( $blogId,
- $order = COMMENT_ORDER_NEWEST_FIRST,
+ $order = COMMENT_ORDER_NEWEST_FIRST,
$status = COMMENT_STATUS_ALL,
$type = COMMENT_TYPE_ANY,
$searchTerms = "",
@@ -425,10 +425,10 @@
*/
$prefix = $this->getPrefix();
$query = "SELECT c.*
- FROM {$prefix}articles_comments c
- WHERE c.blog_id = '".Db::qstr( $blogId )."'";
- if( $status != COMMENT_STATUS_ALL )
- $query .= " AND status = $status";
+ FROM {$prefix}articles_comments c
+ WHERE c.blog_id = '".Db::qstr( $blogId )."'";
+ if( $status != COMMENT_STATUS_ALL )
+ $query .= " AND status = $status";
if( $type != COMMENT_TYPE_ANY )
$query .= " AND type = '".Db::qstr($type)."'";
if( $searchTerms != "" ) {
@@ -447,20 +447,20 @@
return false;
if( $result->RowCount() == 0 ){
- $result->Close();
+ $result->Close();
return Array();
- }
+ }
$comments = Array();
$articles = new Articles();
while( $row = $result->FetchRow()) {
$comments[] = $this->mapRow( $row );
}
- $result->Close();
+ $result->Close();
/*if( $page > -1 && $amount > -1 )
- $comments = array_slice( $comments, ($page-1) * $amount, $amount );*/
-
+ $comments = array_slice( $comments, ($page-1) * $amount, $amount );*/
+
return( $comments );
}
@@ -470,35 +470,35 @@
*/
function mapRow( $row )
{
- require_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
- require_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ require_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
+ require_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
- $prefix = $this->getPrefix();
- $date = $row["date"];
- $articleId = $row["article_id"];
- $blogId = $row["blog_id"];
-
- $blogs = new Blogs();
- $blogInfo = $blogs->getBlogInfo( $blogId );
- $blogSettings = $blogInfo->getSettings();
- $timeDiff = $blogSettings->getValue( "time_offset" );
+ $prefix = $this->getPrefix();
+ $date = $row["date"];
+ $articleId = $row["article_id"];
+ $blogId = $row["blog_id"];
- $date = Timestamp::getDateWithOffset( $date, $timeDiff );
+ $blogs = new Blogs();
+ $blogInfo = $blogs->getBlogInfo( $blogId );
+ $blogSettings = $blogInfo->getSettings();
+ $timeDiff = $blogSettings->getValue( "time_offset" );
+
+ $date = Timestamp::getDateWithOffset( $date, $timeDiff );
- $comment = new UserComment( $row["article_id"],
- $row['blog_id'],
- $row["parent_id"],
- $row["topic"],
- $row["text"],
- $date,
- $row["user_name"],
- $row["user_email"],
- $row["user_url"],
- $row["client_ip"],
- $row["spam_rate"],
- $row["status"],
- unserialize($row["properties"]),
- $row["id"] );
+ $comment = new UserComment( $row["article_id"],
+ $row['blog_id'],
+ $row["parent_id"],
+ $row["topic"],
+ $row["text"],
+ $date,
+ $row["user_name"],
+ $row["user_email"],
+ $row["user_url"],
+ $row["client_ip"],
+ $row["spam_rate"],
+ $row["status"],
+ unserialize($row["properties"]),
+ $row["id"] );
// set the normalized text and topic
$comment->setNormalizedText( $row['normalized_text'] );
@@ -506,7 +506,7 @@
$comment->setType( $row['type'] );
$comment->setUserId( $row['user_id'] );
- return $comment;
+ return $comment;
}
/**
@@ -520,19 +520,26 @@
$query = SearchEngine::adaptSearchString($searchTerms);
- // MARKWU: I also need to take care when there are multiplu search term
+ // MARKWU: I also need to take care when there are multiplu search term
- // Split the search term by space
- $query_array = explode(' ',$query);
+ // Split the search term by space
+ $query_array = explode(' ',$query);
- // For each search terms, I should make a like query for it
- $where_string = "(";
- $where_string .= "((c.normalized_topic LIKE '%{$query_array[0]}%') OR (c.normalized_text LIKE '%{$query_array[0]}%'))";
- for ( $i = 1; $i < count($query_array); $i = $i + 1) {
- $where_string .= " AND ((c.normalized_topic LIKE '%{$query_array[$i]}%') OR (c.normalized_text LIKE '%{$query_array[$i]}%'))";
- }
- $where_string .= " OR ((c.normalized_topic LIKE '%{$query}%') OR (c.normalized_text LIKE '%{$query}%'))";
- $where_string .= ")";
+ $db =& Db::getDb();
+ if( $db->isFullTextSupported()) {
+ // fast path used when FULLTEXT searches are supported
+ $where_string = "(MATCH(c.normalized_text) AGAINST ('{$query}' IN BOOLEAN MODE))";
+ }
+ else {
+ // old and slower path for those cases when they are not
+ $where_string = "(";
+ $where_string .= "((c.normalized_topic LIKE '%{$query_array[0]}%') OR (c.normalized_text LIKE '%{$query_array[0]}%'))";
+ for ( $i = 1; $i < count($query_array); $i = $i + 1) {
+ $where_string .= " AND ((c.normalized_topic LIKE '%{$query_array[$i]}%') OR (c.normalized_text LIKE '%{$query_array[$i]}%'))";
+ }
+ $where_string .= " OR ((c.normalized_topic LIKE '%{$query}%') OR (c.normalized_text LIKE '%{$query}%'))";
+ $where_string .= ")";
+ }
return( $where_string );
}
Modified: plog/branches/lifetype-1.2/class/dao/customfields/customfieldsvalues.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/customfields/customfieldsvalues.class.php 2007-02-02 23:07:45 UTC (rev 4678)
+++ plog/branches/lifetype-1.2/class/dao/customfields/customfieldsvalues.class.php 2007-02-02 23:31:42 UTC (rev 4679)
@@ -148,15 +148,24 @@
$query = SearchEngine::adaptSearchString($searchTerms);
- $query_array = explode(' ',$query);
+ $query_array = explode(' ',$query);
- $where_string = "(";
- $where_string .= "(v.normalized_value LIKE '%{$query_array[0]}%')";
- for ( $i = 1; $i < count($query_array); $i = $i + 1) {
- $where_string .= " AND ((v.normalized_value LIKE '%{$query_array[$i]}%'))";
- }
- $where_string .= " OR (v.normalized_value LIKE '%{$query}%')";
- $where_string .= ")";
+ $db =& Db::getDb();
+ if( $db->isFullTextSupported()) {
+ // fast path used when FULLTEXT searches are supported
+ $where_string = "(MATCH(c.normalized_value) AGAINST ('{$query}' IN BOOLEAN MODE))";
+ }
+ else {
+ $where_string = "(";
+ $where_string .= "(v.normalized_value LIKE '%{$query_array[0]}%')";
+ for ( $i = 1; $i < count($query_array); $i = $i + 1) {
+ $where_string .= " AND ((v.normalized_value LIKE '%{$query_array[$i]}%'))";
+ }
+ $where_string .= " OR (v.normalized_value LIKE '%{$query}%')";
+ $where_string .= ")";
+ }
+
+ print($where_string);
return( $where_string );
}
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryalbums.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryalbums.class.php 2007-02-02 23:07:45 UTC (rev 4678)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryalbums.class.php 2007-02-02 23:31:42 UTC (rev 4679)
@@ -408,7 +408,15 @@
*/
function getSearchConditions( $searchTerms )
{
- return( "name LIKE '%".Db::qstr( $searchTerms )."%' OR normalized_description LIKE '%".Db::qstr( $searchTerms )."%'" );
+ $db =& Db::getDb();
+ if( $db->isFullTextSupported()) {
+ $query = "MATCH(normalized_name,normalized_description) AGAINST ('{$searchTerms}')";
+ }
+ else {
+ $query = "name LIKE '%".Db::qstr( $searchTerms )."%' OR normalized_description LIKE '%".Db::qstr( $searchTerms )."%'";
+ }
+
+ return( $query );
}
/**
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php 2007-02-02 23:07:45 UTC (rev 4678)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php 2007-02-02 23:31:42 UTC (rev 4679)
@@ -851,7 +851,20 @@
*/
function getSearchConditions( $searchTerms )
{
- return( "file_name LIKE '%".Db::qstr( $searchTerms )."%' OR normalized_description LIKE '%".Db::qstr( $searchTerms )."%'" );
+ $query = "file_name LIKE '%".Db::qstr( $searchTerms )."%'";
+
+ // search the text via the existing FULLTEXT index
+ $db =& Db::getDb();
+ if( $db->isFullTextSupported()) {
+ $query .= " OR MATCH(normalized_description) AGAINST ('{$searchTerms}')";
+ }
+ else {
+ $query .= " OR normalized_description LIKE '%".Db::qstr( $searchTerms )."%'";
+ }
+
+ print($query);
+
+ return( $query );
}
/**
More information about the pLog-svn
mailing list