예제 #1
0
파일: browse.php 프로젝트: bellodox/jsolr
 public function getItems()
 {
     $params = JComponentHelper::getParams($this->get('option'), true);
     $list = array();
     $facetParams = array();
     $filters = array();
     $array = array();
     $facetFields = $this->getState('facet.fields');
     if ($this->getState('facet.range')) {
         $facetFields[] = $this->getState('facet.range');
     }
     if (!$this->getState('params')->get('override_schema', 0)) {
         $access = implode(' OR ', JFactory::getUser()->getAuthorisedViewLevels());
         if ($access) {
             $access = 'access:' . '(' . $access . ') OR null';
             $filters[] = $access;
         }
         $filters[] = $this->getLanguageFilter();
     }
     // get context.
     if ($this->getState('query.o', null)) {
         foreach ($dispatcher->trigger('onJSolrSearchRegisterPlugin') as $result) {
             if (JArrayHelper::getValue($result, 'name') == $this->getState('query.o', null)) {
                 $filters = array_merge($filters, array('context:' . JArrayHelper::getValue($result, 'context')));
             }
         }
     }
     if ($prefix = $this->getState('facet.prefix')) {
         $facetParams['facet.prefix'] = $prefix;
     }
     JPluginHelper::importPlugin("jsolrsearch");
     $dispatcher = JDispatcher::getInstance();
     try {
         $query = \JSolr\Search\Factory::getQuery("*:*")->useQueryParser('edismax')->mergeParams($facetParams)->filters($filters)->facet(0, 'index', -1)->rows(0);
         if ($this->getState('facet.fields')) {
             $query->facetFields($this->getState('facet.fields'));
         }
         if ($this->getState('facet.range')) {
             $query->facetRange($this->getState('facet.range'), $this->getState('facet.start'), $this->getState('facet.end'), $this->getState('facet.gap'));
         }
         $results = $query->search();
         foreach ($facetFields as $field) {
             $array[$field] = array();
             if (isset($results->getFacets()->{$field})) {
                 foreach ($results->getFacets()->{$field} as $key => $value) {
                     $array[$field][$key] = $value;
                 }
             }
             if (isset($results->getFacetRanges()->{$field})) {
                 $counts = (array) $results->getFacetRanges()->{$field}->counts;
                 foreach ($counts as $key => $value) {
                     $array[$field][$key] = $value;
                 }
             }
         }
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'jsolrsearch');
     }
     return $array;
 }
예제 #2
0
파일: Sort.php 프로젝트: bellodox/jsolr
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     foreach ($this->element->children() as $option) {
         // Only add <option /> elements.
         if ($option->getName() != 'option') {
             continue;
         }
         $value = JArrayHelper::getValue($option, 'value', null, 'string');
         $selected = $value == $this->value;
         $uri = clone \JSolr\Search\Factory::getSearchRoute();
         if (!empty($value)) {
             $uri->setVar($this->name, $value);
         } else {
             $uri->delVar($this->name);
         }
         $link = '<a role="menuitem" tabindex="-1" href="' . htmlentities((string) $uri, ENT_QUOTES, 'UTF-8') . '">' . JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)) . '</a>';
         // Create a new option object based on the <option /> element.
         $tmp = '<li role="presentation" class="' . ($selected ? 'active' : '') . '" data-value="' . $value . '">' . $link . '</li>';
         // Add the option object to the result set.
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
예제 #3
0
파일: suggest.php 프로젝트: bellodox/jsolr
 /**
  * @return array
  */
 function getItems()
 {
     $q = JFactory::getApplication()->input->getString('q');
     $fields = JFactory::getApplication()->input->getString('fields');
     $suggest = JFactory::getApplication()->input->getString('suggest');
     $query = \JSolr\Search\Factory::getQuery('*:*')->useQueryParser("edismax")->retrieveFields("*,score")->limit(10)->highlight(200, "<strong>", "</strong>", 1);
     $fields = explode(',', $fields);
     $items = array();
     if (empty($q)) {
         return $items;
     }
     foreach ($fields as &$field) {
         $field = explode('^', $field);
         $field = $field[0];
         $field = $field . ':' . $q . '*';
     }
     $filters = implode(' OR ', $fields);
     $query->filters($filters);
     try {
         $results = $query->search();
         print_r($results);
         $response = json_decode($results->getSuggestions());
         foreach ($response->docs as $doc) {
             if (is_array($doc->{$suggest})) {
                 $v = (array) $doc->{$suggest};
                 $items[] = $v[0];
             } else {
                 $items[] = $doc->{$suggest};
             }
         }
     } catch (Exception $e) {
         print_r($e->getMessage());
     }
     return $items;
 }
예제 #4
0
 public function test()
 {
     $solr = \JSolr\Search\Factory::getService();
     $response = $solr->ping();
     if ($response === false) {
         $this->setError(JText::_("COM_JSOLRSEARCH_PING_FAILED"));
         return false;
     }
     return true;
 }
예제 #5
0
 private function _loadDefaultRanges()
 {
     if (!$this->ranges) {
         $params = array();
         $params["stats"] = "true";
         $params["stats.field"] = $this->filter;
         $query = \JSolr\Search\Factory::getQuery("*:*")->mergeParams($params)->rows(0);
         $results = $query->search();
         $stats = $results->getStats();
         if (isset($stats->{$this->filter})) {
             $this->ranges = JArrayHelper::fromObject($stats->{$this->filter});
         }
     }
 }
예제 #6
0
    /**
     * Method to get the field options.
     *
     * @return  array  The field option objects.
     *
     * @since   11.1
     */
    protected function getOptions()
    {
        // Initialize variables.
        $options = array();
        foreach ($this->element->children() as $option) {
            // Only add <option /> elements.
            if ($option->getName() != 'option') {
                continue;
            }
            $value = JArrayHelper::getValue($option, 'value', null, 'string');
            $selected = $value == $this->value;
            $uri = clone \JSolr\Search\Factory::getSearchRoute();
            if (!empty($value)) {
                $uri->setVar($this->name, $value);
            } else {
                $uri->delVar($this->name);
            }
            $link = '<a role="menuitem" tabindex="-1" href="' . (string) $uri . '">' . JText::_(trim((string) $option)) . '</a>';
            $tmp = '<li role="presentation"' . ($selected ? ' class="active" ' : '') . ' data-value="' . $value . '">' . $link . '</li>';
            // Add the option object to the result set.
            $options[] = $tmp;
        }
        if ($this->show_custom) {
            $dataValue = 'custom';
            $cssClass = '';
            if (($min = $this->_getMinInput()) && ($max = $this->_getMaxInput())) {
                $selected = true;
                $dataValue = "min:{$min},max:{$max}";
                $cssClass = 'class="active"';
            }
            $link = <<<HTML
<a
    role="menuitem"
    tabindex="-1"
    href="#custom-dates"
    id="calendar-picker">Custom...</a>
HTML;
            $tmp = <<<HTML
<li
    role="presentation"
    {$cssClass}
    data-value="{$dataValue}">{$link}</li>
HTML;
            $options[] = $tmp;
        }
        reset($options);
        return $options;
    }
예제 #7
0
파일: helper.php 프로젝트: bellodox/jsolr
 public function getItems($params)
 {
     $results = array();
     if (class_exists('\\JSolr\\Search\\Factory')) {
         try {
             $client = \JSolr\Search\Factory::getService();
             $query = \JSolr\Search\Factory::getQuery('*:*')->limit($params->get('count', 5))->sort($params->get('ordering', 'modified') . ' desc')->useQueryParser("edismax")->retrieveFields("*,score");
             if ($limit = $params->get('o')) {
                 $query->filters('extension:' . $limit);
             }
             if ($fq = $params->get('fq', null)) {
                 $filters = array();
                 $parts = explode(',', $fq);
                 foreach ($parts as $part) {
                     $filters[] = trim($part);
                 }
                 $query->mergeFilters($filters);
             }
             $results = $query->search();
         } catch (Exception $e) {
         }
     }
     return $results;
 }
예제 #8
0
파일: Form.php 프로젝트: bellodox/jsolr
 /**
  * Get the list of enabled plugins for search results.
  */
 public function getPlugins()
 {
     JPluginHelper::importPlugin("jsolrsearch");
     $class = "JEventDispatcher";
     if (version_compare(JVERSION, "3.0", "l")) {
         $class = "JDispatcher";
     }
     $dispatcher = $class::getInstance();
     $array = $dispatcher->trigger('onJSolrSearchRegisterPlugin');
     $array = array_merge(array(array('plugin' => '', 'label' => JText::_('Everything'))), $array);
     for ($i = 0; $i < count($array); $i++) {
         $uri = clone \JSolr\Search\Factory::getQueryRoute();
         if (JArrayHelper::getValue($array[$i], 'name')) {
             $uri->setVar('o', $array[$i]['name']);
         } else {
             $uri->delVar('o');
         }
         $array[$i]['uri'] = htmlentities((string) $uri, ENT_QUOTES, 'UTF-8');
     }
     return $array;
 }
예제 #9
0
파일: dspace.php 프로젝트: bellodox/jsolr
 /**
  * (non-PHPdoc)
  * @see \JSolr\Index\Crawler::clean()
  */
 protected function clean()
 {
     $items = $this->getItems();
     $service = \JSolr\Index\Factory::getService();
     $query = \JSolr\Search\Factory::getQuery('*:*')->useQueryParser("edismax")->filters(array($this->get('itemContext')))->retrieveFields('id')->rows(0);
     $results = $query->search();
     if ($results->get('numFound')) {
         $query->rows($results->get('numFound'));
     }
     $results = $query->search();
     if ($results->get('numFound')) {
         $delete = array();
         $prefix = $this->get('itemContext') . '.';
         foreach ($results as $result) {
             $needle = new stdClass();
             $needle->{'search.resourceid'} = $result->id;
             if (array_search($needle, $items) === false) {
                 $delete[] = $prefix . $result->id;
             }
         }
         if (count($delete)) {
             foreach ($delete as $key) {
                 $this->out('cleaning item ' . $key . ' and its bitstreams');
                 $query = 'type:' . $this->get('assetContext') . ' AND parent_id:' . str_replace($prefix, '', $key);
                 $service->deleteByQuery($query);
             }
             $service->deleteByMultipleIds($delete);
             $response = $service->commit();
         }
     }
 }
예제 #10
0
			<?php 
    echo $this->form->getInput($field->name);
    ?>
		<?php 
}
?>
	</div>

	<?php 
echo JHTML::_('form.token');
?>
</form>

<div id="custom-dates">
	<form id="custom-dates-form" action="<?php 
echo JRoute::_(\JSolr\Search\Factory::getSearchRoute());
?>
" method="get">
		<?php 
echo JHtml::_('calendar', '', "qdr_min", "qdr_min", "%Y-%m-%d");
?>
		<?php 
echo JHtml::_('calendar', '', "qdr_max", "qdr_max", "%Y-%m-%d");
?>

		<button id="custom-dates-submit"><?php 
echo JText::_('JSUBMIT');
?>
</button>
		<a id="custom-dates-cancel" href="#"><?php 
echo JText::_('JCANCEL');
예제 #11
0
파일: search.php 프로젝트: bellodox/jsolr
 public function getSuggestionQueryURIs()
 {
     $uris = array();
     $i = 0;
     $uri = \JSolr\Search\Factory::getQueryRouteWithPlugin();
     $uri->setVar('q', $this->getItems()->getSuggestions());
     $uris[$i]['uri'] = $uri;
     $uris[$i]['title'] = $this->getItems()->getSuggestions();
     return $uris;
 }
예제 #12
0
파일: advanced.php 프로젝트: bellodox/jsolr
 /**
  * (non-PHPdoc)
  * @see JModelForm::loadFormData()
  */
 protected function loadFormData()
 {
     $query = \JSolr\Search\Factory::getSearchRoute()->getQuery(true);
     if (count($query)) {
         $query = array_merge($query, $this->parseQuery());
         $data = $query;
     }
     $context = $this->get('option') . '.' . $this->getName();
     if (version_compare(JVERSION, "3.0", "ge")) {
         $this->preprocessData($this->get('context'), $data);
     }
     return $data;
 }
예제 #13
0
파일: default.php 프로젝트: bellodox/jsolr
	<ul>
	<?php 
foreach ($this->items as $keyi => $valuei) {
    ?>
		<?php 
    $field = JArrayHelper::getValue($operators, $keyi);
    ?>
		<?php 
    foreach ($valuei as $keyj => $valuej) {
        ?>
			<?php 
        $vars = array(JFactory::getApplication()->input->get('name') => Helper::getOriginalFacet($keyj), 'o' => JFactory::getApplication()->input->get('o'));
        if ($this->params->get('show_count')) {
            $facet = JText::sprintf('%s [%s]', Helper::getOriginalFacet($keyj), $valuej);
        } else {
            $facet = JText::sprintf('%s', Helper::getOriginalFacet($keyj));
        }
        ?>

			<li><?php 
        echo JHTML::_('link', JRoute::_(\JSolr\Search\Factory::getSearchRoute($vars)), $facet);
        ?>
</li>
		<?php 
    }
    ?>
	<?php 
}
?>
	</ul>
</div>
예제 #14
0
 public function search()
 {
     $this->setRedirect(JRoute::_(\JSolr\Search\Factory::getSearchRoute(), false));
 }
예제 #15
0
 /**
  * Gets the remove url for the applied hidden filter.
  *
  * @return string The filter uri for the current facet.
  */
 protected function getFilterURI()
 {
     $url = clone \JSolr\Search\Factory::getSearchRoute();
     $url->delVar($this->name);
     return (string) $url;
 }
예제 #16
0
파일: Facets.php 프로젝트: bellodox/jsolr
 /**
  * Gets the filter uri for the current facet.
  *
  * @param string $facet The facet value to build into the filter uri.
  * @return string The filter uri for the current facet.
  */
 protected function getFilterURI($facet)
 {
     $url = clone \JSolr\Search\Factory::getSearchRoute();
     foreach ($url->getQuery(true) as $key => $value) {
         $url->setVar($key, urlencode($value));
     }
     $filters = array();
     if ($cleaned = JString::trim($this->value)) {
         $filters = explode(self::FACET_DELIMITER, $cleaned);
     }
     if ($this->isSelected($facet)) {
         if (count($filters) > 1) {
             $found = false;
             for ($i = 0; ($filter = current($filters)) && !$found; $i++) {
                 if ($filter == $facet) {
                     unset($filters[$i]);
                     $found = true;
                 } else {
                     next($filters);
                 }
             }
             $url->setVar($this->name, urlencode(implode(self::FACET_DELIMITER, $filters)));
         } else {
             $url->delVar($this->name);
         }
     } else {
         $filters[] = $facet;
         $url->setVar($this->name, urlencode(implode(self::FACET_DELIMITER, $filters)));
     }
     return (string) $url;
 }