[pLog-svn] r3157 - plog/trunk/class/dao
mark at devel.lifetype.net
mark at devel.lifetype.net
Wed Mar 29 17:31:00 GMT 2006
Author: mark
Date: 2006-03-29 17:31:00 +0000 (Wed, 29 Mar 2006)
New Revision: 3157
Modified:
plog/trunk/class/dao/searchengine.class.php
plog/trunk/class/dao/searchresult.class.php
Log:
Fix some error in search engine and also add two new functions to search engine:
1. SearchBlogs: It can allow us to search blog name
2. SearchGalleryResources: It can allow us to search gallery
Do we need SearchAlbums?? Maybe SearchGalleryResources is enough.
Modified: plog/trunk/class/dao/searchengine.class.php
===================================================================
--- plog/trunk/class/dao/searchengine.class.php 2006-03-29 17:25:55 UTC (rev 3156)
+++ plog/trunk/class/dao/searchengine.class.php 2006-03-29 17:31:00 UTC (rev 3157)
@@ -3,7 +3,12 @@
include_once( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/searchresult.class.php" );
-
+ include_once( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
+
+ define( "SEARCH_ARTICLE", 1 );
+ define( "SEARCH_BLOG", 2 );
+ define( "SEARCH_GALLERYRESOURCE", 3 );
+
/**
* \ingroup DAO
*
@@ -104,9 +109,29 @@
* @see searchCustomFields
* @see searchComments
*/
- function siteSearch( $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
+ function siteSearch( $searchTerms, $searchType, $status = -1)
{
- return $this->search( -1, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 );
+ switch ( $searchType )
+ {
+ case SEARCH_ARTICLE:
+ if ( $status == -1 )
+ $status = POST_STATUS_PUBLISHED;
+ $result = $this->search( -1, $searchTerms, $status );
+ break;
+ case SEARCH_BLOG:
+ if ( $status == -1 )
+ $status = BLOG_STATUS_ACTIVE;
+ $result = $this->searchBlogs( $searchTerms, $status );
+ break;
+ case SEARCH_GALLERYRESOURCE:
+ $result = $this->searchGalleryResources( '_all_', $searchTerms );
+ break;
+ default:
+ if ( $status == -1 )
+ $status = POST_STATUS_PUBLISHED;
+ $result = $this->search( -1, $searchTerms, $status );
+ }
+ return $result;
}
/**
@@ -196,7 +221,6 @@
*/
function searchBlogComments( $blogId, $searchTerms, $postStatus = POST_STATUS_PUBLISHED )
{
- include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
$comments = new ArticleComments();
$commentsResult = $comments->getBlogComments( $blogId, // blog id
@@ -218,6 +242,58 @@
return( $results );
}
+
+ /**
+ * Returns an array of SearchResult objects containing information about the search, such as the
+ * relevance (not very relevant, though :)), and the BlogObject
+ *
+ * @param searchTerms The query string we'd like to use.
+ * @return An array of SearchResult objects
+ */
+ function searchBlogs( $searchTerms, $blogStatus = BLOG_STATUS_ACTIVE )
+ {
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+
+ $blogs = new Blogs();
+ $blogsResult = $blogs->getAllBlogs( $blogStatus,
+ $searchTerms,
+ -1,
+ DEFAULT_ITEMS_PER_PAGE );
+
+ $results = Array();
+ foreach( $blogsResult as $blog ) {
+ $results[] = new SearchResult( $blog, SEARCH_RESULT_ARTICLE, $searchTerms );
+ }
+
+ return( $results );
+ }
+
+ /**
+ * Returns an array of SearchResult objects containing information about the search, such as the
+ * relevance (not very relevant, though :)), and the GalleryResourceObject
+ *
+ * @param searchTerms The query string we'd like to use.
+ * @return An array of SearchResult objects
+ */
+ function searchGalleryResources( $ownerId, $searchTerms )
+ {
+ include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
+
+ $galleryResources = new GalleryResources();
+ $galleryResourcesResult = $galleryResources->getUserResources( $ownerId,
+ GALLERY_NO_ALBUM,
+ GALLERY_RESOURCE_ANY,
+ $searchTerms,
+ $page = -1,
+ DEFAULT_ITEMS_PER_PAGE );
+
+ $results = Array();
+ foreach( $galleryResourcesResult as $galleryResource ) {
+ $results[] = new SearchResult( $galleryResource, SEARCH_RESULT_GALLERYRESOURCE, $searchTerms );
+ }
+
+ return( $results );
+ }
/**
* Filters duplicated or triplicated results.
Modified: plog/trunk/class/dao/searchresult.class.php
===================================================================
--- plog/trunk/class/dao/searchresult.class.php 2006-03-29 17:25:55 UTC (rev 3156)
+++ plog/trunk/class/dao/searchresult.class.php 2006-03-29 17:31:00 UTC (rev 3157)
@@ -5,6 +5,8 @@
define( "SEARCH_RESULT_ARTICLE", 1 );
define( "SEARCH_RESULT_CUSTOM_FIELD", 2 );
define( "SEARCH_RESULT_COMMENT", 3 );
+ define( "SEARCH_RESULT_BLOG", 4 );
+ define( "SEARCH_RESULT_GALLERYRESOURCE", 5 );
/**
* represents a result from a search query.
More information about the pLog-svn
mailing list