/**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function setUp()
 {
     parent::setUp();
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     // Set up our mock database
     JFactory::$database = $this->getMockDatabase('Mysqli');
     FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function setUp()
 {
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     // Set up our mock database
     $db = JFactory::getDbo();
     $db->name = 'mysqli';
     JFactory::$database = $db;
     FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
 }
示例#3
0
 /**
  * Method to get the base word of a token. This method uses the public
  * {@link FinderIndexerHelper::$stemmer} object if it is set. If no stemmer is set,
  * the original token is returned.
  *
  * @param   string  $token  The token to stem.
  * @param   string  $lang   The language of the token.
  *
  * @return  string  The root token.
  *
  * @since   2.5
  */
 public static function stem($token, $lang)
 {
     // Trim apostrophes at either end of the token.
     $token = StringHelper::trim($token, '\'');
     // Trim everything after any apostrophe in the token.
     if (($pos = StringHelper::strpos($token, '\'')) !== false) {
         $token = StringHelper::substr($token, 0, $pos);
     }
     // Stem the token if we have a valid stemmer to use.
     if (static::$stemmer instanceof FinderIndexerStemmer) {
         return static::$stemmer->stem($token, $lang);
     }
     return $token;
 }
示例#4
0
 /**
  * Method to auto-populate the model state.  Calling getState in this method will result in recursion.
  *
  * @param   string  $ordering   An optional ordering field. [optional]
  * @param   string  $direction  An optional direction. [optional]
  *
  * @return  void
  *
  * @since   2.5
  */
 protected function populateState($ordering = null, $direction = null)
 {
     // Get the configuration options.
     $app = JFactory::getApplication();
     $input = $app->input;
     $params = $app->getParams();
     $user = JFactory::getUser();
     $filter = JFilterInput::getInstance();
     $this->setState('filter.language', JLanguageMultilang::isEnabled());
     // Setup the stemmer.
     if ($params->get('stem', 1) && $params->get('stemmer', 'porter_en')) {
         FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance($params->get('stemmer', 'porter_en'));
     }
     $request = $input->request;
     $options = array();
     // Get the query string.
     $options['input'] = !is_null($request->get('q')) ? $request->get('q', '', 'string') : $params->get('q');
     $options['input'] = $filter->clean($options['input'], 'string');
     // Get the empty query setting.
     $options['empty'] = $params->get('allow_empty_query', 0);
     // Get the query language.
     $options['language'] = !is_null($request->get('l')) ? $request->get('l', '', 'cmd') : $params->get('l');
     $options['language'] = $filter->clean($options['language'], 'cmd');
     // Get the static taxonomy filters.
     $options['filter'] = !is_null($request->get('f')) ? $request->get('f', '', 'int') : $params->get('f');
     $options['filter'] = $filter->clean($options['filter'], 'int');
     // Get the dynamic taxonomy filters.
     $options['filters'] = !is_null($request->get('t', '', 'array')) ? $request->get('t', '', 'array') : $params->get('t');
     $options['filters'] = $filter->clean($options['filters'], 'array');
     JArrayHelper::toInteger($options['filters']);
     // Get the start date and start date modifier filters.
     $options['date1'] = !is_null($request->get('d1')) ? $request->get('d1', '', 'string') : $params->get('d1');
     $options['date1'] = $filter->clean($options['date1'], 'string');
     $options['when1'] = !is_null($request->get('w1')) ? $request->get('w1', '', 'string') : $params->get('w1');
     $options['when1'] = $filter->clean($options['when1'], 'string');
     // Get the end date and end date modifier filters.
     $options['date2'] = !is_null($request->get('d2')) ? $request->get('d2', '', 'string') : $params->get('d2');
     $options['date2'] = $filter->clean($options['date2'], 'string');
     $options['when2'] = !is_null($request->get('w2')) ? $request->get('w2', '', 'string') : $params->get('w2');
     $options['when2'] = $filter->clean($options['when2'], 'string');
     // Load the query object.
     $this->query = new FinderIndexerQuery($options);
     // Load the query token data.
     $this->excludedTerms = $this->query->getExcludedTermIds();
     $this->includedTerms = $this->query->getIncludedTermIds();
     $this->requiredTerms = $this->query->getRequiredTermIds();
     // Load the list state.
     $this->setState('list.start', $input->get('limitstart', 0, 'uint'));
     $this->setState('list.limit', $input->get('limit', $app->getCfg('list_limit', 20), 'uint'));
     // Load the sort ordering.
     $order = $params->get('sort_order', 'relevance');
     switch ($order) {
         case 'date':
             $this->setState('list.ordering', 'l.start_date');
             break;
         case 'price':
             $this->setState('list.ordering', 'l.list_price');
             break;
         case $order == 'relevance' && !empty($this->includedTerms):
             $this->setState('list.ordering', 'm.weight');
             break;
         default:
             $this->setState('list.ordering', 'l.link_id');
             break;
     }
     // Load the sort direction.
     $dirn = $params->get('sort_direction', 'desc');
     switch ($dirn) {
         case 'asc':
             $this->setState('list.direction', 'ASC');
             break;
         default:
         case 'desc':
             $this->setState('list.direction', 'DESC');
             break;
     }
     // Set the match limit.
     $this->setState('match.limit', 1000);
     // Load the parameters.
     $this->setState('params', $params);
     // Load the user state.
     $this->setState('user.id', (int) $user->get('id'));
     $this->setState('user.groups', $user->getAuthorisedViewLevels());
 }
示例#5
0
 /**
  * Method to auto-populate the model state.  Calling getState in this method will result in recursion.
  *
  * @param   string  $ordering   An optional ordering field. [optional]
  * @param   string  $direction  An optional direction. [optional]
  *
  * @return  void
  *
  * @since   2.5
  */
 protected function populateState($ordering = null, $direction = null)
 {
     // Get the configuration options.
     $app = JFactory::getApplication();
     $input = $app->input;
     $params = $app->getParams();
     $user = JFactory::getUser();
     $filter = JFilterInput::getInstance();
     $this->setState('filter.language', JLanguageMultilang::isEnabled());
     // Setup the stemmer.
     if ($params->get('stem', 1) && $params->get('stemmer', 'porter_en')) {
         FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance($params->get('stemmer', 'porter_en'));
     }
     $request = $input->request;
     $options = array();
     // Get the empty query setting.
     $options['empty'] = $params->get('allow_empty_query', 0);
     // Get the static taxonomy filters.
     $options['filter'] = $request->getInt('f', $params->get('f', ''));
     // Get the dynamic taxonomy filters.
     $options['filters'] = $request->get('t', $params->get('t', array()), '', 'array');
     // Get the query string.
     $options['input'] = $request->getString('q', $params->get('q', ''));
     // Get the query language.
     $options['language'] = $request->getCmd('l', $params->get('l', ''));
     // Get the start date and start date modifier filters.
     $options['date1'] = $request->getString('d1', $params->get('d1', ''));
     $options['when1'] = $request->getString('w1', $params->get('w1', ''));
     // Get the end date and end date modifier filters.
     $options['date2'] = $request->getString('d2', $params->get('d2', ''));
     $options['when2'] = $request->getString('w2', $params->get('w2', ''));
     // Load the query object.
     $this->query = new FinderIndexerQuery($options);
     // Load the query token data.
     $this->excludedTerms = $this->query->getExcludedTermIds();
     $this->includedTerms = $this->query->getIncludedTermIds();
     $this->requiredTerms = $this->query->getRequiredTermIds();
     // Load the list state.
     $this->setState('list.start', $input->get('limitstart', 0, 'uint'));
     $this->setState('list.limit', $input->get('limit', $app->get('list_limit', 20), 'uint'));
     /* Load the sort ordering.
      * Currently this is 'hard' coded via menu item parameter but may not satisfy a users need.
      * More flexibility was way more user friendly. So we allow the user to pass a custom value
      * from the pool of fields that are indexed like the 'title' field.
      * Also, we allow this parameter to be passed in either case (lower/upper).
      */
     $order = $input->getWord('filter_order', $params->get('sort_order', 'relevance'));
     $order = JString::strtolower($order);
     switch ($order) {
         case 'date':
             $this->setState('list.ordering', 'l.start_date');
             break;
         case 'price':
             $this->setState('list.ordering', 'l.list_price');
             break;
         case $order == 'relevance' && !empty($this->includedTerms):
             $this->setState('list.ordering', 'm.weight');
             break;
             // custom field that is indexed and might be required for ordering
         // custom field that is indexed and might be required for ordering
         case 'title':
             $this->setState('list.ordering', 'l.title');
             break;
         default:
             $this->setState('list.ordering', 'l.link_id');
             break;
     }
     /* Load the sort direction.
      * Currently this is 'hard' coded via menu item parameter but may not satisfy a users need.
      * More flexibility was way more user friendly. So we allow to be inverted.
      * Also, we allow this parameter to be passed in either case (lower/upper).
      */
     $dirn = $input->getWord('filter_order_Dir', $params->get('sort_direction', 'desc'));
     $dirn = JString::strtolower($dirn);
     switch ($dirn) {
         case 'asc':
             $this->setState('list.direction', 'ASC');
             break;
         default:
         case 'desc':
             $this->setState('list.direction', 'DESC');
             break;
     }
     // Set the match limit.
     $this->setState('match.limit', 1000);
     // Load the parameters.
     $this->setState('params', $params);
     // Load the user state.
     $this->setState('user.id', (int) $user->get('id'));
     $this->setState('user.groups', $user->getAuthorisedViewLevels());
 }
示例#6
0
 /**
  * Method to get the indexer state.
  *
  * @return  object  The indexer state object.
  *
  * @since   2.5
  */
 public static function getState()
 {
     // First, try to load from the internal state.
     if (!empty(self::$state)) {
         return self::$state;
     }
     // If we couldn't load from the internal state, try the session.
     $session = JFactory::getSession();
     $data = $session->get('_finder.state', null);
     // If the state is empty, load the values for the first time.
     if (empty($data)) {
         $data = new JObject();
         // Load the default configuration options.
         $data->options = JComponentHelper::getParams('com_finder');
         // Setup the weight lookup information.
         $data->weights = array(self::TITLE_CONTEXT => round($data->options->get('title_multiplier', 1.7), 2), self::TEXT_CONTEXT => round($data->options->get('text_multiplier', 0.7), 2), self::META_CONTEXT => round($data->options->get('meta_multiplier', 1.2), 2), self::PATH_CONTEXT => round($data->options->get('path_multiplier', 2.0), 2), self::MISC_CONTEXT => round($data->options->get('misc_multiplier', 0.3), 2));
         // Set the current time as the start time.
         $data->startTime = JFactory::getDate()->toSql();
         // Set the remaining default values.
         $data->batchSize = (int) $data->options->get('batch_size', 50);
         $data->batchOffset = 0;
         $data->totalItems = 0;
         $data->pluginState = array();
     }
     // Setup the profiler if debugging is enabled.
     if (JFactory::getApplication()->get('debug')) {
         self::$profiler = JProfiler::getInstance('FinderIndexer');
     }
     // Setup the stemmer.
     if ($data->options->get('stem', 1) && $data->options->get('stemmer', 'porter_en')) {
         FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance($data->options->get('stemmer', 'porter_en'));
     }
     // Set the state.
     self::$state = $data;
     return self::$state;
 }
示例#7
0
 * @since 1.5
 */
class plgSearchStreams extends JPlugin
{
    /**
	 * Constructor
	 *
	 * For php4 compatability we must not use the __constructor as a constructor for plugins
	 * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
	 * This causes problems with cross-referencing necessary for the observer design pattern.
	 *
	 * @param 	object $subject The object to observe
	 * @param 	array  $config  An array that holds the plugin configuration
	 * @since 1.5
	 */
    public function __construct(&$subject, $config)
    {
        parent::__construct($subject, $config);
        //$this->loadLanguage();
    }
    /**
	 * Display the button
	 *
	 * @return array A two element array of ( imageName, textToInsert )
	 */
    function onContentSearch()
    {
        //global $mainframe;
        $mainframe = JFactory::getApplication();
        $args = func_get_args();
        if (empty($args[0])) {
            return array();
        }
        // array(4) { [0]=> string(10) "she is asd" [1]=> string(5) "exact/all/any" [2]=> string(6) "oldest/newest/alpha/category/popular" [3]=> NULL }
        // Group ID and Filter Range will be from "areas" parameter in com_search form
        if (is_null($args[3])) {
            $areas = 0;
        } else {
            $areas = is_array($args[3]) ? $args[3][0] : $args[3];
        }
        if (preg_match('/_\\d\\w$/', $areas)) {
            $splitVal = explode('_', $areas);
            $groupId = $splitVal[0];
            $filterRange = $splitVal[1];
            // _2w (2 weeks), _1m (1 month), _3m (3 months), _0a (all)
            $rangeCond = $this->_getDateRange($filterRange);
        } else {
            // no filter range info provided;
            $groupId = $areas;
            $filterRange = '0a';
            $rangeCond = $this->_getDateRange($filterRange);
        }
        // search for all/streams/comments/files/people is from "searchphrase" parameter in com_search form
        $searchFor = $args[1];
        // custom class loader
        JLoader::register('FinderIndexerStemmer', FINDER_PATH_INDEXER . '/stemmer.php');
        FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
        // option porter_en/snowball
        //FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('snowball'); // option porter_en/snowball
        $option = array("input" => $args[0], "empty" => "0", "language" => "", "filter" => 0, "filters" => array());
        $keyTerm = new FinderIndexerQuery($option);
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        // This part get all groups that the logined user is permitted to see.
        $my = JXFactory::getUser();
        if (!$my->isAdmin()) {
            $query->select('id');
            $query->from('#__groups');
            // group must not be archived and access is public
            $query->where(' ( ' . $db->quoteName('archived') . ' = 0 AND ' . $db->quoteName('access') . ' = 0 ) ', 'OR');
            // OR group is private and user is a member of the private group
            $query->where('( ' . $db->quoteName('access') . ' = 1 AND `members` REGEXP \'^' . $my->id . '[^0-9]|[^0-9]' . $my->id . '[^0-9]|[^0-9]' . $my->id . '$\'' . ' )');
            $db->setQuery($query);
            $allowGroups = $db->loadObjectList();
            for ($i = 0; $i < count($allowGroups); $i++) {
                $allowGroupId[] = $allowGroups[$i]->id;
            }
            $allowGroupId[] = 0;
            $allowGroupCond = ' ( group_id IN (' . implode(',', $allowGroupId) . ') ) ';
        } else {
            $allowGroupCond = '';
        }
        //$limit		= 20;
        $condStream = $condComment = $condFile = $condProfile = array();
        $stream = $comment = $files = $people = $user = $rec = array();
        $streamId = $userId = $keywords = array();
        $condition = '';
        $count = 0;
        foreach ($keyTerm->included as $searchKey) {
            $keywords[] = $searchKey->term;
            // prepare stream condition
            $condStream[$count] = " ( message LIKE " . $db->quote('%' . $searchKey->term . '%');
            // prepare comment condition
            //$condComment[$count]	= " ( comment LIKE ".$db->quote('%'.$searchKey->term.'%');
            // prepare files condition
            $condFile[$count] = " ( filename LIKE " . $db->quote('%' . $searchKey->term . '%');
            // prepare people condition
            $condProfile[$count] = " ( value LIKE " . $db->quote('%' . $searchKey->term . '%');
            $condUser[$count] = " ( name LIKE " . $db->quote('%' . $searchKey->term . '%') . " OR username LIKE " . $db->quote('%' . $searchKey->term . '%');
            if ($searchKey->term != $searchKey->stem) {
                $keywords[] = $searchKey->stem;
                $condStream[$count] .= " OR message LIKE " . $db->quote('%' . $searchKey->stem . '%');
                //$condComment[$count]	.= " OR comment LIKE ".$db->quote('%'.$searchKey->stem.'%');
                $condFile[$count] .= " OR filename LIKE " . $db->quote('%' . $searchKey->stem . '%');
                $condProfile[$count] .= " OR value LIKE " . $db->quote('%' . $searchKey->stem . '%');
                $condUser[$count] .= " OR name LIKE " . $db->quote('%' . $searchKey->stem . '%') . " OR username LIKE " . $db->quote('%' . $searchKey->stem . '%');
            }
            $condStream[$count] .= ' ) ';
            //$condComment[$count]	.= ' ) ';
            $condFile[$count] .= ' ) ';
            $condProfile[$count] .= ' ) ';
            $condUser[$count] .= ' ) ';
            $count++;
        }
        if ($searchFor == 'all' || $searchFor == 'streams') {
            // The following part search for the stream message itself
            $query->clear();
            $query->select('id, id as message_id, type, user_id, message, created');
            $query->from('#__stream');
            if (!empty($condStream)) {
                $query->where('(' . implode(" OR ", $condStream) . ')');
            }
            if ($groupId) {
                $query->where('group_id = ' . $db->quote($groupId));
            } else {
                if (!empty($allowGroupCond)) {
                    $query->where($allowGroupCond, 'OR');
                }
            }
            if (!empty($rangeCond)) {
                $query->where($rangeCond);
            }
            $query->order('created DESC');
            $stream = $this->_arrangeRecords($query, $streamId);
        }
        /*if ($searchFor == 'all' || $searchFor == 'comments')
		{
			// Get all stream messages where comment contains the search key words.
			$query->clear();
			$query->select('id, stream_id as message_id, "comment" as type, user_id, group_id, comment as message, created');
			$query->from('#__stream_comments');
			if (!empty($condComment))
			{
				$query->where('('.implode(" OR ", $condComment).')');
			}
			if ($groupId)
			{
				$query->where('group_id = '.$db->quote($groupId));	
			}
			if (!empty($rangeCond))
			{
				$query->where($rangeCond);
			}
			$query->order('created DESC');
			//echo $query;
			$comment = $this->_arrangeRecords($query, &$streamId);
		}
		*/
        if ($searchFor == 'all' || $searchFor == 'files') {
            // Get all files where filename contains the search key words.
            $query->clear();
            $query->select('id, stream_id as message_id, "files" as type, user_id, group_id, filename as message, created');
            $query->from('#__stream_files');
            if (!empty($condFile)) {
                $query->where('(' . implode(" OR ", $condFile) . ')');
            }
            if ($groupId) {
 /**
  * Tests the getInstance method with a non-existing parser
  *
  * @return  void
  *
  * @since   3.0
  *
  * @expectedException  Exception
  */
 public function testGetInstance_noParser()
 {
     FinderIndexerStemmer::getInstance('noway');
 }