Пример #1
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;
 }