作者:till
项目:vufin
/**
* Support function to display spelling suggestions.
*
* @param string $msg HTML to display at the top of
* the spelling section.
* @param \VuFind\Search\Base\Results $results Results object
* @param \Zend\View\Renderer\PhpRenderer $view View renderer object
*
* @return string
*/
public function renderSpellingSuggestions($msg, $results, $view)
{
$spellingSuggestions = $results->getSpellingSuggestions();
if (empty($spellingSuggestions)) {
return '';
}
$html = '<div class="' . $this->getContainerClass() . '">';
$html .= $msg;
foreach ($spellingSuggestions as $term => $details) {
$html .= '<br/>' . $view->escapeHtml($term) . ' » ';
$i = 0;
foreach ($details['suggestions'] as $word => $data) {
if ($i++ > 0) {
$html .= ', ';
}
$html .= '<a href="' . $results->getUrlQuery()->replaceTerm($term, $data['new_term']) . '">' . $view->escapeHtml($word) . '</a>';
if (isset($data['expand_term']) && !empty($data['expand_term'])) {
$url = $results->getUrlQuery()->replaceTerm($term, $data['expand_term']);
$html .= $this->renderExpandLink($url, $view);
}
}
}
$html .= '</div>';
return $html;
}
作者:samul
项目:vufind-er
/**
* Internal utility function for initializing
* UrlQueryHelper for a Results-object with search ids for all tabs.
*
* @param ResultsManager $results Search results.
* @param ServiceManager $sm Service manager.
*
* @return Results Search results with initialized UrlQueryHelper
*/
public static function initUrlQueryHelper(\VuFind\Search\Base\Results $results, $sm)
{
$helper = new UrlQueryHelper($results->getParams());
$savedSearches = $sm->getServiceLocator()->get('Request')->getQuery('search');
if ($savedSearches) {
$helper->setDefaultParameter('search', $savedSearches);
}
$results->setHelper('urlQuery', $helper);
return $results;
}
作者:guenter
项目:vufin
/**
* Sort and extend facet list
*
* @param Results $results VuFind\Search\Solr\Results
* @param String $field Facet group ID, e.g. 'navSubidsbb'
* @param Array $list Contained items of the facet group
* @param String $searchRoute E.g. 'search-results'
* @param Array $routeParams RouteParams
*
* @return Array
*/
public function __invoke(Results $results, $field, array $list, $searchRoute, array $routeParams = [])
{
$facets = [];
// Avoid limit on URL
$urlHelper = $this->getView()->plugin('url');
$baseRoute = $urlHelper($searchRoute, $routeParams);
foreach ($list as $facetItem) {
$facetItem['url'] = $baseRoute . $results->getUrlQuery()->addFacet($field, $facetItem['value']);
$facets[$facetItem['displayText']] = $facetItem;
}
return array_values($facets);
}
作者:till
项目:vufin
/**
* Turns facet information into an alphabetical list.
*
* @param \VuFind\Search\Base\Results $results Search result object
* @param string $field Facet field to sort
* @param array $list Facet value list extract from
* the search result object's getFacetList method
* @param array $searchRoute Route to use to generate
* search URLs for individual facet values
*
* @return array Associative URL => description array sorted by description
*/
public function __invoke($results, $field, $list, $searchRoute)
{
$facets = [];
// avoid limit on URL
$results->getParams()->setLimit($results->getOptions()->getDefaultLimit());
$urlHelper = $this->getView()->plugin('url');
foreach ($list as $value) {
$url = $urlHelper($searchRoute) . $results->getUrlQuery()->addFacet($field, $value['value']);
$facets[$url] = $value['displayText'];
}
natcasesort($facets);
return $facets;
}
作者:samul
项目:vufind-er
/**
* Return the count of records when checkbox filter is activated.
*
* @param array $checkboxFilter Checkbox filter
* @param \VuFind\Search\Base\Results $results Search result set
*
* @return int Record count
*/
public function __invoke($checkboxFilter, $results)
{
$ret = 0;
list($field, $value) = $results->getParams()->parseFilter($checkboxFilter['filter']);
$facets = $results->getFacetList([$field => $value]);
if (isset($facets[$field])) {
foreach ($facets[$field]['list'] as $item) {
if ($item['value'] == $value || substr($value, -1) == '*' && preg_match('/^' . $value . '/', $item['value']) || $item['value'] == 'true' && $value == '1' || $item['value'] == 'false' && $value == '0') {
$ret += $item['count'];
}
}
}
return $ret;
}
作者:grharr
项目:vufin
/**
* Called after the Search Results object has performed its main search. This
* may be used to extract necessary information from the Search Results object
* or to perform completely unrelated processing.
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
public function process($results)
{
$this->results = $results;
// We can't currently deal with advanced searches:
if ($this->results->getParams()->getSearchType() == 'advanced') {
return;
}
// Get the query to manipulate:
$query = $this->results->getParams()->getDisplayQuery();
// If the query is of a type that should be skipped, go no further:
if ($this->queryShouldBeSkipped($query)) {
return;
}
// Perform all checks (based on naming convention):
$methods = get_class_methods($this);
foreach ($methods as $method) {
if (substr($method, 0, 5) == 'check') {
$currentCheck = strtolower(substr($method, 5));
if (!in_array($currentCheck, $this->skipChecks)) {
if ($result = $this->{$method}($query)) {
$this->suggestions['switchquery_' . $currentCheck] = $result;
}
}
}
}
}
作者:steenlibrar
项目:vufin
/**
* This method returns an array of strings matching the user's query for
* display in the autocomplete box.
*
* @param string $query The user query
*
* @return array The suggestions for the provided query
*/
public function getSuggestions($query)
{
if (!is_object($this->searchObject)) {
throw new \Exception('Please set configuration first.');
}
try {
$this->searchObject->getParams()->setBasicSearch($this->mungeQuery($query), $this->handler);
$this->searchObject->getParams()->setSort($this->sortField);
foreach ($this->filters as $current) {
$this->searchObject->getParams()->addFilter($current);
}
// Perform the search:
$searchResults = $this->searchObject->getResults();
// Build the recommendation list -- first we'll try with exact matches;
// if we don't get anything at all, we'll try again with a less strict
// set of rules.
$results = $this->getSuggestionsFromSearch($searchResults, $query, true);
if (empty($results)) {
$results = $this->getSuggestionsFromSearch($searchResults, $query, false);
}
} catch (\Exception $e) {
// Ignore errors -- just return empty results if we must.
}
return isset($results) ? array_unique($results) : [];
}
作者:bbeckma
项目:NDL-VuFind
/**
* Process the jumpto parameter -- either redirect to a specific record and
* return view model, or ignore the parameter and return false.
*
* @param \VuFind\Search\Base\Results $results Search results object.
*
* @return mixed
*/
protected function processJumpTo($results)
{
// Missing/invalid parameter? Ignore it:
$jumpto = $this->params()->fromQuery('jumpto');
if (empty($jumpto) || !is_numeric($jumpto)) {
return false;
}
// Parameter out of range? Ignore it:
$recordList = $results->getResults();
if (!isset($recordList[$jumpto - 1])) {
return false;
}
// If we got this far, we have a valid parameter so we should redirect
// and report success:
$url = $recordList[$jumpto - 1]->getUrl();
return $url ? $this->redirect()->toUrl($url) : false;
}
作者:bbeckma
项目:NDL-VuFind
/**
* Return the count of records when checkbox filter is activated.
*
* @param array $checkboxFilter Checkbox filter
* @param \VuFind\Search\Base\Results $results Search result set
*
* @return int Record count
*/
public function __invoke($checkboxFilter, $results)
{
$ret = 0;
list($field, $value) = $results->getParams()->parseFilter($checkboxFilter['filter']);
$facets = $results->getFacetList([$field => $value]);
if (isset($facets[$field])) {
foreach ($facets[$field]['list'] as $item) {
if ($item['value'] == $value || substr($value, -1) == '*' && preg_match('/^' . $value . '/', $item['value']) || $item['value'] == 'true' && $value == '1' || $item['value'] == 'false' && $value == '0') {
$ret += $item['count'];
}
}
} elseif ($field == 'online_boolean' && $value == '1') {
// Special case for online_boolean, which is translated to online_str_mv
// when deduplication is enabled.
// If we don't have a facet value for online_boolean it means we need to
// do an additional lookup for online_str_mv.
$results = clone $results;
$params = $results->getParams();
$options = $results->getOptions();
$searchConfig = $this->getView()->getHelperPluginManager()->getServiceLocator()->get('VuFind\\Config')->get($options->getSearchIni());
if (!empty($searchConfig->Records->sources)) {
$sources = explode(',', $searchConfig->Records->sources);
$sources = array_map(function ($s) {
return "\"{$s}\"";
}, $sources);
$params->addFilter('(online_str_mv:' . implode(' OR online_str_mv:', $sources) . ')');
} else {
$params->addFilter('online_str_mv:*');
}
$params->setLimit(0);
$params->resetFacetConfig();
$options->disableHighlighting();
$options->spellcheckEnabled(false);
$results->performAndProcessSearch();
return $results->getResultTotal();
}
return $ret;
}
作者:till
项目:vufin
/**
* Represent the current search results as a feed.
*
* @param \VuFind\Search\Base\Results $results Search results to convert to
* feed
* @param string $currentPath Base path to display in feed
* (leave null to load dynamically using currentpath view helper)
*
* @return Feed
*/
public function __invoke($results, $currentPath = null)
{
$this->registerExtension();
// Determine base URL if not already provided:
if (is_null($currentPath)) {
$currentPath = $this->getView()->plugin('currentpath')->__invoke();
}
$serverUrl = $this->getView()->plugin('serverurl');
$baseUrl = $serverUrl($currentPath);
// Create the parent feed
$feed = new Feed();
$feed->setTitle($this->translate('Results for') . ' ' . $results->getParams()->getDisplayQuery());
$feed->setLink($baseUrl . $results->getUrlQuery()->setViewParam(null, false));
$feed->setFeedLink($baseUrl . $results->getUrlQuery()->getParams(false), $results->getParams()->getView());
$feed->setDescription($this->translate('Showing') . ' ' . $results->getStartRecord() . '-' . $results->getEndRecord() . ' ' . $this->translate('of') . ' ' . $results->getResultTotal());
$params = $results->getParams();
// add atom links for easier paging
$feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage(1, false), 'first', $params->getView());
if ($params->getPage() > 1) {
$feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() - 1, false), 'previous', $params->getView());
}
$lastPage = ceil($results->getResultTotal() / $params->getLimit());
if ($params->getPage() < $lastPage) {
$feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() + 1, false), 'next', $params->getView());
}
$feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($lastPage, false), 'last', $params->getView());
// add opensearch fields
$feed->setOpensearchTotalResults($results->getResultTotal());
$feed->setOpensearchItemsPerPage($params->getLimit());
$feed->setOpensearchStartIndex($results->getStartRecord() - 1);
$feed->setOpensearchSearchTerms($params->getQuery()->getString());
$records = $results->getResults();
foreach ($records as $current) {
$this->addEntry($feed, $current);
}
return $feed;
}
作者:bbeckma
项目:NDL-VuFind
/**
* Internal utility function for initializing
* UrlQueryHelper for a Results-object with search ids for all tabs.
*
* @param ResultsManager $results Search results.
* @param ServiceManager $locator Service locator.
*
* @return Results Search results with initialized UrlQueryHelper
*/
public static function initUrlQueryHelper(\VuFind\Search\Base\Results $results, $locator)
{
if (Console::isConsole()) {
return $results;
}
$helper = new UrlQueryHelper($results->getParams());
$savedSearches = $locator->get('Request')->getQuery('search');
if ($savedSearches) {
$helper->setDefaultParameter('search', $savedSearches);
}
$results->setHelper('urlQuery', $helper);
return $results;
}
作者:steenlibrar
项目:vufin
/**
* Add a search into the search table (history)
*
* @param \VuFind\Search\Results\PluginManager $manager Search manager
* @param \VuFind\Search\Base\Results $newSearch Search to save
* @param string $sessionId Current session ID
* @param array $searchHistory Existing saved
* searches (for deduplication purposes)
*
* @return void
*/
public function saveSearch(\VuFind\Search\Results\PluginManager $manager, $newSearch, $sessionId, $searchHistory = [])
{
// Duplicate elimination
$newUrl = $newSearch->getUrlQuery()->getParams();
foreach ($searchHistory as $oldSearch) {
// Deminify the old search (note that if we have a resource, we need
// to grab the contents -- this is necessary for PostgreSQL compatibility
// although MySQL returns a plain string).
$minSO = $oldSearch->getSearchObject();
$dupSearch = $minSO->deminify($manager);
// See if the classes and urls match
$oldUrl = $dupSearch->getUrlQuery()->getParams();
if (get_class($dupSearch) == get_class($newSearch) && $oldUrl == $newUrl) {
// Is the older search saved?
if ($oldSearch->saved) {
// Return existing saved row instead of creating a new one:
$newSearch->updateSaveStatus($oldSearch);
return;
} else {
// Delete the old search since we'll be creating a new, more
// current version below:
$oldSearch->delete();
}
}
}
// If we got this far, we didn't find a saved duplicate, so we should
// save the new search:
$data = ['session_id' => $sessionId, 'created' => date('Y-m-d'), 'search_object' => serialize(new minSO($newSearch))];
$this->insert($data);
$row = $this->getRowById($this->getLastInsertValue());
// Chicken and egg... We didn't know the id before insert
$newSearch->updateSaveStatus($row);
$row->search_object = serialize(new minSO($newSearch));
$row->save();
}
作者:no-repl
项目:cbpl-vufin
/**
* process
*
* Called after the Search Results object has performed its main search. This
* may be used to extract necessary information from the Search Results object
* or to perform completely unrelated processing.
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
public function process($results)
{
// If we received a Summon search object, we'll use that. If not, we need
// to create a new Summon search object using the specified request
// parameter for search terms.
if ($results->getParams()->getSearchClassId() != 'Summon') {
$sm = $this->getSearchManager();
$params = $sm->setSearchClassId('Summon')->getParams();
$params->setBasicSearch($this->lookfor);
$results = $sm->setSearchClassId('Summon')->getResults($params);
$results->performAndProcessSearch();
}
$this->databases = $results->getDatabaseRecommendations();
}
作者:paulusov
项目:VuFind-2.
/**
* process
*
* Called after the Search Results object has performed its main search. This
* may be used to extract necessary information from the Search Results object
* or to perform completely unrelated processing.
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
public function process($results)
{
$filters = $results->getParams()->getFilters();
foreach ($filters as $key => $value) {
if ($key == $this->geoField) {
$match = array();
if (preg_match('/Intersects\\(([0-9 \\-\\.]+)\\)/', $value[0], $match)) {
$this->selectedCoordinates = explode(' ', $match[1]);
} else {
if (preg_match($this->polygonMatch, $value[0], $match)) {
$this->selectedCoordinates = [$match[1], $match[2], $match[3], $match[4]];
}
}
$this->searchParams = $results->getUrlQuery()->removeFacet($this->geoField, $value[0], false);
}
}
if ($this->searchParams == null) {
$this->searchParams = $results->getUrlQuery()->getParams(false);
}
}
作者:guenter
项目:vufin
/**
* Saves the record view to wherever the config [Statistics] says so
*
* @param \VuFind\Search\Base\Results $data Results from Search controller
* @param Zend_Controller_Request_Http $request Request data
*
* @return void
*/
public function log($data, $request)
{
$this->save(['recordId' => $data->getUniqueId(), 'recordSource' => $data->getResourceSource()], $request);
}
作者:steenlibrar
项目:vufin
/**
* Saves the search to wherever the config [Statistics] says so
*
* @param \VuFind\Search\Base\Results $data Results from Search controller
* @param Zend_Controller_Request_Http $request Request data from the controller
*
* @return void
*/
public function log($data, $request)
{
$stat = ['phrase' => $data->getParams()->getDisplayQuery(), 'searchSource' => $data->getParams()->getSearchClassId(), 'type' => $data->getParams()->getSearchHandler(), 'resultCount' => $data->getResultTotal(), 'noresults' => $data->getResultTotal() == 0];
$this->save($stat, $request);
}
作者:grharr
项目:vufin
/**
* Called after the Search Results object has performed its main search. This
* may be used to extract necessary information from the Search Results object
* or to perform completely unrelated processing.
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
public function process($results)
{
// If we received a Summon search object, we'll use that. If not, we need
// to create a new Summon search object using the specified request
// parameter for search terms.
if ($results->getParams()->getSearchClassId() != 'Summon') {
$results = $this->resultsManager->get('Summon');
$this->configureSummonResults($results);
$results->performAndProcessSearch();
}
$this->results = $results;
}
作者:paulusov
项目:VuFind-2.
/**
* process
*
* Called after the Search Results object has performed its main search. This
* may be used to extract necessary information from the Search Results object
* or to perform completely unrelated processing.
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
public function process($results)
{
if ($this->selectedDateRange == null) {
return;
}
$this->searchParams = $results->getUrlQuery()->removeFacet($this->selectedDateRange, false);
$curr_date = date('Ym', strtotime('now'));
$s1 = date('Ym', strtotime('last year'));
$e1 = date('Ym', strtotime('last year december'));
$s2 = date('Ym', strtotime('this year january'));
$e2 = $curr_date;
$ranges = array_merge(range($e2, $s2), range($e1, $s1));
foreach ($ranges as $date) {
$range = $this->createRange($date, $e2);
$label = $this->createLabel($date);
$this->dateRanges[$label] = array('filter' => $this->createFilter($range), 'selected' => $this->selectedDateRange == $range);
}
}
作者:shemmen
项目:vufin
/**
* Process the jumpto parameter -- either redirect to a specific record and
* return view model, or ignore the parameter and return false.
*
* @param \VuFind\Search\Base\Results $results Search results object.
*
* @return bool|\Zend\View\Model\ViewModel
*/
protected function processJumpTo($results)
{
// Missing/invalid parameter? Ignore it:
$jumpto = $this->params()->fromQuery('jumpto');
if (empty($jumpto) || !is_numeric($jumpto)) {
return false;
}
// Parameter out of range? Ignore it:
$recordList = $results->getResults();
if (!isset($recordList[$jumpto - 1])) {
return false;
}
// If we got this far, we have a valid parameter so we should redirect
// and report success:
$details = $this->getRecordRouter()->getTabRouteDetails($recordList[$jumpto - 1]);
return $this->redirect()->toRoute($details['route'], $details['params']);
}
作者:bbeckma
项目:NDL-VuFind
/**
* Build a hidden filter query fragment from the given filters
*
* @param Results $results Search results
* @param array $filters Filters
*
* @return string Query parameters
*/
protected function buildUrlHiddenFilters(Results $results, $filters)
{
// Set up results object for URL building:
$params = $results->getParams();
foreach ($filters as $filter) {
$params->addHiddenFilter($filter);
}
$urlParams = $results->getUrlQuery()->getParams(false);
return $urlParams !== '?' ? $urlParams : '';
}