Exemplo n.º 1
0
 /**
  * get reports
  *
  * @param string $infoType
  * @param integer $productId
  * @param string $where
  * @param array $selected
  * @return array
  */
 public function getReports($infoType, $productId, $selected = array())
 {
     $reports = array();
     $productIds = Yii::app()->user->getState('visit_product_id');
     $condition = 'product_id IN (' . join(',', $productIds) . ')';
     if (isset($productId)) {
         $condition .= ' AND product_id = ' . $productId;
     }
     $searchRowArr = Yii::app()->user->getState($productId . '_' . $infoType . '_search');
     if (null == $searchRowArr) {
         $searchRowArr = array();
     }
     $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId);
     $result = SqlService::baseGetGroupQueryStr($searchFieldConfig, $infoType, $searchRowArr);
     if (CommonService::$ApiResult['SUCCESS'] == $result['status']) {
         $condition .= ' AND ' . $result['detail'];
     }
     $reportDatas = $this->getReportData($infoType, $productId, $condition, $selected);
     foreach ($reportDatas as $key => $data) {
         $show = false;
         if (!empty($selected) && in_array($key, $selected)) {
             $show = true;
         }
         $reports[] = new Report($infoType, $productId, $data['type'], $condition, $data, $show);
     }
     return $reports;
 }
Exemplo n.º 2
0
 /**
  * Proxy the call to delete
  *
  * @param  string|object $table
  * @param string $where
  */
 public function delete($table, $where = '')
 {
     if (is_object($table)) {
         $where = 'id = ' . $table->id;
         if ($this->searchService != null) {
             $this->searchService->delete($table);
         }
         if ($this->tagService != null) {
             $this->tagService->deleteTags($table, za()->getUser());
         }
         if ($this->itemLinkService != null) {
             $this->itemLinkService->deleteItem($table);
         }
         $table = get_class($table);
     }
     $table = strtolower($table);
     $return = false;
     try {
         $this->beginTransaction();
         if (is_array($where)) {
             $where = $this->bindValues($where);
         }
         $this->proxied->delete($table, $where);
         $return = true;
         $this->commit();
     } catch (Exception $e) {
         error_log(get_class($e) . " - Caught: " . $e->getMessage());
         error_log($e->getTraceAsString());
         $this->rollBack();
         throw $e;
     }
     return $return;
 }
Exemplo n.º 3
0
 protected function getSearchResults ()
 {
     $searchService = new SearchService ($this->searchOptions);
     $results = $searchService->search ();
     
     foreach ($results as $rss)
     {
         $this->searchResults = array_merge($this->searchResults, $rss->items);
     }
     
     $this->totalResults = count ($this->searchResults);
     
     if ($this->totalResults > 0)
     {
         $this->sort ($this->sort);
     }
 }       
Exemplo n.º 4
0
 public function indexAction()
 {
     $query = $this->_getParam('query');
     if ($this->_getParam('contacts')) {
         $this->searchContacts($this->_getParam('query'));
         return;
     }
     $hits = $this->searchService->search($query);
     $this->view->results = $this->filterResults($hits);
     $this->view->query = $query;
     $this->view->perPage = 6;
     if ($this->_getParam('_ajax')) {
         $this->renderRawView('search/results.php');
     } else {
         $this->renderView('search/results.php');
     }
 }
 public function execute()
 {
     $this->sType = $this->getOption('param', '');
     //PW(24.07.2013) TODO: add help, descriptions, status/error output
     $solr = SearchService::getInstance();
     echo $solr->deleteIndex($this->sType);
     return;
 }
Exemplo n.º 6
0
 private function _process()
 {
     $filter = array('categories' => $this->_getSelectedCategories(Input::get('categories')), 'min' => Input::get('min'), 'max' => Input::get('max'));
     $keywords = Input::get('keywords');
     try {
         $result = SearchService::search(Config::get('constants.SEARCH.ITEM'), $keywords, $filter);
         return Response::json(array('success_code' => 'OK', 'data' => $result->toArray()), 200);
     } catch (Exception $exception) {
         return Response::json(array('error_code' => $exception->getCode(), 'error_message' => $exception->getMessage()), 500);
     }
 }
 /**
  * Constructor for BuildIndexMainControl class
  */
 public function __construct()
 {
     $this->oSearchService = SearchService::getInstance();
     $this->sFilePathIndexProgTxt = BSDATADIR . DS . 'index_prog.txt';
     $this->sFilePathIndexLogFile = BSDATADIR . DS . 'ExtendedSearchIndex.log';
     $this->sFilePathLockFile = BSDATADIR . DS . 'ExtendedSearch.lock';
     //Possible values of PHP_SAPI (not all): apache, cgi (until PHP 5.3), cgi-fcgi, cli
     $this->bCommandLineMode = PHP_SAPI === 'cli';
     $this->sCustomerId = BsConfig::get('MW::ExtendedSearch::CustomerID');
     // Set major types to be indexed
     $this->aTypes['wiki'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesWiki');
     $this->aTypes['special'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesSpecial');
     $this->aTypes['repo'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesRepo');
     $this->aTypes['linked'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTyLinked');
     $this->aTypes['special-linked'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesSpecialLinked');
 }
Exemplo n.º 8
0
 /**
  * edit user query
  *
  * @author                                   youzhao.zxw<*****@*****.**>
  * @param   string       $title              user query title
  * @param   int          $productId          product id
  * @param   string       $type               bug,case or result
  * @param   array        $searchConditionArr search condition array
  * @return  array                            edit user query result information
  */
 public static function editUserQuery($title, $productId, $type, $searchConditionArr)
 {
     $resultInfo = array();
     $updateFlag = false;
     $title = trim($title);
     $userQuery = UserQuery::model()->findByAttributes(array('query_type' => $type, 'product_id' => $productId, 'created_by' => Yii::app()->user->id, 'title' => $title));
     if (false != $userQuery) {
         $updateFlag = true;
         $userQuery->updated_at = date(CommonService::DATE_FORMAT);
     } else {
         $userQuery = new UserQuery();
         $userQuery->created_by = Yii::app()->user->id;
         $userQuery->created_at = date(CommonService::DATE_FORMAT);
         $userQuery->updated_at = $userQuery->created_at;
         $userQuery->query_type = $type;
         $userQuery->product_id = $productId;
         $userQuery->title = $title;
     }
     $searchRowConditionArr = SearchService::getSearchConditionArr($searchConditionArr);
     $queryConditonArr = array();
     $keyArr = array('leftParenthesesName', 'field', 'operator', 'value', 'rightParenthesesName', 'andor');
     foreach ($searchRowConditionArr as $rowCondtion) {
         foreach ($rowCondtion as $key => $value) {
             $queryConditonArr[$key][] = $value;
         }
     }
     $userQuery->left_parentheses = serialize($queryConditonArr['leftParenthesesName']);
     $userQuery->fieldlist = serialize($queryConditonArr['field']);
     $userQuery->operatorlist = serialize($queryConditonArr['operator']);
     $userQuery->valuelist = serialize($queryConditonArr['value']);
     $userQuery->right_parentheses = serialize($queryConditonArr['rightParenthesesName']);
     $userQuery->andorlist = serialize($queryConditonArr['andor']);
     if ($userQuery->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         if ($updateFlag) {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_UPDATE_SUCCESS));
         } else {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_CREATE_SUCCESS));
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $userQuery->getErrors();
     }
     return $resultInfo;
 }
 /**
  * Return a instance of SearchService.
  * @return SearchService Instance of SearchService
  */
 public static function getInstance()
 {
     wfProfileIn('BS::' . __METHOD__);
     if (self::$oInstance === null) {
         if (PHP_SAPI === 'cli') {
             $oDbr = wfGetDB(DB_SLAVE);
             if ($oDbr->tableExists('bs_settings')) {
                 BsConfig::loadSettings();
             }
         }
         $aUrl = parse_url(BsConfig::get('MW::ExtendedSearch::SolrServiceUrl'));
         if (empty($aUrl['host']) || empty($aUrl['port']) || empty($aUrl['path'])) {
             wfProfileOut('BS::' . __METHOD__);
             throw new Exception('Creating instance of ' . __CLASS__ . ' not possible with these params:' . ', $host=' . (isset($aUrl['host']) ? $aUrl['host'] : '') . ', $port=' . (isset($aUrl['port']) ? $aUrl['port'] : '') . ', $path=' . (isset($aUrl['path']) ? $aUrl['path'] : ''));
         }
         $oServer = new self($aUrl['scheme'], $aUrl['host'], $aUrl['port'], $aUrl['path']);
         self::$oInstance = $oServer;
         wfProfileOut('BS::' . __METHOD__);
         return $oServer;
     }
     wfProfileOut('BS::' . __METHOD__);
     return self::$oInstance;
 }
Exemplo n.º 10
0
 private function getGridShowContent($searchFieldConfig, $showFieldArr, $infoType, $productId, $filterColumn, $whereStr, $isAllBasicField = false)
 {
     $pageSize = CommonService::getPageSize();
     $viewColumnArr = SearchService::getViewColumnArr($searchFieldConfig, $showFieldArr, $infoType, $productId, $filterColumn);
     $totalNum = SqlService::getTotalFoundNum($infoType, $productId, $whereStr, $isAllBasicField);
     $sql = SqlService::getRawDataSql($searchFieldConfig, $infoType, $productId, $this->getSqlSelectFieldArr($infoType, $showFieldArr), $whereStr, $isAllBasicField);
     $dataProvider = new CSqlDataProvider($sql, array('totalItemCount' => $totalNum, 'sort' => array('defaultOrder' => array('id' => true), 'multiSort' => true, 'attributes' => array_merge($showFieldArr, array(Info::MARK))), 'pagination' => array('pageSize' => $pageSize)));
     $sortArr = $dataProvider->getSort()->getDirections();
     Yii::app()->user->setState($productId . '_' . $infoType . '_sortArr', $sortArr);
     $preNextSessionSql = SqlService::getPreNextSql($searchFieldConfig, $infoType, $productId, $whereStr, Yii::app()->user->getState($productId . '_' . $infoType . '_sortArr', $isAllBasicField));
     Yii::app()->user->setState($productId . '_' . $infoType . '_prenextsql', $preNextSessionSql);
     return array('viewColumnArr' => $viewColumnArr, 'dataProvider' => $dataProvider, 'totalNum' => $totalNum);
 }
 /**
  * Processes incoming search request
  */
 public function readInSearchRequest()
 {
     global $wgCanonicalNamespaceNames, $wgExtraNamespaces, $wgContentNamespaces;
     $this->aOptions['searchStringRaw'] = $this->oSearchRequest->sInput;
     $this->aOptions['searchStringOrig'] = ExtendedSearchBase::preprocessSearchInput($this->oSearchRequest->sInput);
     self::$searchStringRaw = $this->aOptions['searchStringRaw'];
     $sCustomerId = $this->getCustomerId();
     $sLogOp = ' OR ';
     $aFq = array();
     $aBq = array();
     $oRequest = RequestContext::getMain()->getRequest();
     $scope = $oRequest->getVal('search_scope', BsConfig::get('MW::ExtendedSearch::DefScopeUser')) == 'title' ? 'title' : 'text';
     $this->aOptions['scope'] = $scope;
     $vNamespace = $this->checkSearchstringForNamespace($this->aOptions['searchStringRaw'], $this->aOptions['searchStringOrig'], $aFq, BsConfig::get('MW::ExtendedSearch::ShowFacets'));
     $this->aOptions['searchStringWildcarded'] = SearchService::wildcardSearchstring($this->aOptions['searchStringOrig']);
     $this->aOptions['searchStringForStatistics'] = $this->aOptions['searchStringWildcarded'];
     $aSearchTitle = array('title:(' . $this->aOptions['searchStringOrig'] . ')^5', 'titleWord:(' . $this->aOptions['searchStringOrig'] . ')^2', 'titleReverse:(' . $this->aOptions['searchStringWildcarded'] . ')', 'redirects:(' . $this->aOptions['searchStringOrig'] . ')');
     $aSearchText = array('textWord:(' . $this->aOptions['searchStringOrig'] . ')^2', 'textReverse:(' . $this->aOptions['searchStringWildcarded'] . ')', 'sections:(' . $this->aOptions['searchStringOrig'] . ')');
     $sSearchStringTitle = implode($sLogOp, $aSearchTitle);
     $sSearchStringText = implode($sLogOp, $aSearchText);
     $this->aOptions['searchStringFinal'] = $this->aOptions['scope'] === 'title' ? $sSearchStringTitle : $sSearchStringTitle . $sLogOp . $sSearchStringText;
     // filter query
     $aFq[] = 'redirect:0';
     $aFq[] = 'special:0';
     $aFq[] = 'wiki:(' . $sCustomerId . ')';
     // $this->aOptions['namespaces'] HAS TO BE an array with numeric indices of type string!
     $this->aOptions['namespaces'] = $this->oSearchRequest->aNamespaces;
     $aNamespaces = array_slice($wgCanonicalNamespaceNames, 2);
     $aNamespaces = $aNamespaces + $wgExtraNamespaces;
     $bTagNamespace = false;
     if ($vNamespace === false) {
         $this->aOptions['files'] = $this->oSearchRequest->bSearchFiles === true ? true : false;
         $oUser = RequestContext::getMain()->getUser();
         if (!$oUser->getOption('searcheverything')) {
             if (empty($this->aOptions['namespaces']) && $this->oSearchRequest->bNoSelect === false) {
                 $this->aOptions['namespaces'] = array();
                 $aOptions = $oUser->getOptions();
                 foreach ($aOptions as $sOpt => $sValue) {
                     if (strpos($sOpt, 'searchNs') !== false && $sValue == true) {
                         $this->aOptions['namespaces'][] = '' . str_replace('searchNs', '', $sOpt);
                     }
                 }
                 $aAllowedTypes = explode(',', BsConfig::get('MW::ExtendedSearch::IndexFileTypes'));
                 $aAllowedTypes = array_map('trim', $aAllowedTypes);
                 $aSearchFilesFacet = array_intersect($this->oSearchRequest->aType, $aAllowedTypes);
                 if (($this->aOptions['files'] === true || !empty($aSearchFilesFacet)) && $oUser->isAllowed('searchfiles')) {
                     $this->aOptions['namespaces'][] = '999';
                     $this->aOptions['namespaces'][] = '998';
                 }
             } else {
                 $bTagNamespace = true;
                 $aTmp = array();
                 foreach ($this->aOptions['namespaces'] as $iNs) {
                     if (BsNamespaceHelper::checkNamespacePermission($iNs, 'read') === true) {
                         $aTmp[] = $iNs;
                     }
                 }
                 $this->aOptions['namespaces'] = $aTmp;
             }
         } else {
             if (empty($this->aOptions['namespaces'])) {
                 $aTmp = array();
                 foreach ($aNamespaces as $iNs) {
                     if (BsNamespaceHelper::checkNamespacePermission($iNs, 'read') === true) {
                         $this->aOptions['namespaces'][] = $iNs;
                     }
                 }
             } else {
                 $bTagNamespace = true;
                 $aTmp = array();
                 foreach ($this->aOptions['namespaces'] as $iNs) {
                     if (!BsNamespaceHelper::checkNamespacePermission($iNs, 'read')) {
                         $aTmp[] = $iNs;
                     }
                 }
                 if (!empty($aTmp)) {
                     $this->aOptions['namespaces'] = array_diff($this->aOptions['namespaces'], $aTmp);
                 }
             }
         }
     } else {
         $bTagNamespace = true;
         $this->aOptions['namespaces'][] = '' . $vNamespace;
     }
     $this->aOptions['namespaces'] = array_unique($this->aOptions['namespaces']);
     if (!empty($this->aOptions['namespaces'])) {
         $aFqNamespaces = array();
         foreach ($this->aOptions['namespaces'] as $sNamespace) {
             $aFqNamespaces[] = $sNamespace;
             if ($sNamespace == '999') {
                 $filesAlreadyAddedInLoopBefore = true;
             }
         }
         if (!isset($filesAlreadyAddedInLoopBefore) && $this->aOptions['files'] === true && $oUser->isAllowed('searchfiles')) {
             $aFqNamespaces[] = '999';
         }
         $bTagNamespace = true;
         $aFq[] = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=na}namespace:("' . implode('" "', $aFqNamespaces) . '")' : 'namespace:("' . implode('" "', $aFqNamespaces) . '")';
     }
     // $this->aOptions['cats'] = $this->oSearchRequest->sCat; // string, defaults to '' if 'search_cat' not set in REQUEST
     $this->aOptions['cats'] = $this->oSearchRequest->sCategories;
     // array of strings or empty array
     if (!empty($this->aOptions['cats'])) {
         if (isset($this->oSearchRequest->sOperator)) {
             switch ($this->oSearchRequest->sOperator) {
                 case 'AND':
                     $sLogOp = ' AND ';
                     break;
                 default:
             }
         }
         $sFqCategories = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=ca}' : '';
         $sFqCategories .= 'cat:("' . implode('"' . $sLogOp . '"', $this->aOptions['cats']) . '")';
         $aFq[] = $sFqCategories;
     }
     $this->aOptions['type'] = $this->oSearchRequest->aType;
     if (!empty($this->aOptions['type'])) {
         $sFqType = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=ty}' : '';
         $sFqType .= 'type:("' . implode('"' . $sLogOp . '"', $this->aOptions['type']) . '")';
         $aFq[] = $sFqType;
     }
     $this->aOptions['editor'] = $this->oSearchRequest->sEditor;
     if (!empty($this->aOptions['editor'])) {
         // there may be spaces in name of editor. solr analyses those to two
         // terms (editor's names) thus we wrap the name into quotation marks
         // todo: better: in schema.xml define field editor not to be tokenized
         //       at whitespace
         // but: +editor:("Robert V" "Mathias S") is already split correctly!
         $sFqEditor = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=ed}' : '';
         $sFqEditor .= 'editor:("' . implode('"' . $sLogOp . '"', $this->aOptions['editor']) . '")';
         $aFq[] = $sFqEditor;
     }
     // Boost query
     foreach ($wgContentNamespaces as $iNs) {
         $aBq[] = "namespace:{$iNs}^2";
     }
     // We want that files are also seen as a content namespace
     $aBq[] = "namespace:999^2";
     $searchLimit = BsConfig::get('MW::ExtendedSearch::LimitResults');
     $this->aOptions['offset'] = $this->oSearchRequest->iOffset;
     $this->aOptions['order'] = $this->oSearchRequest->sOrder;
     $this->aOptions['asc'] = $this->oSearchRequest->sAsc;
     $this->aOptions['searchLimit'] = $searchLimit == 0 ? 15 : $searchLimit;
     $this->aOptions['titleExists'] = ExtendedSearchBase::titleExists($this->oSearchRequest->sInput, $this->aOptions);
     $this->aOptions['bExtendedForm'] = $this->oSearchRequest->bExtendedForm;
     $this->aSearchOptions['defType'] = 'edismax';
     $this->aSearchOptions['fl'] = 'uid,type,title,path,namespace,cat,ts,redirects,overall_type';
     $this->aSearchOptions['fq'] = $aFq;
     $this->aSearchOptions['sort'] = $this->aOptions['order'] . ' ' . $this->aOptions['asc'];
     $this->aSearchOptions['hl'] = 'on';
     $this->aSearchOptions['hl.fl'] = 'titleWord, titleReverse, sections, textWord, textReverse';
     $this->aSearchOptions['hl.snippets'] = BsConfig::get('MW::ExtendedSearch::HighlightSnippets');
     $this->aSearchOptions['bq'] = implode(' ', $aBq);
     if (BsConfig::get('MW::ExtendedSearch::ShowFacets')) {
         $this->aSearchOptions['facet'] = 'on';
         $this->aSearchOptions['facet.sort'] = 'false';
         $this->aSearchOptions['facet.mincount'] = '1';
         $this->aSearchOptions['facet.missing'] = 'true';
         $this->aSearchOptions['facet.field'] = array();
         $this->aSearchOptions['facet.field'][] = $bTagNamespace === true ? '{!ex=na}namespace' : 'namespace';
         $this->aSearchOptions['facet.field'][] = isset($sFqCategories) ? '{!ex=ca}cat' : 'cat';
         $this->aSearchOptions['facet.field'][] = isset($sFqType) ? '{!ex=ty}type' : 'type';
         $this->aSearchOptions['facet.field'][] = isset($sFqEditor) ? '{!ex=ed}editor' : 'editor';
     }
 }
Exemplo n.º 12
0
<?php

$keywords = $_GET['keywords'];
$next_id = intval($_GET['next_id']);
if ($next_id < 0) {
    $next_id = 0;
}
$count = intval($_GET['count']);
if ($count <= 0) {
    $count = 10;
}
$service = new SearchService();
$acts = $service->search_activity($keywords, $next_id, $count);
echo json_encode(array("total" => count($acts), "result" => $acts));
Exemplo n.º 13
0
 public function search($argv)
 {
     $searchService = new SearchService();
     if ($argv[0] === './repose') {
         array_shift($argv);
         // $argv[0]  repose script
         array_shift($argv);
         // $argv[1]  search cmd
     }
     $return = array_shift($argv);
     // $argv[2]  return mode    (show|return)
     $unit = array_shift($argv);
     // $argv[3]  unit to search ('all'|'disk'|'volume'|'collection'):name
     $terms = $argv;
     // remainder is terms (key:matchval)
     $searchService->search(compact('return', 'unit', 'terms'));
 }
 /**
  * Returns status information of delete index progress.
  * Error is indicated by return false or return null
  * @return string information about the Progress or error message.
  */
 public function getDeleteFeedback()
 {
     $sForm = '';
     $oSolr = SearchService::getInstance();
     if ($oSolr === null) {
         return '';
     }
     try {
         $iStatus = $oSolr->deleteIndex();
         if ($iStatus == 200) {
             $iStatus = $oSolr->deleteIndex();
             $sForm .= wfMessage('bs-extendedsearch-index-successfully-deleted')->plain() . '<br />';
         } else {
             $sForm .= wfMessage('bs-extendedsearch-index-error-deleting', $iStatus)->plain() . '<br />';
         }
     } catch (Exception $e) {
         $sForm .= wfMessage('bs-extendedsearch-no-success-deleting', $e->getMessage())->plain() . '<br />';
         $sForm .= $e->getMessage();
     }
     return $sForm;
 }
Exemplo n.º 15
0
<?
	require ('../Util/SearchUtil.php');
	require ('../Service/SearchService.php');
	
	$options = array (
			'query' => 'Gibson "les paul"',
			'minAsk' => 20000,
		);
	
	$domains = array ('sfbay', 'newyork');
	$type = 'msg';

	$ss = new SearchService ($options, $type, $domains);
	$ss->search ();
	
	$options['query'] = '"Les  paul" giBSON';
	$ss = new SearchService ($options, $type, $domains);
	$ss->search ();	
?>
 public function execute()
 {
     $params = $this->extractRequestParams();
     //HINT: includes/api/ApiFeedContributions.php
     //HINT: includes/api/ApiFeedWatchlist.php
     global $wgSitename, $wgLanguageCode, $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry, $wgFeed, $wgFeedClasses;
     if (!$wgFeed) {
         $this->dieUsage('Syndication feeds are not available', 'feed-unavailable');
     }
     if (!isset($wgFeedClasses[$params['feedformat']])) {
         $this->dieUsage('Invalid subscription feed type', 'feed-invalid');
     }
     $msg = wfMessage('specialextendedsearch')->inContentLanguage()->text();
     $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
     $feedUrl = SpecialPage::getTitleFor('SpecialExtendedSearch')->getFullURL();
     $feed = new $wgFeedClasses[$params['feedformat']]($feedTitle, htmlspecialchars($msg), $feedUrl);
     $feedItems = array();
     try {
         $oSearchService = SearchService::getInstance();
         $oSearchRequest = new BsSearchRequest('apifeed');
         $oSearchRequestMW = new SearchRequestMW($oSearchRequest);
         $oSearchOptions = new SearchOptions($oSearchRequestMW);
         // Prepare search input
         $sSearchString = $params['q'];
         $sSearchString = urldecode($sSearchString);
         $sSearchString = BsSearchService::preprocessSearchInput($sSearchString);
         $sSearchString = BsSearchService::sanitzeSearchString($sSearchString);
         // Make solr query suitable for autocomplete
         $aSolrQuery = $oSearchOptions->getSolrQuery();
         //$sSearchString = 'titleWord:("'.$params['q'].'") OR titleWord:('.$params['q'].') OR titleReverse:(*'.$params['q'].'*) OR textWord:("'.$params['q'].'") OR textWord:('.$params['q'].') OR textReverse:(*'.$params['q'].'*)';
         $sSearchString = 'titleWord:(' . $sSearchString . ') OR titleWord:(' . $sSearchString . '*) OR titleReverse:(*' . $sSearchString . '*) OR textWord:(' . $sSearchString . ') OR textReverse:(*' . $sSearchString . '*)';
         $aSearchOptions = $aSolrQuery['searchOptions'];
         $aSearchOptions['facet'] = 'off';
         $aSearchOptions['hl'] = 'on';
         $aSearchOptions['hl.fl'] = 'textWord, textReverse';
         $aSearchOptions['hl.snippets'] = 3;
         // params are query, offset, limit, params
         $aHits = $oSearchService->search($sSearchString, 0, 25, $aSearchOptions);
         foreach ($aHits->response->docs as $doc) {
             if ($doc->namespace != '999') {
                 $oTitle = Title::makeTitle($doc->namespace, $doc->title);
             } else {
                 continue;
             }
             if (!$oTitle->userCan('read')) {
                 continue;
             }
             $oHighlightData = $aHits->highlighting->{$doc->uid};
             if (isset($oHighlightData->textWord)) {
                 $aHighlightsnippets = $oHighlightData->textWord;
             } else {
                 if (isset($oHighlightData->textReverse)) {
                     $aHighlightsnippets = $oHighlightData->textReverse;
                 }
             }
             $sTextFragment = '';
             foreach ($aHighlightsnippets as $sFrag) {
                 $sFrag = strip_tags($sFrag, '<em>');
                 if (empty($sFrag)) {
                     continue;
                 }
                 $sTextFragment .= "{$sFrag}<br />";
             }
             $feedItems[] = new FeedItem($doc->title, $sTextFragment, $oTitle->getFullURL());
         }
     } catch (Exception $e) {
         $this->dieUsage($e->getMessage(), 'feed-invalid');
     }
     ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
 }
Exemplo n.º 17
0
 /**
  * check if show field is legal
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   string      $infoType           bug,case or result
  * @param   array       $searchRowArr       search condition
  * @param   int         $productId          product id
  * @param   array       $showFieldArr       show field array
  * @param   array       $orderArr           order array
  * @param   string      $filterSql          filter sql
  * @param   int         $pageSize           page size
  * @param   int         $currentPageSize    current page size
  * @return  array                           export date result
  */
 public static function getExportData($infoType, $searchRowArr, $productId = null, $showFieldArr = null, $orderArr = null, $filterSql = null, $pageSize = null, $currentPage = null)
 {
     $resultInfo = array();
     if (!empty($productId)) {
         $accessIdArr = Yii::app()->user->getState('visit_product_id');
         if (!in_array($productId, $accessIdArr)) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail'] = Yii::t('Product', 'No access right to this product');
             return $resultInfo;
         }
     }
     $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId);
     $checkSearchRowResult = self::checkSearchRowField($searchFieldConfig, $searchRowArr);
     if ('' != $checkSearchRowResult) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $checkSearchRowResult;
         return $resultInfo;
     }
     if (!empty($showFieldArr)) {
         $showFieldCheckResult = self::checkShowField($searchFieldConfig, $showFieldArr);
         if ('' != $showFieldCheckResult) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail'] = $showFieldCheckResult;
             return $resultInfo;
         }
     }
     $getSqlResult = SqlService::baseGetGroupQueryStr($searchFieldConfig, $infoType, $searchRowArr);
     if (CommonService::$ApiResult['FAIL'] == $getSqlResult['status']) {
         $resultInfo = $getSqlResult;
         return $resultInfo;
     }
     $whereStr = $getSqlResult['detail'];
     if (!empty($filterSql)) {
         $whereStr .= ' and ' . $filterSql;
     }
     if (empty($showFieldArr)) {
         $showFieldArr = array_keys($searchFieldConfig);
         $showFieldArr = array_diff($showFieldArr, array(Info::MARK));
     }
     $allRelatedFieldArr = array();
     foreach ($searchRowArr as $searchRowTmp) {
         $allRelatedFieldArr[] = $searchRowTmp['field'];
     }
     $isAllBasicField = SearchService::isAllBasicField(SearchService::getBasicFieldArr($infoType), array_merge($showFieldArr, $allRelatedFieldArr));
     $sql = SqlService::getRawDataSql($searchFieldConfig, $infoType, $productId, $showFieldArr, $whereStr, $isAllBasicField);
     $totalNum = SqlService::getTotalFoundNum($infoType, $productId, $whereStr, $isAllBasicField);
     if (empty($pageSize)) {
         $pageSize = $totalNum;
     }
     if ($pageSize > 5000) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = 'items can not exceed 5000';
         return $resultInfo;
     }
     if (!isset($currentPage)) {
         $currentPage = 1;
     } else {
         if (0 == $currentPage) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail'] = 'page should start from 1';
             return $resultInfo;
         }
         $maxPage = ceil($totalNum / $pageSize);
         if ($currentPage > $maxPage && 0 != $maxPage) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail'] = 'current page [' . $currentPage . '] is greater than the max page [' . $maxPage . ']';
             return $resultInfo;
         }
     }
     if (empty($orderArr)) {
         $orderArr = array('{{bug_info_view}}.id' => true);
     }
     $dataProvider = new CSqlDataProvider($sql, array('totalItemCount' => $totalNum, 'sort' => array('defaultOrder' => $orderArr, 'attributes' => array_keys($searchFieldConfig)), 'pagination' => array('pageSize' => $pageSize, 'currentPage' => $currentPage - 1)));
     $rawData = $dataProvider->getData();
     $rawData = SqlService::handleRawData($rawData, $infoType, $searchFieldConfig, $showFieldArr, $productId);
     $rawData = self::getExportComment($infoType, $rawData, $productId);
     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
     $resultInfo['detail'] = $rawData;
     return $resultInfo;
 }
Exemplo n.º 18
0
 /**
  * There's some built in services that we're going to load first. 
  *
  * @return an array of services created
  */
 private function loadDefaultServices()
 {
     $services = new ArrayObject();
     $dbService = new DbService();
     if (isset($this->config['services']['DbService'])) {
         $dbService->configure($this->config['services']['DbService']);
     }
     $this->injector->registerService($dbService);
     $services[] = $dbService;
     $service = new TypeManager();
     if (isset($this->config['services']['TypeManager'])) {
         $service->configure(ifset($this->config['services'], 'TypeManager', array()));
     }
     $this->injector->registerService($service);
     $services[] = $service;
     $service = new SearchService();
     if (isset($this->config['services']['SearchService'])) {
         $service->configure($this->config['services']['SearchService']);
     }
     $this->injector->registerService($service);
     $services[] = $service;
     $authService = new AuthService();
     if (isset($this->config['services']['AuthService'])) {
         $authService->configure($this->config['services']['AuthService']);
     }
     $this->injector->registerService($authService);
     $services[] = $authService;
     $authComponent = new AuthComponent();
     if (isset($this->config['services']['AuthComponent'])) {
         $authComponent->configure($this->config['services']['AuthComponent']);
     }
     $this->injector->registerService($authComponent);
     $services[] = $authComponent;
     $tasksService = new ScheduledTasksService();
     $this->injector->registerService($tasksService);
     $services[] = $tasksService;
     $accessService = new AccessService();
     $this->injector->registerService($accessService);
     $services[] = $accessService;
     $cacheService = new CacheService();
     $this->injector->registerService($cacheService);
     $services[] = $cacheService;
     if (isset($this->config['services']['CacheService'])) {
         $cacheService->configure($this->config['services']['CacheService']);
     }
     $service = new VersioningService();
     $this->injector->registerService($service);
     $services[] = $service;
     if (isset($this->config['services']['VersioningService'])) {
         $service->configure($this->config['services']['VersioningService']);
     }
     return $services;
 }
Exemplo n.º 19
0
<?php

require_once 'config.php';
require_once ykfile('source/search_service.php');
$keyword = $_GET['keyword'];
if (!empty($keyword)) {
    //注意文件的编码格式需要保存为为UTF-8格式
    require "sphinxapi.php";
    $cl = new SphinxClient();
    $cl->SetServer('127.0.0.1', 9312);
    //以下设置用于返回数组形式的结果
    $cl->SetArrayResult(true);
    $keyword = $_GET['keyword'];
    //在做索引时,没有进行 sql_attr_类型 设置的字段,可以作为“搜索字符串”,进行全文搜索
    $res = $cl->Query("{$keyword}", "activity");
    //"*"表示在所有索引里面同时搜索,"索引名称(例如test或者test,test2)"则表示搜索指定的
    $seasrv = new SearchService();
    foreach ($res['matches'] as $result) {
        $id[] = $result['id'];
    }
    $activity_list = $seasrv->get_act_by_ids($id);
}
$page_title = "搜索";
include ykfile('pages/search.php');
Exemplo n.º 20
0
<?php

require_once ykfile('source/search_service.php');
$service = new SearchService();
$words = $service->get_words();
echo json_encode(array("hotwords" => $words));
 /**
  * Starts a autocomplete search
  * @param string $sSearchString Reference to given search string
  * @param boolean $vNsSearch bool always false
  * @return array Array of Apache_Solr_Documents
  */
 private static function searchAutocomplete(&$sSearchString, &$vNsSearch)
 {
     $oSerachService = SearchService::getInstance();
     $oSearchRequest = new SearchRequest();
     $oSearchRequest->init();
     $oSearchOptions = new SearchOptions($oSearchRequest, RequestContext::getMain());
     $oSearchOptions->readInSearchRequest();
     $sSearchString = urldecode($sSearchString);
     $sSolrSearchString = self::preprocessSearchInput($sSearchString);
     $aQuery = $oSearchOptions->getSolrAutocompleteQuery($sSearchString, $sSolrSearchString);
     try {
         $oHits = $oSerachService->search($aQuery['searchString'], $aQuery['offset'], $aQuery['searchLimit'], $aQuery['searchOptions']);
     } catch (Exception $e) {
         return '';
     }
     $oDocuments = $oHits->response->docs;
     if ($aQuery['namespace'] !== false) {
         $vNsSearch = $aQuery['namespace'];
     }
     $bEscalateToFuzzy = $oHits->response->numFound == 0;
     // boolean!
     // Escalate to fuzzy
     if ($bEscalateToFuzzy) {
         $oSearchOptions->setOption('scope', 'title');
         $aFuzzyQuery = $oSearchOptions->getSolrFuzzyQuery($sSolrSearchString);
         $aFuzzyQuery['searchLimit'] = BsConfig::get('MW::ExtendedSearch::AcEntries');
         $aFuzzyQuery['searchOptions']['facet'] = 'off';
         $aFuzzyQuery['searchOptions']['hl'] = 'off';
         try {
             $oHits = $oSerachService->search($aFuzzyQuery['searchString'], $aFuzzyQuery['offset'], $aFuzzyQuery['searchLimit'], $aFuzzyQuery['searchOptions']);
         } catch (Exception $e) {
             return '';
         }
         $oDocuments = $oHits->response->docs;
     }
     return $oDocuments;
 }