Skip to content

Commit

Permalink
[OJS.de lucene - part II - ap1] Initial search UI re-design.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrandel committed Oct 16, 2012
1 parent 463a5cd commit 8513392
Show file tree
Hide file tree
Showing 20 changed files with 655 additions and 498 deletions.
88 changes: 88 additions & 0 deletions classes/search/ArticleSearch.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,80 @@ function &_getSparseArray(&$mergedResults) {
return $results;
}

/**
* Retrieve the search filters from the
* request.
* @param $request Request
* @return array All search filters (empty and active)
*/
function getSearchFilters(&$request) {
$searchFilters = array(
'query' => $request->getUserVar('query'),
'searchJournal' => $request->getUserVar('searchJournal'),
'abstract' => $request->getUserVar('abstract'),
'authors' => $request->getUserVar('authors'),
'title' => $request->getUserVar('title'),
'galleyFullText' => $request->getUserVar('galleyFullText'),
'suppFiles' => $request->getUserVar('suppFiles'),
'discipline' => $request->getUserVar('discipline'),
'subject' => $request->getUserVar('subject'),
'type' => $request->getUserVar('type'),
'coverage' => $request->getUserVar('coverage'),
'indexTerms' => $request->getUserVar('indexTerms')
);

// Is this a simplified query from the navigation
// block plugin?
$simpleQuery = $request->getUserVar('simpleQuery');
if (!empty($simpleQuery)) {
// In the case of a simplified query we get the
// filter type from a drop-down.
$searchType = $request->getUserVar('searchField');
if (array_key_exists($searchType, $searchFilters)) {
$searchFilters[$searchType] = $simpleQuery;
}
}

// Publishing dates.
$fromDate = $request->getUserDateVar('dateFrom', 1, 1);
$searchFilters['fromDate'] = (is_null($fromDate) ? null : date('Y-m-d H:i:s', $fromDate));
$toDate = $request->getUserDateVar('dateTo', 32, 12, null, 23, 59, 59);
$searchFilters['toDate'] = (is_null($toDate) ? null : date('Y-m-d H:i:s', $toDate));

// Instantiate the journal.
$journal =& $request->getJournal();
$siteSearch = !((boolean)$journal);
if ($siteSearch && !empty($searchFilters['searchJournal'])) {
$journalDao =& DAORegistry::getDAO('JournalDAO');
$journal =& $journalDao->getById($searchFilters['searchJournal']);
}
$searchFilters['searchJournal'] =& $journal;
$searchFilters['siteSearch'] = $siteSearch;

return $searchFilters;
}

/**
* Load the keywords array from a given search filter.
* @param $searchFilters array Search filters as returned from
* ArticleSearch::getSearchFilters()
* @return array Keyword array as required by ArticleSearch::retrieveResults()
*/
function getKeywordsFromSearchFilters($searchFilters) {
$indexFieldMap = ArticleSearch::getIndexFieldMap();
$indexFieldMap[ARTICLE_SEARCH_INDEX_TERMS] = 'indexTerms';
$keywords = array();
if (isset($searchFilters['query'])) {
$keywords[null] = $searchFilters['query'];
}
foreach($indexFieldMap as $bitmap => $searchField) {
if (isset($searchFilters[$searchField]) && !empty($searchFilters[$searchField])) {
$keywords[$bitmap] = $searchFilters[$searchField];
}
}
return $keywords;
}

/**
* See implementation of retrieveResults for a description of this
* function.
Expand Down Expand Up @@ -380,6 +454,20 @@ function &retrieveResults(&$journal, &$keywords, &$error, $publishedFrom = null,
$returner = new VirtualArrayIterator($results, $totalResults, $page, $itemsPerPage);
return $returner;
}

function getIndexFieldMap() {
return array(
ARTICLE_SEARCH_AUTHOR => 'authors',
ARTICLE_SEARCH_TITLE => 'title',
ARTICLE_SEARCH_ABSTRACT => 'abstract',
ARTICLE_SEARCH_GALLEY_FILE => 'galleyFullText',
ARTICLE_SEARCH_SUPPLEMENTARY_FILE => 'suppFiles',
ARTICLE_SEARCH_DISCIPLINE => 'discipline',
ARTICLE_SEARCH_SUBJECT => 'subject',
ARTICLE_SEARCH_TYPE => 'type',
ARTICLE_SEARCH_COVERAGE => 'coverage'
);
}
}

?>
85 changes: 85 additions & 0 deletions js/pages/search/SearchFormHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @defgroup js_pages_search
*/
/**
* @file js/pages/search/SearchFormHandler.js
*
* Copyright (c) 2000-2012 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class SearchFormHandler
*
* @brief Form handler that handles the search form. It checks whether
* at least one search query term has been entered before submitting
* the form. It also handles instant search (if enabled).
*/
(function($) {

/** @type {Object} */
$.pkp.pages = $.pkp.pages || {};


/** @type {Object} */
$.pkp.pages.search = $.pkp.pages.search || {};



/**
* @constructor
*
* @extends $.pkp.controllers.form.FormHandler
*
* @param {jQueryObject} $form The wrapped HTML form element.
* @param {Object} options Configuration of the form handler.
*/
$.pkp.pages.search.SearchFormHandler = function($form, options) {
// Focus the main query field and select all text.
$form.find('input[name="query"]').focus().select();

// Configure the form handler.
options.submitHandler = this.submitForm;
options.trackFormChanges = false;
options.transformButtons = false;
this.parent($form, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.pages.search.SearchFormHandler,
$.pkp.controllers.form.FormHandler);


//
// Public methods
//
/**
* Internal callback called after form validation to handle form
* submission.
*
* @param {Object} validator The validator plug-in.
* @param {HTMLElement} formElement The wrapped HTML form.
*/
$.pkp.pages.search.SearchFormHandler.prototype.submitForm =
function(validator, formElement) {
var $form, allBlank, formFields, i, max;

$form = this.getHtmlElement();

formFields = [
'query', 'authors', 'title', 'abstract', 'discipline', 'subject',
'type', 'coverage', 'indexTerms', 'suppFiles', 'galleyFullText'];
for (i = 0, max = formFields.length; i < max; i++) {
allBlank = $form.find('input[name="' + formFields[i] + '"]').val() == '';
if (!allBlank) {
break;
}
}

if (allBlank) {
alert($.pkp.locale.search_noKeywordError);
return;
}

this.submitFormWithoutValidation(validator);
};

/** @param {jQuery} $ jQuery closure. */
}(jQuery));
Loading

0 comments on commit 8513392

Please sign in to comment.