示例#1
0
 /**
  * Information about index
  */
 function getIndexInfo()
 {
     require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_jucene' . DS . 'helpers' . DS . 'jucene.php';
     $index = JuceneHelper::getIndex();
     $info['infodocs'] = $index->count();
     $dir_info = $this->getDirectorySize(JuceneHelper::getIndexPath());
     $info['folderSize'] = $dir_info['size'];
     return $info;
 }
示例#2
0
 /**
  * 
  * @param $article
  * @param $isNew
  */
 function onIndexContent($article, $isNew = false)
 {
     //FIXME move the content type tests and following transformations to the helper
     global $mainframe;
     $pk = $article->id;
     if (!$isNew) {
         JuceneHelper::removeFromIndex('pk:' . $pk);
     }
     $index = JuceneHelper::getIndex();
     $xml_field = substr($article->fulltext, 0, 5) != '<?xml' ? $article->introtext : $article->fulltext;
     if (substr($xml_field, 0, 5) == '<?xml') {
         $dom = new DOMDocument();
         $pmml = true;
         $xslt = new DOMDocument();
         $error = false;
         //load xslt stylesheet
         if (!@$xslt->load(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_jucene' . DS . 'xslt/jucene.xsl')) {
             $error = true;
             $this->raiseMessage("XSLTLOADERROR", 'error');
         }
         $proc = new XSLTProcessor();
         if (!$proc->importStylesheet($xslt)) {
             $error = true;
             $this->raiseMessage("XSLTIMPORTERROR", 'error');
         }
         unset($artcile->fulltext);
         unset($record->introtext);
         if ($dom->loadXML($xml_field) && !$error && $pmml) {
             //simplify the document - prepare it for the indexation process
             $xslOutput = $proc->transformToXml($dom);
             //create new DOM document to preserve output and transform the XML to the indexable one
             $transXml = new DOMDocument();
             $transXml->preserveWhitespace = false;
             @$transXml->loadXML($xslOutput);
             //unset unneccessary variables
             unset($xslOutput);
             unset($dom);
             unset($xslt);
             //index every assoc rule as document with same credentials
             if (!$error) {
                 $rules = $transXml->getElementsByTagName("AssociationRule");
                 $rulesCount = $rules->length;
                 if ($rulesCount == 0) {
                     $error = true;
                     $this->raiseMessage('XMLDOCUMENTNORULES', 'error');
                 }
                 $rule_doc_position = 0;
                 foreach ($rules as $rule) {
                     $additional['rating'] = 0;
                     $additional['position'] = $rule_doc_position;
                     JPluginHelper::importPlugin('content');
                     $dispatcher =& JDispatcher::getInstance();
                     $results = $dispatcher->trigger('onIndexPmml', array($rule, $additional));
                     $rule_doc_position++;
                 }
             }
         }
     } else {
         $zendDoc = Zend_Search_Lucene_Document_Html::loadHTML($article->fulltext, false, UTF - 8);
         $index->addDocument($zendDoc);
     }
 }
示例#3
0
 /**
  * Function to update rating of the association rule by the Sewebar domain experts. It should be
  * in the format +/- 1.
  * @param $docId reference of the document id - e.g. db primary key id, pk field of the lucene record
  * @param $rating value of the rating +/- 1
  * @param $rulePosition position in the document
  */
 function updateRating($docId, $userRating, $rulePosition)
 {
     $index = JuceneHelper::getIndex();
     $results = $index->find("pk:'.{$docId}.' AND position:" . $rulePosition);
     if (count($results) > 0) {
         foreach ($results as $result) {
             $del = $index->delete($result->id);
         }
         $ruleRating = $result->rating;
         if ($userRating == -1 || $userRating == 1) {
             $newRating = $ruleRating + $userRating;
             $zendDoc = Zend_Search_Lucene_Document_Pmml::addPmml($result, array(), false);
             $index->addDocument($zendDoc);
         }
     }
 }
示例#4
0
 /**
  * 
  */
 function getFields()
 {
     if (empty($this->_fields)) {
         $index = JuceneHelper::getIndex();
         $results = $index->getFieldNames();
         $this->_fields = $results;
     }
     return $this->_fields;
 }
示例#5
0
/**
 * This method is used to generate search results field that are passed to the view
 * for displaying to the end-user
 * @param $query
 * @param $ordering
 */
function plgSearchJucene($query, $ordering = '')
{
    //import helpers
    require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_jucene' . DS . 'helpers' . DS . 'jucene.php';
    require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
    //set up some variables
    global $mainframe;
    $user =& JFactory::getUser();
    $time = time();
    try {
        //retrieve the Lucene Index if exists
        $index =& JuceneHelper::getIndex();
    } catch (Exception $e) {
        JFactory::getApplication()->enqueueMessage(JText::_($e->getMessage()), 'error');
    }
    //It is time to define the parameters! First get the right plugin; 'search' (the group), 'nameofplugin'.
    $plugin =& JPluginHelper::getPlugin('search', 'jucene');
    //load the parameters of the plugin
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->def('search_limit', 0);
    //TODO log search query
    //Set query
    try {
        $query = JuceneHelper::prepareNumber($query);
    } catch (Exception $e) {
    }
    Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
    try {
        Zend_Search_Lucene_Search_QueryParser::parse($query);
    } catch (Exception $e) {
        JFactory::getApplication()->enqueueMessage(JText::_($e->getMessage()), 'error');
    }
    $query = str_replace('-', ':', $query);
    if (JDEBUG) {
        JFactory::getApplication()->enqueueMessage(JText::_($query, 'error'));
    }
    //query time
    $_SESSION['jucene_timer'] = time();
    try {
        $results = $index->find($query, 'score', SORT_NUMERIC, SORT_DESC, 'rating', SORT_NUMERIC, SORT_DESC);
    } catch (Exception $e) {
        JFactory::getApplication()->enqueueMessage(JText::_($e->getMessage()), 'error');
    }
    //TODO find better solution to create links, perhaps to create router like it the com_content
    // Create a user access object for the current user
    $access = new stdClass();
    $access->canEdit = $user->authorize('com_content', 'edit', 'content', 'all');
    $access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');
    $access->canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
    // Check to see if the user has access to view the full article
    $aid = $user->get('aid');
    //pk is the value of the primary key of the record, because we cannot call id - lucene would return id WITHIN index.. not database primary key
    foreach ($results as $key => $val) {
        if ($val->access <= $aid) {
            $results[$key]->href = JRoute::_(ContentHelperRoute::getArticleRoute($val->alias, $val->catid, $val->sectionid));
            //ContentHelperRoute::getArticleRoute ( $val->pk );
        } else {
            $params =& JComponentHelper::getParams('com_jucene');
            $leave_out = $params->get('leave_out', 1);
            // Create login URL or leave out private content
            if ($leave_out == 1) {
                unset($results[$key]);
            } else {
                $uri = JFactory::getURI();
                $return = $uri->toString();
                $url = 'index.php?option=com_user&view=login';
                $url .= '&return=' . base64_encode($return);
                $results[$key]->href = $url;
            }
        }
        $results[$key]->count = '';
        $results[$key]->time = $time;
    }
    //Return the search results in an array
    return $results;
}
示例#6
0
 /**
  * 
  * @param $conditions
  * array of conditions in form of fied => value
  */
 function searchKbi(DOMDocument $ar_query, $specific_index = NULL)
 {
     if (!JuceneHelper::stringContains($ar_query, "<?xml")) {
         return "";
     }
     $xslt = new DOMDocument();
     if (!@$xslt->load(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_jucene' . DS . 'xslt/ARQuery.xsl')) {
         $error = true;
         $this->raiseMessage("XSLTLOADERROR", 'error');
     }
     $xslt_proc = new XSLTProcessor();
     if (!$xslt_proc->importStylesheet($xslt)) {
         $error = true;
         $this->raiseMessage("XSLTIMPORTERROR", 'error');
     }
     $ar_query_dom = new DOMDocument();
     if ($ar_query_dom->loadXML($ar_query)) {
         $query = $xslt_proc->transformToXml($ar_query);
     }
     $index = is_null($specific_index) ? JuceneHelper::getIndex() : JuceneHelper::getIndex($specific_index);
     try {
         $results = $index->find($query);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     if (count($results) > 0) {
         //TODO make the results XML
         $results_xml = new DOMDocument();
         $results_xml->formatOutput = true;
         $search_result = $results_xml->appendChild('SearchResult');
         $hits = $search_result->appendChild('Hits');
         foreach ($results as $field_name => $value) {
             $hit = $hits->appendChild('Hit');
             $hitValue = $results_xml->createElement($field_name, $value);
             $hit->appendChild($hitValue);
         }
         $xml = $results_xml->saveXML();
     }
     return $xml;
 }
示例#7
0
 /**
  * 
  * @param $doc_id
  */
 function removeFromIndexById($doc_id)
 {
     if (!is_numeric()) {
         return false;
     }
     $message = "";
     $index = JuceneHelper::getIndex();
     $hits = $index->find("pk:" . $doc_id);
     if (count($hits > 0)) {
         foreach ($hits as $hit) {
             try {
                 $index->delete($hit->id);
             } catch (Exception $e) {
                 JFactory::getApplication()->enqueueMessage($e->getMessage());
             }
             $message .= "Deleted " . $hit->id;
             //$this->raiseMessage("removed: ".$hit->id,'error');
         }
     }
     JFactory::getApplication()->enqueueMessage($message);
 }