当前位置: 首页>>代码示例>>PHP>>正文


PHP Search::searchFor方法代码示例

本文整理汇总了PHP中Search::searchFor方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::searchFor方法的具体用法?PHP Search::searchFor怎么用?PHP Search::searchFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search::searchFor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findPublishedInSearchIndexByString

 /**
  * Find published news in search index
  * @param array
  * @return array
  */
 public static function findPublishedInSearchIndexByString($keywords, $limit = '', $offset = 0)
 {
     // $objSearch = \Search::searchFor($strKeywords, ($strQueryType == 'or'), $arrPages, 0, 0, $blnFuzzy);
     $t = static::$strTable;
     // $arrColumns = array("($t.id IN(" . implode(',', array_map('intval', $arrIds)) . ")");
     if (!BE_USER_LOGGED_IN) {
         $time = time();
         $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
     }
     $objSearch = \Search::searchFor($keywords, 'or', '', $limit, $offset, true);
     $arrIds = static::getIdsOfNewsItemsFromSearchObject($objSearch);
     // $arrIds = array('vgt-03-15');
     //return static::findBy('alias', $arrIds);
     $objArticles = static::findPublishedNewsByIds($arrIds);
     return $objArticles;
 }
开发者ID:heimrichhannot,项目名称:contao-news_plus,代码行数:21,代码来源:NewsPlusModel.php

示例2: findCurrentByPidAndFilter


//.........这里部分代码省略.........
                                 } else {
                                     if (\HeimrichHannot\Haste\Util\StringUtil::startsWith($id, 'h')) {
                                         $arrHosts[] = substr($id, 1);
                                     }
                                 }
                             }
                         }
                         if (!empty($arrDocents)) {
                             if (is_array($valueArray) && !empty($valueArray)) {
                                 if ($arrFilterConfig['show_related']) {
                                     $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.docents", $arrDocents, EVENTMODEL_CONDITION_OR);
                                 } else {
                                     $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.docents", $arrDocents);
                                 }
                             }
                         }
                         if (!empty($arrMembers)) {
                             if (is_array($valueArray) && !empty($valueArray)) {
                                 if ($arrFilterConfig['show_related'] || $arrFilterConfig['combine_docents']) {
                                     $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberdocents", $arrMembers, EVENTMODEL_CONDITION_OR);
                                     if ($key = 'hosts' || $key == 'docents' && $arrFilterConfig['combine_docents']) {
                                         $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberhosts", $arrMembers, EVENTMODEL_CONDITION_OR);
                                     }
                                 } else {
                                     $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberdocents", $arrMembers);
                                     if ($key = 'hosts' || $key == 'docents' && $arrFilterConfig['combine_docents']) {
                                         $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberhosts", $arrMembers);
                                     }
                                 }
                             }
                         }
                         if (!empty($arrHosts) && ($key = 'hosts' || $key == 'docents' && $arrFilterConfig['cal_docent_combine'])) {
                             if (is_array($valueArray) && !empty($valueArray)) {
                                 if ($arrFilterConfig['show_related']) {
                                     $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.hosts", $arrHosts, EVENTMODEL_CONDITION_OR);
                                 } else {
                                     $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.hosts", $arrHosts);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'postal':
                 if ($value != '') {
                     $arrColumns[] = "LEFT({$t}.postal, 1) = ?";
                     $arrValues[] = $value;
                 }
                 break;
             case 'timeHours':
                 if ($value != '') {
                     $arrColumns[] = "({$t}.{$key} >= {$value} AND {$t}.{$key} < ({$value} + 1))";
                 }
                 break;
             case 'q':
                 if ($value != '' && is_array($arrFilterConfig['jumpTo'])) {
                     try {
                         $objSearch = \Search::searchFor($value, $arrFilterConfig['module']['queryType'] == 'or', $arrFilterConfig['jumpTo'], 0, 0, $arrFilterConfig['module']['fuzzy']);
                         // return if keyword not found
                         if ($objSearch->numRows < 1) {
                             return null;
                         }
                         $arrUrls = $objSearch->fetchEach('url');
                         $strKeyWordColumns = "";
                         $n = 0;
                         foreach ($arrUrls as $i => $strAlias) {
                             $strKeyWordColumns .= ($n > 0 ? " OR " : "") . "{$t}.alias = ?";
                             $arrValues[] = basename($strAlias);
                             $n++;
                         }
                         $arrColumns[] = "({$strKeyWordColumns})";
                     } catch (\Exception $e) {
                         \System::log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
                     }
                 }
                 break;
             default:
                 if ($value != '') {
                     $arrColumns[] = "{$t}.{$key}=?";
                     $arrValues[] = $value;
                 }
         }
     }
     $arrColumns[] = "(({$t}.startTime>={$intStart} AND {$t}.startTime<={$intEnd}) OR ({$t}.endTime>={$intStart} AND {$t}.endTime<={$intEnd}) OR ({$t}.startTime<={$intStart} AND {$t}.endTime>={$intEnd}) OR ({$t}.recurring=1 AND ({$t}.recurrences=0 OR {$t}.repeatEnd>={$intStart}) AND {$t}.startTime<={$intEnd}))";
     if (!BE_USER_LOGGED_IN) {
         $time = time();
         $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
     }
     // for related search
     if (!empty($arrColumnsOr)) {
         $arrColumns[] = implode(' OR ', $arrColumnsOr);
     }
     if (!isset($arrOptions['order'])) {
         $arrOptions['order'] = "{$t}.startTime";
     }
     if ($count) {
         return static::countBy($arrColumns, $arrValues, $arrOptions);
     }
     return static::findBy($arrColumns, $arrValues, $arrOptions);
 }
开发者ID:heimrichhannot,项目名称:contao-calendar_plus,代码行数:101,代码来源:CalendarPlusEventsModel.php

示例3: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Mark the x and y parameter as used (see #4277)
     if (isset($_GET['x'])) {
         \Input::get('x');
         \Input::get('y');
     }
     // Trigger the search module from a custom form
     if (!isset($_GET['keywords']) && \Input::post('FORM_SUBMIT') == 'tl_search') {
         $_GET['keywords'] = \Input::post('keywords');
         $_GET['query_type'] = \Input::post('query_type');
         $_GET['per_page'] = \Input::post('per_page');
     }
     $blnFuzzy = $this->fuzzy;
     $strQueryType = \Input::get('query_type') ?: $this->queryType;
     $strKeywords = trim(\Input::get('keywords'));
     /** @var \FrontendTemplate|object $objFormTemplate */
     $objFormTemplate = new \FrontendTemplate($this->searchType == 'advanced' ? 'mod_search_advanced' : 'mod_search_simple');
     $objFormTemplate->uniqueId = $this->id;
     $objFormTemplate->queryType = $strQueryType;
     $objFormTemplate->keyword = specialchars($strKeywords);
     $objFormTemplate->keywordLabel = $GLOBALS['TL_LANG']['MSC']['keywords'];
     $objFormTemplate->optionsLabel = $GLOBALS['TL_LANG']['MSC']['options'];
     $objFormTemplate->search = specialchars($GLOBALS['TL_LANG']['MSC']['searchLabel']);
     $objFormTemplate->matchAll = specialchars($GLOBALS['TL_LANG']['MSC']['matchAll']);
     $objFormTemplate->matchAny = specialchars($GLOBALS['TL_LANG']['MSC']['matchAny']);
     $objFormTemplate->id = \Config::get('disableAlias') && \Input::get('id') ? \Input::get('id') : false;
     $objFormTemplate->action = ampersand(\Environment::get('indexFreeRequest'));
     // Redirect page
     if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
         $objFormTemplate->action = $this->generateFrontendUrl($objTarget->row());
     }
     $this->Template->form = $objFormTemplate->parse();
     $this->Template->pagination = '';
     $this->Template->results = '';
     // Execute the search if there are keywords
     if ($strKeywords != '' && $strKeywords != '*' && !$this->jumpTo) {
         // Reference page
         if ($this->rootPage > 0) {
             $intRootId = $this->rootPage;
             $arrPages = $this->Database->getChildRecords($this->rootPage, 'tl_page');
             array_unshift($arrPages, $this->rootPage);
         } else {
             $intRootId = $objPage->rootId;
             $arrPages = $this->Database->getChildRecords($objPage->rootId, 'tl_page');
         }
         // HOOK: add custom logic (see #5223)
         if (isset($GLOBALS['TL_HOOKS']['customizeSearch']) && is_array($GLOBALS['TL_HOOKS']['customizeSearch'])) {
             foreach ($GLOBALS['TL_HOOKS']['customizeSearch'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($arrPages, $strKeywords, $strQueryType, $blnFuzzy);
             }
         }
         // Return if there are no pages
         if (!is_array($arrPages) || empty($arrPages)) {
             $this->log('No searchable pages found', __METHOD__, TL_ERROR);
             return;
         }
         $arrResult = null;
         $strChecksum = md5($strKeywords . $strQueryType . $intRootId . $blnFuzzy);
         $query_starttime = microtime(true);
         $strCacheFile = 'system/cache/search/' . $strChecksum . '.json';
         // Load the cached result
         if (file_exists(TL_ROOT . '/' . $strCacheFile)) {
             $objFile = new \File($strCacheFile, true);
             if ($objFile->mtime > time() - 1800) {
                 $arrResult = json_decode($objFile->getContent(), true);
             } else {
                 $objFile->delete();
             }
         }
         // Cache the result
         if ($arrResult === null) {
             try {
                 $objSearch = \Search::searchFor($strKeywords, $strQueryType == 'or', $arrPages, 0, 0, $blnFuzzy);
                 $arrResult = $objSearch->fetchAllAssoc();
             } catch (\Exception $e) {
                 $this->log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
                 $arrResult = array();
             }
             \File::putContent($strCacheFile, json_encode($arrResult));
         }
         $query_endtime = microtime(true);
         // Sort out protected pages
         if (\Config::get('indexProtected') && !BE_USER_LOGGED_IN) {
             $this->import('FrontendUser', 'User');
             foreach ($arrResult as $k => $v) {
                 if ($v['protected']) {
                     if (!FE_USER_LOGGED_IN) {
                         unset($arrResult[$k]);
                     } else {
                         $groups = deserialize($v['groups']);
                         if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) {
                             unset($arrResult[$k]);
                         }
//.........这里部分代码省略.........
开发者ID:StephenGWills,项目名称:sample-contao-app,代码行数:101,代码来源:ModuleSearch.php

示例4: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     // Trigger the search module from a custom form
     if (!$_GET['keywords'] && \Input::post('FORM_SUBMIT') == 'tl_search') {
         $_GET['keywords'] = \Input::post('keywords');
         $_GET['query_type'] = \Input::post('query_type');
         $_GET['per_page'] = \Input::post('per_page');
     }
     // Remove insert tags
     $strKeywords = trim(\Input::get('keywords'));
     $strKeywords = preg_replace('/\\{\\{[^\\}]*\\}\\}/', '', $strKeywords);
     // Overwrite the default query_type
     if (\Input::get('query_type')) {
         $this->queryType = \Input::get('query_type');
     }
     $objFormTemplate = new \FrontendTemplate($this->searchType == 'advanced' ? 'mod_search_advanced' : 'mod_search_simple');
     $objFormTemplate->uniqueId = $this->id;
     $objFormTemplate->queryType = $this->queryType;
     $objFormTemplate->keyword = specialchars($strKeywords);
     $objFormTemplate->keywordLabel = $GLOBALS['TL_LANG']['MSC']['keywords'];
     $objFormTemplate->optionsLabel = $GLOBALS['TL_LANG']['MSC']['options'];
     $objFormTemplate->search = specialchars($GLOBALS['TL_LANG']['MSC']['searchLabel']);
     $objFormTemplate->matchAll = specialchars($GLOBALS['TL_LANG']['MSC']['matchAll']);
     $objFormTemplate->matchAny = specialchars($GLOBALS['TL_LANG']['MSC']['matchAny']);
     $objFormTemplate->id = $GLOBALS['TL_CONFIG']['disableAlias'] && \Input::get('id') ? \Input::get('id') : false;
     $objFormTemplate->action = $this->getIndexFreeRequest();
     // Redirect page
     if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
         $objFormTemplate->action = $this->generateFrontendUrl($objTarget->row());
     }
     $this->Template->form = $objFormTemplate->parse();
     $this->Template->pagination = '';
     $this->Template->results = '';
     // Execute the search if there are keywords
     if ($strKeywords != '' && $strKeywords != '*' && !$this->jumpTo) {
         // Reference page
         if ($this->rootPage > 0) {
             $intRootId = $this->rootPage;
             $arrPages = $this->Database->getChildRecords($this->rootPage, 'tl_page');
             array_unshift($arrPages, $this->rootPage);
         } else {
             global $objPage;
             $intRootId = $objPage->rootId;
             $arrPages = $this->Database->getChildRecords($objPage->rootId, 'tl_page');
         }
         // Return if there are no pages
         if (!is_array($arrPages) || empty($arrPages)) {
             $this->log('No searchable pages found', 'ModuleSearch compile()', TL_ERROR);
             return;
         }
         $arrResult = null;
         $strChecksum = md5($strKeywords . \Input::get('query_type') . $intRootId . $this->fuzzy);
         $query_starttime = microtime(true);
         $strCacheFile = 'system/cache/search/' . $strChecksum . '.json';
         // Load the cached result
         if (file_exists(TL_ROOT . '/' . $strCacheFile)) {
             $objFile = new \File($strCacheFile);
             if ($objFile->mtime > time() - 1800) {
                 $arrResult = json_decode($objFile->getContent(), true);
             } else {
                 $objFile->delete();
             }
         }
         // Cache the result
         if ($arrResult === null) {
             try {
                 $objSearch = \Search::searchFor($strKeywords, \Input::get('query_type') == 'or', $arrPages, 0, 0, $this->fuzzy);
                 $arrResult = $objSearch->fetchAllAssoc();
             } catch (\Exception $e) {
                 $this->log('Website search failed: ' . $e->getMessage(), 'ModuleSearch compile()', TL_ERROR);
                 $arrResult = array();
             }
             $objFile = new \File($strCacheFile);
             $objFile->write(json_encode($arrResult));
             $objFile->close();
         }
         $query_endtime = microtime(true);
         // Sort out protected pages
         if ($GLOBALS['TL_CONFIG']['indexProtected'] && !BE_USER_LOGGED_IN) {
             $this->import('FrontendUser', 'User');
             foreach ($arrResult as $k => $v) {
                 if ($v['protected']) {
                     if (!FE_USER_LOGGED_IN) {
                         unset($arrResult[$k]);
                     } else {
                         $groups = deserialize($v['groups']);
                         if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) {
                             unset($arrResult[$k]);
                         }
                     }
                 }
             }
             $arrResult = array_values($arrResult);
         }
         $count = count($arrResult);
         // No results
         if ($count < 1) {
//.........这里部分代码省略.........
开发者ID:rburch,项目名称:core,代码行数:101,代码来源:ModuleSearch.php

示例5: getArticles

 protected function getArticles()
 {
     $offset = intval($this->skipFirst);
     $limit = null;
     // Maximum number of items
     if ($this->numberOfItems > 0) {
         $limit = $this->numberOfItems;
     }
     // Handle featured news
     if ($this->news_featured == 'featured') {
         $blnFeatured = true;
     } elseif ($this->news_featured == 'unfeatured') {
         $blnFeatured = false;
     } else {
         $blnFeatured = null;
     }
     $this->Template->articles = array();
     $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
     $objSubmission = $this->objForm->getSubmission(false);
     if ($objSubmission === null) {
         $objSubmission = new \HeimrichHannot\FormHybrid\Submission();
     }
     $objSubmission->search = trim($objSubmission->search);
     $objSubmission->search = preg_replace('/\\{\\{[^\\}]*\\}\\}/', '', $objSubmission->search);
     if ($objSubmission->from) {
         $from = strtotime($objSubmission->from);
         $objSubmission->from = mktime(0, 0, 0, date('m', $from), date('d', $from), date('Y', $from));
     }
     if ($objSubmission->to) {
         $to = strtotime($objSubmission->to);
         $objSubmission->to = mktime(23, 59, 59, date('m', $to), date('d', $to), date('Y', $to));
     }
     $arrAliases = array();
     if ($objSubmission->search != '') {
         $objSearch = \Search::searchFor($objSubmission->search);
         $arrResults = $objSearch->fetchAllAssoc();
         if (!empty($arrResults)) {
             foreach ($arrResults as $arrResult) {
                 $arrAliases[] = str_replace(\Config::get('urlSuffix'), '', basename($arrResult['url']));
             }
         }
     }
     // Get the total number of items
     $intTotal = NewsFilterModel::countPublishedByPidsAndSearch($this->news_archives, $objSubmission, $arrAliases, $blnFeatured);
     if ($intTotal < 1) {
         return;
     }
     $total = $intTotal - $offset;
     // Split the results
     if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) {
         // Adjust the overall limit
         if (isset($limit)) {
             $total = min($limit, $total);
         }
         // Get the current page
         $id = 'page_n' . $this->id;
         $page = \Input::get($id) ?: 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
             global $objPage;
             $objPage->noSearch = 1;
             $objPage->cache = 0;
             // Send a 404 header
             header('HTTP/1.1 404 Not Found');
             return;
         }
         // Set limit and offset
         $limit = $this->perPage;
         $offset += (max($page, 1) - 1) * $this->perPage;
         $skip = intval($this->skipFirst);
         // Overall limit
         if ($offset + $limit > $total + $skip) {
             $limit = $total + $skip - $offset;
         }
         // Add the pagination menu
         $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     // Get the items
     if (isset($limit)) {
         $objArticles = NewsFilterModel::findPublishedByPidsAndSearch($this->news_archives, $objSubmission, $arrAliases, $blnFeatured, $limit, $offset);
     } else {
         $objArticles = NewsFilterModel::findPublishedByPidsAndSearch($this->news_archives, $objSubmission, $arrAliases, $blnFeatured, 0, $offset);
     }
     // Add the articles
     if ($objArticles !== null) {
         $this->Template->articles = $this->parseArticles($objArticles);
     }
     $this->Template->archives = $this->news_archives;
 }
开发者ID:heimrichhannot,项目名称:contao-newsfilter,代码行数:90,代码来源:ModuleNewsFilter.php

示例6: findNewsInSearchIndex

 protected function findNewsInSearchIndex()
 {
     $arrIds = array();
     // Reference page
     if ($this->rootPage > 0) {
         $arrPages = $this->Database->getChildRecords($this->rootPage, 'tl_page');
         array_unshift($arrPages, $this->rootPage);
     } else {
         global $objPage;
         $arrPages = $this->Database->getChildRecords($objPage->rootId, 'tl_page');
     }
     try {
         $objSearch = \Search::searchFor($this->strKeywords, $this->objFilter->news_filterSearchQueryType === false, $arrPages, 0, 0, $this->objFilter->news_filterFuzzySearch);
         if ($objSearch->numRows > 0) {
             $arrUrls = array();
             while ($objSearch->next()) {
                 $arrUrls[] = $objSearch->url;
             }
             $strKeyWordColumns = "";
             $n = 0;
             foreach ($arrUrls as $i => $strAlias) {
                 $strKeyWordColumns .= ($n > 0 ? " OR " : "") . "{$this->t}.alias = ?";
                 $arrValues[] = basename($strAlias);
                 $n++;
             }
             $arrColumns[] = "({$strKeyWordColumns})";
             $objArticles = \HeimrichHannot\NewsPlus\NewsPlusModel::findBy($arrColumns, $arrValues);
             if ($objArticles !== null) {
                 $arrIds = $objArticles->fetchEach('id');
             }
             return $arrIds;
         } else {
             return $arrIds;
         }
     } catch (\Exception $e) {
         $this->log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         return $arrIds;
     }
 }
开发者ID:heimrichhannot,项目名称:contao-news_plus,代码行数:39,代码来源:ModuleNewsListPlus.php


注:本文中的Search::searchFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。