Source for file token.php

Documentation is available at token.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_finder
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Token class for the Finder indexer package.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_finder
  17.  * @since       2.5
  18.  */
  19. {
  20.     /**
  21.      * This is the term that will be referenced in the terms table and the
  22.      * mapping tables.
  23.      *
  24.      * @var    string 
  25.      * @since  2.5
  26.      */
  27.     public $term;
  28.  
  29.     /**
  30.      * The stem is used to match the root term and produce more potential
  31.      * matches when searching the index.
  32.      *
  33.      * @var    string 
  34.      * @since  2.5
  35.      */
  36.     public $stem;
  37.  
  38.     /**
  39.      * If the token is numeric, it is likely to be short and uncommon so the
  40.      * weight is adjusted to compensate for that situation.
  41.      *
  42.      * @var    boolean 
  43.      * @since  2.5
  44.      */
  45.     public $numeric;
  46.  
  47.     /**
  48.      * If the token is a common term, the weight is adjusted to compensate for
  49.      * the higher frequency of the term in relation to other terms.
  50.      *
  51.      * @var    boolean 
  52.      * @since  2.5
  53.      */
  54.     public $common;
  55.  
  56.     /**
  57.      * Flag for phrase tokens.
  58.      *
  59.      * @var    boolean 
  60.      * @since  2.5
  61.      */
  62.     public $phrase;
  63.  
  64.     /**
  65.      * The length is used to calculate the weight of the token.
  66.      *
  67.      * @var    integer 
  68.      * @since  2.5
  69.      */
  70.     public $length;
  71.  
  72.     /**
  73.      * The weight is calculated based on token size and whether the token is
  74.      * considered a common term.
  75.      *
  76.      * @var    integer 
  77.      * @since  2.5
  78.      */
  79.     public $weight;
  80.  
  81.     /**
  82.      * The simple language identifier for the token.
  83.      *
  84.      * @var    string 
  85.      * @since  2.5
  86.      */
  87.     public $language;
  88.  
  89.     /**
  90.      * Method to construct the token object.
  91.      *
  92.      * @param   mixed   $term    The term as a string for words or an array for phrases.
  93.      * @param   string  $lang    The simple language identifier.
  94.      * @param   string  $spacer  The space separator for phrases. [optional]
  95.      *
  96.      * @since   2.5
  97.      */
  98.     public function __construct($term$lang$spacer ' ')
  99.     {
  100.         $this->language = $lang;
  101.  
  102.         // Tokens can be a single word or an array of words representing a phrase.
  103.         if (is_array($term))
  104.         {
  105.             // Populate the token instance.
  106.             $this->term = implode($spacer$term);
  107.             $this->stem = implode($spacerarray_map(array('FinderIndexerHelper''stem')$termarray($lang)));
  108.             $this->numeric = false;
  109.             $this->common = false;
  110.             $this->phrase = true;
  111.             $this->length = JString::strlen($this->term);
  112.  
  113.             /*
  114.              * Calculate the weight of the token.
  115.              *
  116.              * 1. Length of the token up to 30 and divide by 30, add 1.
  117.              * 2. Round weight to 4 decimal points.
  118.              */
  119.             $this->weight = (($this->length >= 30 30 $this->length301;
  120.             $this->weight = round($this->weight4);
  121.         }
  122.         else
  123.         {
  124.             // Populate the token instance.
  125.             $this->term = $term;
  126.             $this->stem = FinderIndexerHelper::stem($this->term$lang);
  127.             $this->numeric = (is_numeric($this->term|| (bool) preg_match('#^[0-9,.\-\+]+$#'$this->term));
  128.             $this->common = $this->numeric ? false FinderIndexerHelper::isCommon($this->term$lang);
  129.             $this->phrase = false;
  130.             $this->length = JString::strlen($this->term);
  131.  
  132.             /*
  133.              * Calculate the weight of the token.
  134.              *
  135.              * 1. Length of the token up to 15 and divide by 15.
  136.              * 2. If common term, divide weight by 8.
  137.              * 3. If numeric, multiply weight by 1.5.
  138.              * 4. Round weight to 4 decimal points.
  139.              */
  140.             $this->weight = (($this->length >= 15 15 $this->length15);
  141.             $this->weight = ($this->common == true $this->weight / $this->weight);
  142.             $this->weight = ($this->numeric == true $this->weight * 1.5 $this->weight);
  143.             $this->weight = round($this->weight4);
  144.         }
  145.     }
  146. }

Documentation generated on Tue, 19 Nov 2013 15:15:48 +0100 by phpDocumentor 1.4.3