Source for file postgresql.php

Documentation is available at postgresql.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. jimport('joomla.filesystem.file');
  13.  
  14. /**
  15.  * Indexer class supporting PostgreSQL for the Finder indexer package.
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  com_finder
  19.  * @since       3.0
  20.  */
  21. {
  22.     /**
  23.      * Method to index a content item.
  24.      *
  25.      * @param   FinderIndexerResult  $item    The content item to index.
  26.      * @param   string               $format  The format of the content. [optional]
  27.      *
  28.      * @return  integer  The ID of the record in the links table.
  29.      *
  30.      * @since   3.0
  31.      * @throws  Exception on database error.
  32.      */
  33.     public function index($item$format 'html')
  34.     {
  35.         // Mark beforeIndexing in the profiler.
  36.         static::$profiler static::$profiler->mark('beforeIndexing'null;
  37.         $db JFactory::getDbo();
  38.         $nd $db->getNullDate();
  39.  
  40.         // Check if the item is in the database.
  41.         $query $db->getQuery(true)
  42.             ->select($db->quoteName('link_id'', ' $db->quoteName('md5sum'))
  43.             ->from($db->quoteName('#__finder_links'))
  44.             ->where($db->quoteName('url'' = ' $db->quote($item->url));
  45.  
  46.         // Load the item  from the database.
  47.         $db->setQuery($query);
  48.         $link $db->loadObject();
  49.  
  50.         // Get the indexer state.
  51.         $state static::getState();
  52.  
  53.         // Get the signatures of the item.
  54.         $curSig static::getSignature($item);
  55.         $oldSig = isset($link->md5sum$link->md5sum null;
  56.  
  57.         // Get the other item information.
  58.         $linkId empty($link->link_idnull $link->link_id;
  59.         $isNew empty($link->link_idtrue false;
  60.  
  61.         // Check the signatures. If they match, the item is up to date.
  62.         if (!$isNew && $curSig == $oldSig)
  63.         {
  64.             return $linkId;
  65.         }
  66.  
  67.         /*
  68.          * If the link already exists, flush all the term maps for the item.
  69.          * Maps are stored in 16 tables so we need to iterate through and flush
  70.          * each table one at a time.
  71.          */
  72.         if (!$isNew)
  73.         {
  74.             for ($i 0$i <= 15$i++)
  75.             {
  76.                 // Flush the maps for the link.
  77.                 $query->clear()
  78.                     ->delete($db->quoteName('#__finder_links_terms' dechex($i)))
  79.                     ->where($db->quoteName('link_id'' = ' . (int) $linkId);
  80.                 $db->setQuery($query);
  81.                 $db->execute();
  82.             }
  83.  
  84.             // Remove the taxonomy maps.
  85.             FinderIndexerTaxonomy::removeMaps($linkId);
  86.         }
  87.  
  88.         // Mark afterUnmapping in the profiler.
  89.         static::$profiler static::$profiler->mark('afterUnmapping'null;
  90.  
  91.         // Perform cleanup on the item data.
  92.         $item->publish_start_date = (int) $item->publish_start_date != $item->publish_start_date $nd;
  93.         $item->publish_end_date = (int) $item->publish_end_date != $item->publish_end_date $nd;
  94.         $item->start_date = (int) $item->start_date != $item->start_date $nd;
  95.         $item->end_date = (int) $item->end_date != $item->end_date $nd;
  96.  
  97.         // Prepare the item description.
  98.         $item->description FinderIndexerHelper::parse($item->summary);
  99.  
  100.         /*
  101.          * Now, we need to enter the item into the links table. If the item
  102.          * already exists in the database, we need to use an UPDATE query.
  103.          * Otherwise, we need to use an INSERT to get the link id back.
  104.          */
  105.  
  106.         if ($isNew)
  107.         {
  108.             $columnsArray array(
  109.                 $db->quoteName('url')$db->quoteName('route')$db->quoteName('title')$db->quoteName('description'),
  110.                 $db->quoteName('indexdate')$db->quoteName('published')$db->quoteName('state')$db->quoteName('access'),
  111.                 $db->quoteName('language')$db->quoteName('type_id')$db->quoteName('object')$db->quoteName('publish_start_date'),
  112.                 $db->quoteName('publish_end_date')$db->quoteName('start_date')$db->quoteName('end_date')$db->quoteName('list_price'),
  113.                 $db->quoteName('sale_price')
  114.             );
  115.  
  116.             // Insert the link.
  117.             $query->clear()
  118.                 ->insert($db->quoteName('#__finder_links'))
  119.                 ->columns($columnsArray)
  120.                 ->values(
  121.                 $db->quote($item->url', '
  122.                 . $db->quote($item->route', '
  123.                 . $db->quote($item->title', '
  124.                 . $db->quote($item->description', '
  125.                 . $query->currentTimestamp(', '
  126.                 . '1, '
  127.                 . (int) $item->state ', '
  128.                 . (int) $item->access ', '
  129.                 . $db->quote($item->language', '
  130.                 . (int) $item->type_id ', '
  131.                 . $db->quote(serialize($item)) ', '
  132.                 . $db->quote($item->publish_start_date', '
  133.                 . $db->quote($item->publish_end_date', '
  134.                 . $db->quote($item->start_date', '
  135.                 . $db->quote($item->end_date', '
  136.                 . (double) ($item->list_price $item->list_price 0', '
  137.                 . (double) ($item->sale_price $item->sale_price 0)
  138.             );
  139.             $db->setQuery($query);
  140.             $db->execute();
  141.  
  142.             // Get the link id.
  143.             $linkId = (int) $db->insertid();
  144.         }
  145.         else
  146.         {
  147.             // Update the link.
  148.             $query->clear()
  149.                 ->update($db->quoteName('#__finder_links'))
  150.                 ->set($db->quoteName('route'' = ' $db->quote($item->route))
  151.                 ->set($db->quoteName('title'' = ' $db->quote($item->title))
  152.                 ->set($db->quoteName('description'' = ' $db->quote($item->description))
  153.                 ->set($db->quoteName('indexdate'' = ' $query->currentTimestamp())
  154.                 ->set($db->quoteName('state'' = ' . (int) $item->state)
  155.                 ->set($db->quoteName('access'' = ' . (int) $item->access)
  156.                 ->set($db->quoteName('language'' = ' $db->quote($item->language))
  157.                 ->set($db->quoteName('type_id'' = ' . (int) $item->type_id)
  158.                 ->set($db->quoteName('object'' = ' $db->quote(serialize($item)))
  159.                 ->set($db->quoteName('publish_start_date'' = ' $db->quote($item->publish_start_date))
  160.                 ->set($db->quoteName('publish_end_date'' = ' $db->quote($item->publish_end_date))
  161.                 ->set($db->quoteName('start_date'' = ' $db->quote($item->start_date))
  162.                 ->set($db->quoteName('end_date'' = ' $db->quote($item->end_date))
  163.                 ->set($db->quoteName('list_price'' = ' . (double) ($item->list_price $item->list_price 0))
  164.                 ->set($db->quoteName('sale_price'' = ' . (double) ($item->sale_price $item->sale_price 0))
  165.                 ->where('link_id = ' . (int) $linkId);
  166.             $db->setQuery($query);
  167.             $db->execute();
  168.         }
  169.  
  170.         // Set up the variables we will need during processing.
  171.         $count 0;
  172.  
  173.         // Mark afterLinking in the profiler.
  174.         static::$profiler static::$profiler->mark('afterLinking'null;
  175.  
  176.         // Truncate the tokens tables.
  177.         $db->truncateTable('#__finder_tokens');
  178.  
  179.         // Truncate the tokens aggregate table.
  180.         $db->truncateTable('#__finder_tokens_aggregate');
  181.  
  182.         /*
  183.          * Process the item's content. The items can customize their
  184.          * processing instructions to define extra properties to process
  185.          * or rearrange how properties are weighted.
  186.          */
  187.         foreach ($item->getInstructions(as $group => $properties)
  188.         {
  189.             // Iterate through the properties of the group.
  190.             foreach ($properties as $property)
  191.             {
  192.                 // Check if the property exists in the item.
  193.                 if (empty($item->$property))
  194.                 {
  195.                     continue;
  196.                 }
  197.  
  198.                 // Tokenize the property.
  199.                 if (is_array($item->$property))
  200.                 {
  201.                     // Tokenize an array of content and add it to the database.
  202.                     foreach ($item->$property as $ip)
  203.                     {
  204.                         /*
  205.                          * If the group is path, we need to a few extra processing
  206.                          * steps to strip the extension and convert slashes and dashes
  207.                          * to spaces.
  208.                          */
  209.                         if ($group === static::PATH_CONTEXT)
  210.                         {
  211.                             $ip JFile::stripExt($ip);
  212.                             $ip str_replace('/'' '$ip);
  213.                             $ip str_replace('-'' '$ip);
  214.                         }
  215.  
  216.                         // Tokenize a string of content and add it to the database.
  217.                         $count += $this->tokenizeToDB($ip$group$item->language$format);
  218.  
  219.                         // Check if we're approaching the memory limit of the token table.
  220.                         if ($count static::$state->options->get('memory_table_limit'30000))
  221.                         {
  222.                             $this->toggleTables(false);
  223.                         }
  224.                     }
  225.                 }
  226.                 else
  227.                 {
  228.                     /*
  229.                      * If the group is path, we need to a few extra processing
  230.                      * steps to strip the extension and convert slashes and dashes
  231.                      * to spaces.
  232.                      */
  233.                     if ($group === static::PATH_CONTEXT)
  234.                     {
  235.                         $item->$property JFile::stripExt($item->$property);
  236.                         $item->$property str_replace('/'' '$item->$property);
  237.                         $item->$property str_replace('-'' '$item->$property);
  238.                     }
  239.  
  240.                     // Tokenize a string of content and add it to the database.
  241.                     $count += $this->tokenizeToDB($item->$property$group$item->language$format);
  242.  
  243.                     // Check if we're approaching the memory limit of the token table.
  244.                     if ($count static::$state->options->get('memory_table_limit'30000))
  245.                     {
  246.                         $this->toggleTables(false);
  247.                     }
  248.                 }
  249.             }
  250.         }
  251.  
  252.         /*
  253.          * Process the item's taxonomy. The items can customize their
  254.          * taxonomy mappings to define extra properties to map.
  255.          */
  256.         foreach ($item->getTaxonomy(as $branch => $nodes)
  257.         {
  258.             // Iterate through the nodes and map them to the branch.
  259.             foreach ($nodes as $node)
  260.             {
  261.                 // Add the node to the tree.
  262.                 $nodeId FinderIndexerTaxonomy::addNode($branch$node->title$node->state$node->access);
  263.  
  264.                 // Add the link => node map.
  265.                 FinderIndexerTaxonomy::addMap($linkId$nodeId);
  266.  
  267.                 // Tokenize the node title and add them to the database.
  268.                 $count += $this->tokenizeToDB($node->titlestatic::META_CONTEXT$item->language$format);
  269.             }
  270.         }
  271.  
  272.         // Mark afterProcessing in the profiler.
  273.         static::$profiler static::$profiler->mark('afterProcessing'null;
  274.  
  275.         /*
  276.          * At this point, all of the item's content has been parsed, tokenized
  277.          * and inserted into the #__finder_tokens table. Now, we need to
  278.          * aggregate all the data into that table into a more usable form. The
  279.          * aggregated data will be inserted into #__finder_tokens_aggregate
  280.          * table.
  281.          */
  282.         $query    'INSERT INTO ' $db->quoteName('#__finder_tokens_aggregate'.
  283.                 ' (' $db->quoteName('term_id'.
  284.                 ', ' $db->quoteName('term'.
  285.                 ', ' $db->quoteName('stem'.
  286.                 ', ' $db->quoteName('common'.
  287.                 ', ' $db->quoteName('phrase'.
  288.                 ', ' $db->quoteName('term_weight'.
  289.                 ', ' $db->quoteName('context'.
  290.                 ', ' $db->quoteName('context_weight'.
  291.                 ', ' $db->quoteName('language'')' .
  292.                 ' SELECT' .
  293.                 ' t.term_id, t1.term, t1.stem, t1.common, t1.phrase, t1.weight, t1.context,' .
  294.                 ' ROUND( t1.weight * COUNT( t2.term ) * %F, 8 ) AS context_weight, t1.language' .
  295.                 ' FROM (' .
  296.                 '   SELECT DISTINCT t1.term, t1.stem, t1.common, t1.phrase, t1.weight, t1.context, t1.language' .
  297.                 '   FROM ' $db->quoteName('#__finder_tokens'' AS t1' .
  298.                 '   WHERE t1.context = %d' .
  299.                 ' ) AS t1' .
  300.                 ' JOIN ' $db->quoteName('#__finder_tokens'' AS t2 ON t2.term = t1.term' .
  301.                 ' LEFT JOIN ' $db->quoteName('#__finder_terms'' AS t ON t.term = t1.term' .
  302.                 ' WHERE t2.context = %d' .
  303.                 ' GROUP BY t1.term, t.term_id, t1.term, t1.stem, t1.common, t1.phrase, t1.weight, t1.context, t1.language' .
  304.                 ' ORDER BY t1.term DESC';
  305.  
  306.         // Iterate through the contexts and aggregate the tokens per context.
  307.         foreach ($state->weights as $context => $multiplier)
  308.         {
  309.             // Run the query to aggregate the tokens for this context..
  310.             $db->setQuery(sprintf($query$multiplier$context$context));
  311.             $db->execute();
  312.         }
  313.  
  314.         // Mark afterAggregating in the profiler.
  315.         static::$profiler static::$profiler->mark('afterAggregating'null;
  316.  
  317.         /*
  318.          * When we pulled down all of the aggregate data, we did a LEFT JOIN
  319.          * over the terms table to try to find all the term ids that
  320.          * already exist for our tokens. If any of the rows in the aggregate
  321.          * table have a term of 0, then no term record exists for that
  322.          * term so we need to add it to the terms table.
  323.          */
  324.         /* Emulation of IGNORE INTO behaviour */
  325.         $db->setQuery(
  326.             ' SELECT ta.term' .
  327.             ' FROM ' $db->quoteName('#__finder_tokens_aggregate'' AS ta' .
  328.             ' WHERE ta.term_id = 0'
  329.         );
  330.         if ($db->loadRow(== null)
  331.         {
  332.             $db->setQuery(
  333.                 'INSERT INTO ' $db->quoteName('#__finder_terms'.
  334.                 ' (' $db->quoteName('term'.
  335.                 ', ' $db->quoteName('stem'.
  336.                 ', ' $db->quoteName('common'.
  337.                 ', ' $db->quoteName('phrase'.
  338.                 ', ' $db->quoteName('weight'.
  339.                 ', ' $db->quoteName('soundex'.
  340.                 ', ' $db->quoteName('language'')' .
  341.                 ' SELECT ta.term, ta.stem, ta.common, ta.phrase, ta.term_weight, SOUNDEX(ta.term), ta.language' .
  342.                 ' FROM ' $db->quoteName('#__finder_tokens_aggregate'' AS ta' .
  343.                 ' WHERE ta.term_id = 0' .
  344.                 ' GROUP BY ta.term, ta.stem, ta.common, ta.phrase, ta.term_weight, SOUNDEX(ta.term), ta.language'
  345.             );
  346.             $db->execute();
  347.         }
  348.  
  349.         /*
  350.          * Now, we just inserted a bunch of new records into the terms table
  351.          * so we need to go back and update the aggregate table with all the
  352.          * new term ids.
  353.          */
  354.         $query $db->getQuery(true)
  355.             ->update($db->quoteName('#__finder_tokens_aggregate'' AS ta')
  356.             ->join('INNER'$db->quoteName('#__finder_terms'' AS t ON t.term = ta.term')
  357.             ->set('ta.term_id = t.term_id')
  358.             ->where('ta.term_id = 0');
  359.         $db->setQuery($query);
  360.         $db->execute();
  361.  
  362.         // Mark afterTerms in the profiler.
  363.         static::$profiler static::$profiler->mark('afterTerms'null;
  364.  
  365.         /*
  366.          * After we've made sure that all of the terms are in the terms table
  367.          * and the aggregate table has the correct term ids, we need to update
  368.          * the links counter for each term by one.
  369.          */
  370.         $query->clear()
  371.             ->update($db->quoteName('#__finder_terms'' AS t')
  372.             ->join('INNER'$db->quoteName('#__finder_tokens_aggregate'' AS ta ON ta.term_id = t.term_id')
  373.             ->set('t.' $db->quoteName('links'' = t.links + 1');
  374.         $db->setQuery($query);
  375.         $db->execute();
  376.  
  377.         // Mark afterTerms in the profiler.
  378.         static::$profiler static::$profiler->mark('afterTerms'null;
  379.  
  380.         /*
  381.          * Before we can insert all of the mapping rows, we have to figure out
  382.          * which mapping table the rows need to be inserted into. The mapping
  383.          * table for each term is based on the first character of the md5 of
  384.          * the first character of the term. In php, it would be expressed as
  385.          * substr(md5(substr($token, 0, 1)), 0, 1)
  386.          */
  387.         $query->clear()
  388.             ->update($db->quoteName('#__finder_tokens_aggregate'))
  389.             ->set($db->quoteName('map_suffix'' = SUBSTR(MD5(SUBSTR(' $db->quoteName('term'', 1, 1)), 1, 1)');
  390.         $db->setQuery($query);
  391.         $db->execute();
  392.  
  393.         /*
  394.          * At this point, the aggregate table contains a record for each
  395.          * term in each context. So, we're going to pull down all of that
  396.          * data while grouping the records by term and add all of the
  397.          * sub-totals together to arrive at the final total for each token for
  398.          * this link. Then, we insert all of that data into the appropriate
  399.          * mapping table.
  400.          */
  401.         for ($i 0$i <= 15$i++)
  402.         {
  403.             // Get the mapping table suffix.
  404.             $suffix dechex($i);
  405.  
  406.             /*
  407.              * We have to run this query 16 times, one for each link => term
  408.              * mapping table.
  409.              */
  410.             $db->setQuery(
  411.                 'INSERT INTO ' $db->quoteName('#__finder_links_terms' $suffix.
  412.                 ' (' $db->quoteName('link_id'.
  413.                 ', ' $db->quoteName('term_id'.
  414.                 ', ' $db->quoteName('weight'')' .
  415.                 ' SELECT ' . (int) $linkId ', ' $db->quoteName('term_id'',' .
  416.                 ' ROUND(SUM(' $db->quoteName('context_weight''), 8)' .
  417.                 ' FROM ' $db->quoteName('#__finder_tokens_aggregate'.
  418.                 ' WHERE ' $db->quoteName('map_suffix'' = ' $db->quote($suffix.
  419.                 ' GROUP BY ' $db->quoteName('term'.
  420.                 ' ORDER BY ' $db->quoteName('term'' DESC'
  421.             );
  422.             $db->execute();
  423.         }
  424.  
  425.         // Mark afterMapping in the profiler.
  426.         static::$profiler static::$profiler->mark('afterMapping'null;
  427.  
  428.         // Update the signature.
  429.         $query->clear()
  430.             ->update($db->quoteName('#__finder_links'))
  431.             ->set($db->quoteName('md5sum'' = ' $db->quote($curSig))
  432.             ->where($db->quoteName('link_id'' = ' $db->quote($linkId));
  433.         $db->setQuery($query);
  434.         $db->execute();
  435.  
  436.         // Mark afterSigning in the profiler.
  437.         static::$profiler static::$profiler->mark('afterSigning'null;
  438.  
  439.         // Truncate the tokens tables.
  440.         $db->truncateTable('#__finder_tokens');
  441.  
  442.         // Truncate the tokens aggregate table.
  443.         $db->truncateTable('#__finder_tokens_aggregate');
  444.  
  445.         // Toggle the token tables back to memory tables.
  446.         $this->toggleTables(true);
  447.  
  448.         // Mark afterTruncating in the profiler.
  449.         static::$profiler static::$profiler->mark('afterTruncating'null;
  450.  
  451.         return $linkId;
  452.     }
  453.  
  454.     /**
  455.      * Method to remove a link from the index.
  456.      *
  457.      * @param   integer  $linkId  The id of the link.
  458.      *
  459.      * @return  boolean  True on success.
  460.      *
  461.      * @since   2.5
  462.      * @throws  Exception on database error.
  463.      */
  464.     public function remove($linkId)
  465.     {
  466.         $db JFactory::getDbo();
  467.         $query $db->getQuery(true);
  468.  
  469.         // Update the link counts and remove the mapping records.
  470.         for ($i 0$i <= 15$i++)
  471.         {
  472.             // Update the link counts for the terms.
  473.             $query->update($db->quoteName('#__finder_terms'' AS t')
  474.                 ->join('INNER'$db->quoteName('#__finder_links_terms' dechex($i)) ' AS m ON m.term_id = t.term_id')
  475.                 ->set('t.links = t.links - 1')
  476.                 ->where('m.link_id = ' $db->quote((int) $linkId));
  477.             $db->setQuery($query);
  478.             $db->execute();
  479.  
  480.             // Remove all records from the mapping tables.
  481.             $query->clear()
  482.                 ->delete($db->quoteName('#__finder_links_terms' dechex($i)))
  483.                 ->where($db->quoteName('link_id'' = ' . (int) $linkId);
  484.             $db->setQuery($query);
  485.             $db->execute();
  486.         }
  487.  
  488.         // Delete all orphaned terms.
  489.         $query->clear()
  490.             ->delete($db->quoteName('#__finder_terms'))
  491.             ->where($db->quoteName('links'' <= 0');
  492.         $db->setQuery($query);
  493.         $db->execute();
  494.  
  495.         // Delete the link from the index.
  496.         $query->clear()
  497.             ->delete($db->quoteName('#__finder_links'))
  498.             ->where($db->quoteName('link_id'' = ' $db->quote((int) $linkId));
  499.         $db->setQuery($query);
  500.         $db->execute();
  501.  
  502.         // Remove the taxonomy maps.
  503.         FinderIndexerTaxonomy::removeMaps($linkId);
  504.  
  505.         // Remove the orphaned taxonomy nodes.
  506.  
  507.         return true;
  508.     }
  509.  
  510.     /**
  511.      * Method to optimize the index. We use this method to remove unused terms
  512.      * and any other optimizations that might be necessary.
  513.      *
  514.      * @return  boolean  True on success.
  515.      *
  516.      * @since   2.5
  517.      * @throws  Exception on database error.
  518.      */
  519.     public function optimize()
  520.     {
  521.         // Get the database object.
  522.         $db JFactory::getDbo();
  523.         $query $db->getQuery(true);
  524.  
  525.         // Delete all orphaned terms.
  526.         $query->delete($db->quoteName('#__finder_terms'))
  527.             ->where($db->quoteName('links'' <= 0');
  528.         $db->setQuery($query);
  529.         $db->execute();
  530.  
  531.         // Optimize the links table.
  532.         $db->setQuery('VACUUM ' $db->quoteName('#__finder_links'));
  533.         $db->execute();
  534.         $db->setQuery('REINDEX TABLE ' $db->quoteName('#__finder_links'));
  535.         $db->execute();
  536.  
  537.         for ($i 0$i <= 15$i++)
  538.         {
  539.             // Optimize the terms mapping table.
  540.             $db->setQuery('VACUUM ' $db->quoteName('#__finder_links_terms' dechex($i)));
  541.             $db->execute();
  542.             $db->setQuery('REINDEX TABLE ' $db->quoteName('#__finder_links_terms' dechex($i)));
  543.             $db->execute();
  544.         }
  545.  
  546.         // Optimize the terms mapping table.
  547.         $db->setQuery('REINDEX TABLE ' $db->quoteName('#__finder_links_terms'));
  548.         $db->execute();
  549.  
  550.         // Remove the orphaned taxonomy nodes.
  551.  
  552.         // Optimize the taxonomy mapping table.
  553.         $db->setQuery('REINDEX TABLE ' $db->quoteName('#__finder_taxonomy_map'));
  554.         $db->execute();
  555.  
  556.         return true;
  557.     }
  558.  
  559.     /**
  560.      * Method to add a set of tokens to the database.
  561.      *
  562.      * @param   mixed  $tokens   An array or single FinderIndexerToken object.
  563.      * @param   mixed  $context  The context of the tokens. See context constants. [optional]
  564.      *
  565.      * @return  integer  The number of tokens inserted into the database.
  566.      *
  567.      * @since   2.5
  568.      * @throws  Exception on database error.
  569.      */
  570.     protected function addTokensToDB($tokens$context '')
  571.     {
  572.         // Get the database object.
  573.         $db JFactory::getDbo();
  574.         $query $db->getQuery(true);
  575.  
  576.         // Force tokens to an array.
  577.         $tokens is_array($tokens$tokens array($tokens);
  578.  
  579.         // Count the number of token values.
  580.         $values 0;
  581.  
  582.         // Insert the tokens into the database.
  583.         $query->insert($db->quoteName('#__finder_tokens'))
  584.             ->columns(
  585.                 array(
  586.                     $db->quoteName('term'),
  587.                     $db->quoteName('stem'),
  588.                     $db->quoteName('common'),
  589.                     $db->quoteName('phrase'),
  590.                     $db->quoteName('weight'),
  591.                     $db->quoteName('context'),
  592.                     $db->quoteName('language')
  593.                 )
  594.             );
  595.  
  596.         // Iterate through the tokens to create SQL value sets.
  597.         foreach ($tokens as $token)
  598.         {
  599.             $query->values(
  600.                 $db->quote($token->term', '
  601.                     . $db->quote($token->stem', '
  602.                     . (int) $token->common ', '
  603.                     . (int) $token->phrase ', '
  604.                     . (float) $token->weight ', '
  605.                     . (int) $context ', '
  606.                     . $db->quote($token->language)
  607.             );
  608.             $values++;
  609.         }
  610.         $db->setQuery($query);
  611.         $db->execute();
  612.  
  613.         return $values;
  614.     }
  615.  
  616.     /**
  617.      * Method to switch the token tables from Memory tables to MyISAM tables
  618.      * when they are close to running out of memory.
  619.      *
  620.      * @param   boolean  $memory  Flag to control how they should be toggled.
  621.      *
  622.      * @return  boolean  True on success.
  623.      *
  624.      * @since   2.5
  625.      * @throws  Exception on database error.
  626.      */
  627.     protected function toggleTables($memory)
  628.     {
  629.         return true;
  630.     }
  631. }

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