function searchEntityName($search, $searchKey = '', $fieldName = null, $contactEntityTypeId = false, $onlyApproved = true, $excludeIds = null) { if (trim($search) == '') { return array(); } if ($fieldName == null) { $fieldName = 'entityName'; } $aSearchKey = explode(' ', $searchKey); if ($onlyApproved == true) { $aSearchKey[] = 'statusApproved'; } $aSearch = cleanSearchString($search, $aSearchKey, true, true); if (empty($aSearch)) { return array(); } $fieldId = $contactEntityTypeId == true ? " CONCAT(entityTypeId, '-', entityId) " : " entityId "; $match = "MATCH (entityNameSearch) AGAINST ('" . implode(' ', $aSearch) . "' IN BOOLEAN MODE) "; $this->db->select($fieldId . ' AS id, ' . $fieldName . ' AS text, ' . $match . ' AS score ', false)->from('entities_search')->where($match, NULL, FALSE)->order_by('entityTree')->limit(config_item('autocompleteSize')); if ($excludeIds != null) { $this->db->where_not_in('entityId', explode(',', $excludeIds)); } $query = $this->db->get()->result_array(); // pr($this->db->last_query()); die; return $query; }
function searchEntries($userFilters) { $this->load->model('Feeds_Model'); $userId = $this->session->userdata('userId'); $aEntityId = array(); $aSearchKey = array('searchEntries'); $search = $userFilters['search']; $aSearch = cleanSearchString($search, $aSearchKey); $feedId = null; $tagId = null; $aFeedsSearch = array(); $aEntrySearch = array(); if (empty($aSearch)) { return array(); } if ($userFilters['type'] == 'feed') { $feedId = $userFilters['id']; } if ($userFilters['type'] == 'tag' && $userFilters['id'] != config_item('tagAll')) { $tagId = $userFilters['id']; } if ($userFilters['type'] == 'tag' && $userFilters['id'] == config_item('tagStar')) { $tagId = config_item('tagStar'); $indexName = 'indexTag'; $query = $this->db->select(' users_entries.entryId ', false)->from('users_entries FORCE INDEX (' . $indexName . ')')->where('users_entries.userId', $userId)->where('users_entries.tagId', config_item('tagStar'))->get()->result_array(); //pr($this->db->last_query()); die; foreach ($query as $data) { $aEntrySearch[] = $data['entryId']; } } else { $query = $this->Feeds_Model->selectFeedIdByUserId($userId, $feedId, $tagId); foreach ($query as $data) { $aFeedsSearch[] = " MATCH (entityNameSearch) AGAINST ('+searchEntries +searchInFeedId" . $data['feedId'] . "' IN BOOLEAN MODE) "; } $tagId = config_item('tagAll'); } if (empty($aFeedsSearch) && empty($aEntrySearch)) { return array(); } $match = 'MATCH (entityFullSearch) AGAINST (\'' . implode(' ', $aSearch) . '\' IN BOOLEAN MODE)'; $this->db->select(' entityId, entityName, ' . $match . ' AS score, MATCH (entityNameSearch) AGAINST (\'' . implode(' ', cleanSearchString($search, $aSearchKey, false, false)) . '\' IN BOOLEAN MODE) AS scoreName ', false)->from('entities_search')->where($match, NULL, FALSE)->order_by('scoreName DESC, score DESC'); if (!empty($aFeedsSearch)) { $this->db->where('(' . implode(' OR ', $aFeedsSearch) . ')', NULL, FALSE); } if (!empty($aEntrySearch)) { $this->db->where('entityTypeId', config_item('entityTypeEntry')); $this->db->where_in('entityId', $aEntrySearch); } $this->Commond_Model->appendLimitInQuery($userFilters['page'], config_item('entriesPageSize')); $query = $this->db->get()->result_array(); //pr($this->db->last_query()); die; foreach ($query as $data) { $aEntryId[] = $data['entityId']; } if (empty($aEntryId)) { return array(); } $this->db->select('feeds.feedId, feedName, feedUrl, feedLInk, feedIcon, entries.entryId, entryTitle, entryUrl, entryContent, entries.entryDate, entryAuthor, entryRead, entryStarred ', false)->from('entries')->join('feeds', 'entries.feedId = feeds.feedId', 'inner')->join('users_entries', 'users_entries.entryId = entries.entryId AND users_entries.feedId = entries.feedId', 'inner')->where_in('entries.entryId', $aEntryId)->where('users_entries.userId', $userId)->where('users_entries.tagId', $tagId); $this->db->_protect_identifiers = FALSE; $this->db->order_by('FIELD(entries.entryId, ' . implode(',', $aEntryId) . ' ) '); $this->db->_protect_identifiers = TRUE; $query = $this->db->get()->result_array(); //pr($this->db->last_query()); die; return $query; }