/** * On rebuild of the search index, rebuild all user records * * @param type $event */ public static function onSearchRebuild($event) { foreach (User::model()->findAll() as $obj) { HSearch::getInstance()->addModel($obj); print "u"; } }
/** * Returns the singleton instance of this class * * @return HSearch */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
public function afterDelete($event) { if ($this->getOwner() instanceof ISearchable) { HSearch::getInstance()->deleteModel($this->getOwner()); } parent::afterDelete($event); }
public function run($args) { $this->printHeader('Search Index Optimizer'); print "- Optimizing ...\n"; HSearch::getInstance()->optimize(); print "- Search Index successfully optimized!\n"; print "\n"; }
/** * Reindex Lucene records from the * provided Model */ public function actionReindex() { $model_str = Yii::app()->request->getParam('model'); $model = new $model_str(); foreach ($model::model()->findAll() as $record) { HSearch::getInstance()->deleteModel($record); $record->save(); } }
/** * On rebuild of the search index, rebuild all space records * * @param type $event */ public static function onSearchRebuild($event) { foreach (Space::model()->findAll() as $obj) { if ($obj->visibility != Space::VISIBILITY_NONE) { HSearch::getInstance()->addModel($obj); } print "s"; } }
public function run($args) { $this->printHeader('Rebuild Search Index\\n'); print "Deleting old index files: "; HSearch::getInstance()->flushIndex(); print " done!\n"; print "Rebuilding index: "; HSearch::getInstance()->rebuild(); print " done!\n"; print "\n"; }
/** * Returns a workspace list by json * * It can be filtered by by keyword. */ public function actionSearchJson() { $keyword = Yii::app()->request->getParam('keyword', ""); // guid of user/workspace $page = (int) Yii::app()->request->getParam('page', 1); // current page (pagination) $limit = (int) Yii::app()->request->getParam('limit', HSetting::Get('paginationSize')); // current page (pagination) $keyword = Yii::app()->input->stripClean($keyword); $hitCount = 0; $query = "model:Space "; if (strlen($keyword) > 2) { // Include Keyword if (strpos($keyword, "@") === false) { $keyword = str_replace(".", "", $keyword); $query .= "AND (title:" . $keyword . "* OR tags:" . $keyword . "*)"; } } //, $limit, $page $hits = new ArrayObject(HSearch::getInstance()->Find($query)); $hitCount = count($hits); // Limit Hits $hits = new LimitIterator($hits->getIterator(), ($page - 1) * $limit, $limit); $json = array(); #$json['totalHits'] = $hitCount; #$json['limit'] = $limit; #$results = array(); foreach ($hits as $hit) { $doc = $hit->getDocument(); $model = $doc->getField("model")->value; if ($model == "Space") { $workspaceId = $doc->getField('pk')->value; $workspace = Space::model()->findByPk($workspaceId); if ($workspace != null) { $wsInfo = array(); $wsInfo['guid'] = $workspace->guid; $wsInfo['title'] = CHtml::encode($workspace->name); $wsInfo['tags'] = CHtml::encode($workspace->tags); $wsInfo['image'] = $workspace->getProfileImage()->getUrl(); $wsInfo['link'] = $workspace->getUrl(); #$results[] = $wsInfo; $json[] = $wsInfo; } else { Yii::log("Could not load workspace with id " . $userId . " from search index!", CLogger::LEVEL_ERROR); } } else { Yii::log("Got no workspace hit from search index!", CLogger::LEVEL_ERROR); } } #$json['results'] = $results; print CJSON::encode($json); Yii::app()->end(); }
/** * After Save Addons * * @return type */ public function afterSave() { parent::afterSave(); if ($this->isNewRecord) { $activity = Activity::CreateForContent($this); $activity->type = "QuestionCreated"; $activity->module = "questionanswer"; $activity->save(); $activity->fire(); } HSearch::getInstance()->addModel($this); return true; }
/** * Run method for CronRunner * * @param type $args */ public function run($args) { $this->printHeader('Cron Interface'); if (!isset($args[0]) || $args[0] != "daily" && $args[0] != 'hourly') { print "\n Run with parameter:\n" . "\t daily - for Daily Interval\n" . "\t hourly - for Hourly Interval \n"; print "\n\n"; exit; } // Set current interval to attribute if ($args[0] == 'daily') { $this->interval = self::INTERVAL_DAILY; } elseif ($args[0] == 'hourly') { $this->interval = self::INTERVAL_HOURLY; } else { throw new CException(500, 'Invalid cron interval!'); } // Do some base tasks, handle by event in future if ($this->interval == self::INTERVAL_HOURLY) { // Raise Event for Module specific tasks if ($this->hasEventHandler('onHourlyRun')) { $this->onHourlyRun(new CEvent($this)); } print "- Optimizing Search Index\n"; // Optimize Search Index HSearch::getInstance()->Optimize(); if (HSetting::Get('enabled', 'authentication_ldap') && HSetting::Get('refreshUsers', 'authentication_ldap')) { print "- Updating LDAP Users\n"; HLdap::getInstance()->refreshUsers(); } print "- Invoking EMailing hourly\n\n"; // Execute Hourly Mailing Runner Yii::import('application.commands.shell.EMailing.*'); $command = new EMailing('test', 'test'); $command->run(array('hourly')); HSetting::Set('cronLastHourlyRun', time()); } elseif ($this->interval == self::INTERVAL_DAILY) { // Raise Event for Module specific tasks if ($this->hasEventHandler('onDailyRun')) { $this->onDailyRun(new CEvent($this)); } // Execute Daily Mailing Runner print "- Invoking EMailing daily\n\n"; Yii::import('application.commands.shell.EMailing.*'); $command = new EMailing('test', 'test'); $command->run(array('daily')); HSetting::Set('cronLastDailyRun', time()); } }
/** * On rebuild of the search index, rebuild all user records * * @param type $event */ public static function onSearchRebuild($event) { foreach (Question::model()->findAll() as $obj) { HSearch::getInstance()->addModel($obj); print "q"; } foreach (Tag::model()->findAll() as $obj) { HSearch::getInstance()->addModel($obj); print "t"; } foreach (Answer::model()->findAll() as $obj) { HSearch::getInstance()->addModel($obj); print "a"; } foreach (Comment::model()->findAll() as $obj) { HSearch::getInstance()->addModel($obj); print "c"; } }
/** * Setup some inital database settings. * * This will be done at the first step. */ private function setupInitialData() { // Seems database is already initialized if (HSetting::Get('paginationSize') == 10) { return; } // Rebuild Search HSearch::getInstance()->rebuild(); HSetting::Set('baseUrl', Yii::app()->getBaseUrl(true)); HSetting::Set('paginationSize', 10); HSetting::Set('displayNameFormat', '{profile.firstname} {profile.lastname}'); // Authentication HSetting::Set('authInternal', '1', 'authentication'); HSetting::Set('authLdap', '0', 'authentication'); HSetting::Set('needApproval', '0', 'authentication_internal'); HSetting::Set('anonymousRegistration', '1', 'authentication_internal'); HSetting::Set('internalUsersCanInvite', '1', 'authentication_internal'); // Mailing HSetting::Set('transportType', 'php', 'mailing'); HSetting::Set('systemEmailAddress', '*****@*****.**', 'mailing'); HSetting::Set('systemEmailName', 'My Social Network', 'mailing'); HSetting::Set('receive_email_activities', User::RECEIVE_EMAIL_DAILY_SUMMARY, 'mailing'); HSetting::Set('receive_email_notifications', User::RECEIVE_EMAIL_WHEN_OFFLINE, 'mailing'); // File HSetting::Set('maxFileSize', '1048576', 'file'); HSetting::Set('forbiddenExtensions', 'exe', 'file'); // Caching HSetting::Set('type', 'CFileCache', 'cache'); HSetting::Set('expireTime', '3600', 'cache'); HSetting::Set('installationId', md5(uniqid("", true)), 'admin'); // Design HSetting::Set('theme', "HumHub"); // Basic HSetting::Set('enable', 1, 'tour'); // Add Categories $cGeneral = new ProfileFieldCategory(); $cGeneral->title = "General"; $cGeneral->sort_order = 100; $cGeneral->visibility = 1; $cGeneral->is_system = true; $cGeneral->description = ''; $cGeneral->save(); $cCommunication = new ProfileFieldCategory(); $cCommunication->title = "Communication"; $cCommunication->sort_order = 200; $cCommunication->visibility = 1; $cCommunication->is_system = true; $cCommunication->description = ''; $cCommunication->save(); $cSocial = new ProfileFieldCategory(); $cSocial->title = "Social bookmarks"; $cSocial->sort_order = 300; $cSocial->visibility = 1; $cSocial->is_system = true; $cSocial->description = ''; $cSocial->save(); // Add Fields $field = new ProfileField(); $field->internal_name = "firstname"; $field->title = 'Firstname'; $field->sort_order = 100; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->ldap_attribute = 'givenName'; $field->is_system = true; $field->required = true; $field->show_at_registration = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "lastname"; $field->title = 'Lastname'; $field->sort_order = 200; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->ldap_attribute = 'sn'; $field->show_at_registration = true; $field->required = true; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "title"; $field->title = 'Title'; $field->sort_order = 300; $field->ldap_attribute = 'title'; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "gender"; $field->title = 'Gender'; $field->sort_order = 300; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeSelect'; $field->is_system = true; if ($field->save()) { $field->fieldType->options = "male=>Male\nfemale=>Female\ncustom=>Custom"; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "street"; $field->title = 'Street'; $field->sort_order = 400; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 150; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "zip"; $field->title = 'Zip'; $field->sort_order = 500; $field->profile_field_category_id = $cGeneral->id; $field->is_system = true; $field->field_type_class = 'ProfileFieldTypeText'; if ($field->save()) { $field->fieldType->maxLength = 10; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "city"; $field->title = 'City'; $field->sort_order = 600; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "country"; $field->title = 'Country'; $field->sort_order = 700; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "state"; $field->title = 'State'; $field->sort_order = 800; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "birthday"; $field->title = 'Birthday'; $field->sort_order = 900; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeBirthday'; $field->is_system = true; if ($field->save()) { $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "about"; $field->title = 'About'; $field->sort_order = 900; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeTextArea'; $field->is_system = true; if ($field->save()) { #$field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "phone_private"; $field->title = 'Phone Private'; $field->sort_order = 100; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "phone_work"; $field->title = 'Phone Work'; $field->sort_order = 200; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "mobile"; $field->title = 'Mobile'; $field->sort_order = 300; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "fax"; $field->title = 'Fax'; $field->sort_order = 400; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_skype"; $field->title = 'Skype Nickname'; $field->sort_order = 500; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_msn"; $field->title = 'MSN'; $field->sort_order = 600; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_icq"; $field->title = 'ICQ Number'; $field->sort_order = 700; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeNumber'; $field->is_system = true; if ($field->save()) { $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_xmpp"; $field->title = 'XMPP Jabber Address'; $field->sort_order = 800; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'email'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url"; $field->title = 'Url'; $field->sort_order = 100; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_facebook"; $field->title = 'Facebook URL'; $field->sort_order = 200; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_linkedin"; $field->title = 'LinkedIn URL'; $field->sort_order = 300; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_xing"; $field->title = 'Xing URL'; $field->sort_order = 400; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_youtube"; $field->title = 'Youtube URL'; $field->sort_order = 500; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_vimeo"; $field->title = 'Vimeo URL'; $field->sort_order = 600; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_flickr"; $field->title = 'Flickr URL'; $field->sort_order = 700; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_myspace"; $field->title = 'MySpace URL'; $field->sort_order = 800; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_googleplus"; $field->title = 'Google+ URL'; $field->sort_order = 900; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_twitter"; $field->title = 'Twitter URL'; $field->sort_order = 1000; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = 'ProfileFieldTypeText'; $field->is_system = true; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $group = new Group(); $group->name = "Users"; $group->description = "Example Group by Installer"; $group->save(); }
/** * Before Delete of a User * */ public function beforeDelete() { // We don't allow deletion of users who owns a space - validate that foreach (SpaceMembership::GetUserSpaces($this->id) as $workspace) { if ($workspace->isSpaceOwner($this->id)) { throw new Exception("Tried to delete a user which is owner of a space!"); } } UserSetting::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); // Delete Profile Image $this->getProfileImage()->delete(); // Delete all pending invites UserInvite::model()->deleteAllByAttributes(array('user_originator_id' => $this->id)); Follow::model()->deleteAllByAttributes(array('user_id' => $this->id)); Follow::model()->deleteAllByAttributes(array('object_model' => 'User', 'object_id' => $this->id)); // Delete all group admin assignments GroupAdmin::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Delete wall entries WallEntry::model()->deleteAllByAttributes(array('wall_id' => $this->wall_id)); // Deletes all content created by this user foreach (Content::model()->findAllByAttributes(array('user_id' => $this->id)) as $content) { $content->delete(); } foreach (Content::model()->findAllByAttributes(array('created_by' => $this->id)) as $content) { $content->delete(); } // Delete all passwords foreach (UserPassword::model()->findAllByAttributes(array('user_id' => $this->id)) as $password) { $password->delete(); } return parent::beforeDelete(); }
/** * Before deleting a SIContent try to delete all corresponding SIContentAddons. */ public function beforeDelete() { // delete also all wall entries foreach ($this->getWallEntries() as $entry) { $entry->delete(); } // remove from search index if ($this->object_model instanceof ISearchable) { HSearch::getInstance()->deleteModel($this->getContentObject()); } // Remove From User Content UserContent::model()->deleteAllByAttributes(array('object_model' => $this->object_model, 'object_id' => $this->object_id)); // Try delete the underlying object (Post, Question, Task, ...) if ($this->getUnderlyingObject() !== null) { $this->getUnderlyingObject()->delete(); } return parent::beforeDelete(); }
/** * JSON Search interface for Mentioning */ public function actionMentioning() { $results = array(); $keyword = Yii::app()->request->getParam('keyword', ""); $keyword = Yii::app()->input->stripClean(trim($keyword)); if (strlen($keyword) >= 3) { $hits = new ArrayObject(HSearch::getInstance()->Find($keyword . "* AND (model:User OR model:Space)")); $hitCount = count($hits); $hits = new LimitIterator($hits->getIterator(), 0, 10); foreach ($hits as $hit) { $doc = $hit->getDocument(); $model = $doc->getField('model')->value; $pk = $doc->getField('pk')->value; $object = $model::model()->findByPk($pk); if ($object !== null && $object instanceof HActiveRecordContentContainer) { $result = array(); $result['guid'] = $object->guid; if ($object instanceof Space) { $result['name'] = CHtml::encode($object->name); $result['type'] = 's'; } elseif ($object instanceof User) { $result['name'] = CHtml::encode($object->displayName); $result['type'] = 'u'; } $result['image'] = $object->getProfileImage()->getUrl(); $result['link'] = $object->getUrl(); $results[] = $result; } } } print CJSON::encode($results); }
/** * After Save Addons * * @return type */ protected function afterSave() { HSearch::getInstance()->addModel($this); return parent::afterSave(); }
/** * Before deletion of a Space */ protected function beforeDelete() { foreach (SpaceSetting::model()->findAllByAttributes(array('space_id' => $this->id)) as $spaceSetting) { $spaceSetting->delete(); } // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); $this->getProfileImage()->delete(); // Remove all Follwers UserFollow::model()->deleteAllByAttributes(array('object_id' => $this->id, 'object_model' => 'Space')); //Delete all memberships: //First select, then delete - done to make sure that SpaceMembership::beforeDelete() is triggered $spaceMemberships = SpaceMembership::model()->findAllByAttributes(array('space_id' => $this->id)); foreach ($spaceMemberships as $spaceMembership) { $spaceMembership->delete(); } UserInvite::model()->deleteAllByAttributes(array('space_invite_id' => $this->id)); // Delete all content objects of this space foreach (Content::model()->findAllByAttributes(array('space_id' => $this->id)) as $content) { $content->delete(); } // When this workspace is used in a group as default workspace, delete the link foreach (Group::model()->findAllByAttributes(array('space_id' => $this->id)) as $group) { $group->space_id = ""; $group->save(); } Wall::model()->deleteAllByAttributes(array('id' => $this->wall_id)); return parent::beforeDelete(); }
/** * Before deleting a SIContent try to delete all corresponding SIContentAddons. */ public function beforeDelete() { // delete also all wall entries foreach ($this->getWallEntries() as $entry) { $entry->delete(); } // remove from search index if ($this->object_model instanceof ISearchable) { HSearch::getInstance()->deleteModel($this->getContentObject()); } return parent::beforeDelete(); }
/** * SearchAction * * Modes: normal for full page, quick as partial for lightbox */ public function actionIndex() { // Get Parameters $keyword = Yii::app()->request->getParam('keyword', ""); $spaceGuid = Yii::app()->request->getParam('sguid', ""); $mode = Yii::app()->request->getParam('mode', "normal"); $page = (int) Yii::app()->request->getParam('page', 1); // current page (pagination) // Cleanup $keyword = Yii::app()->input->stripClean($keyword); $spaceGuid = Yii::app()->input->stripClean($spaceGuid); if ($mode != 'quick') { $mode = "normal"; } $limit = HSetting::Get('paginationSize'); // Show Hits $hitCount = 0; // Total Hit Count $query = ""; // Lucene Query $append = " AND (model:User OR model:Space)"; // Appends for Lucene Query $moreResults = false; // Indicates if there are more hits $results = array(); // Quick Search shows always 1 if ($mode == 'quick') { $limit = 5; } // Load also Space if requested $currentSpace = null; if ($spaceGuid) { $currentSpace = Space::model()->findByAttributes(array('guid' => $spaceGuid)); } /* * $index = new Zend_Search_Lucene_Interface_MultiSearcher(); * $index->addIndex(Zend_Search_Lucene::open('search/index1')); * $index->addIndex(Zend_Search_Lucene::open('search/index2')); * $index->find('someSearchQuery'); */ // Do Search if ($keyword != "") { if ($currentSpace != null) { $append = " AND (model:User OR model:Space OR (belongsToType:Space AND belongsToId:" . $currentSpace->id . "))"; } $hits = new ArrayObject(HSearch::getInstance()->Find($keyword . "* " . $append)); $hitCount = count($hits); // Limit Hits $hits = new LimitIterator($hits->getIterator(), ($page - 1) * $limit, $limit); if ($hitCount > $limit) { $moreResults = true; } // Build Results Array foreach ($hits as $hit) { $doc = $hit->getDocument(); $model = $doc->getField('model')->value; $pk = $doc->getField('pk')->value; $object = $model::model()->findByPk($pk); $results[] = $object->getSearchResult(); } } // Create Pagination Class $pages = new CPagination($hitCount); $pages->setPageSize($limit); $_GET['keyword'] = $keyword; // Fix for post var if ($mode == 'quick') { $this->renderPartial('quick', array('keyword' => $keyword, 'results' => $results, 'spaceGuid' => $spaceGuid, 'moreResults' => $moreResults, 'hitCount' => $hitCount)); } else { $this->render('index', array('keyword' => $keyword, 'results' => $results, 'spaceGuid' => $spaceGuid, 'moreResults' => $moreResults, 'pages' => $pages, 'pageSize' => $limit, 'hitCount' => $hitCount)); } }
/** * Space Section of directory * * Provides a list of all visible spaces. * * @todo Dont pass lucene hits to view, build user array inside of action */ public function actionSpaces() { $keyword = Yii::app()->request->getParam('keyword', ""); // guid of user/workspace $page = (int) Yii::app()->request->getParam('page', 1); // current page (pagination) $keyword = Yii::app()->input->stripClean($keyword); $hits = array(); $query = ""; $hitCount = 0; $sortField = null; $query = "model:Space"; if ($keyword != "") { $query .= " AND " . $keyword; } else { $sortField = 'title'; } //$hits = new ArrayObject( // HSearch::getInstance()->Find($query, HSetting::Get('paginationSize'), $page // )); $hits = new ArrayObject(HSearch::getInstance()->Find($query, $sortField)); $hitCount = count($hits); // Limit Hits $hits = new LimitIterator($hits->getIterator(), ($page - 1) * HSetting::Get('paginationSize'), HSetting::Get('paginationSize')); // Create Pagination Class $pages = new CPagination($hitCount); $pages->setPageSize(HSetting::Get('paginationSize')); $_GET['keyword'] = $keyword; // Fix for post var // Add Meber Statistic Sidebar Yii::app()->interceptor->preattachEventHandler('DirectorySidebarWidget', 'onInit', function ($event) { $event->sender->addWidget('application.modules_core.directory.widgets.NewSpacesWidget', array(), array('sortOrder' => 10)); $event->sender->addWidget('application.modules_core.directory.widgets.SpaceStatisticsWidget', array(), array('sortOrder' => 20)); }); $this->render('spaces', array('keyword' => $keyword, 'hits' => $hits, 'pages' => $pages, 'hitCount' => $hitCount, 'pageSize' => HSetting::Get('paginationSize'))); }