20 define(
'SUBMISSION_SEARCH_AUTHOR', 0x00000001);
21 define(
'SUBMISSION_SEARCH_TITLE', 0x00000002);
22 define(
'SUBMISSION_SEARCH_ABSTRACT', 0x00000004);
23 define(
'SUBMISSION_SEARCH_DISCIPLINE', 0x00000008);
24 define(
'SUBMISSION_SEARCH_SUBJECT', 0x00000010);
25 define(
'SUBMISSION_SEARCH_TYPE', 0x00000020);
26 define(
'SUBMISSION_SEARCH_COVERAGE', 0x00000040);
27 define(
'SUBMISSION_SEARCH_GALLEY_FILE', 0x00000080);
28 define(
'SUBMISSION_SEARCH_SUPPLEMENTARY_FILE', 0x00000100);
29 define(
'SUBMISSION_SEARCH_INDEX_TERMS', 0x00000078);
31 define(
'SUBMISSION_SEARCH_DEFAULT_RESULT_LIMIT', 20);
33 import(
'lib.pkp.classes.search.SubmissionSearchIndex');
59 $return = array(
'+' => array(),
'' => array(),
'-' => array());
60 $postBool = $preBool =
'';
67 while ($pos < $total) {
68 if (!empty($signTokens[$pos])) $sign = $signTokens[$pos];
69 else if (empty($sign)) $sign =
'+';
83 if ($peek == $orOperator) {
86 }
else if ($peek == $andOperator) {
91 $bool = empty($postBool) ? $preBool : $postBool;
93 if ($bool ==
'or') $sign =
'';
94 if (is_array($token)) {
97 $k = $submissionSearchIndex->filterKeywords($token,
true);
99 if (!empty($k)) $return[$sign][] = $k;
118 $resultsPerKeyword =
Config::getVar(
'search',
'results_per_keyword');
119 $resultCacheHours =
Config::getVar(
'search',
'result_cache_hours');
120 if (!is_numeric($resultsPerKeyword)) $resultsPerKeyword = 100;
121 if (!is_numeric($resultCacheHours)) $resultCacheHours = 24;
123 $mergedKeywords = array(
'+' => array(),
'' => array(),
'-' => array());
124 foreach ($keywords as $type => $keyword) {
125 if (!empty($keyword[
'+']))
126 $mergedKeywords[
'+'][] = array(
'type' => $type,
'+' => $keyword[
'+'],
'' => array(),
'-' => array());
127 if (!empty($keyword[
'']))
128 $mergedKeywords[
''][] = array(
'type' => $type,
'+' => array(),
'' => $keyword[
''],
'-' => array());
129 if (!empty($keyword[
'-']))
130 $mergedKeywords[
'-'][] = array(
'type' => $type,
'+' => array(),
'' => $keyword[
'-'],
'-' => array());
132 return $this->
_getMergedKeywordResults($context, $mergedKeywords,
null, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours);
138 function _getMergedKeywordResults($context, &$keyword, $type, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours) {
139 $mergedResults =
null;
141 if (isset($keyword[
'type'])) {
142 $type = $keyword[
'type'];
145 foreach ($keyword[
'+'] as $phrase) {
146 $results = $this->
_getMergedPhraseResults($context, $phrase, $type, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours);
147 if ($mergedResults ===
null) {
148 $mergedResults = $results;
150 foreach ($mergedResults as $submissionId => $data) {
151 if (isset($results[$submissionId])) {
152 $mergedResults[$submissionId][
'count'] += $results[$submissionId][
'count'];
154 unset($mergedResults[$submissionId]);
160 if ($mergedResults ==
null) {
161 $mergedResults = array();
164 if (!empty($mergedResults) || empty($keyword[
'+'])) {
165 foreach ($keyword[
''] as $phrase) {
166 $results = $this->
_getMergedPhraseResults($context, $phrase, $type, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours);
167 foreach ($results as $submissionId => $data) {
168 if (isset($mergedResults[$submissionId])) {
169 $mergedResults[$submissionId][
'count'] += $data[
'count'];
170 }
else if (empty($keyword[
'+'])) {
171 $mergedResults[$submissionId] = $data;
176 foreach ($keyword[
'-'] as $phrase) {
177 $results = $this->
_getMergedPhraseResults($context, $phrase, $type, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours);
178 foreach ($results as $submissionId => $count) {
179 if (isset($mergedResults[$submissionId])) {
180 unset($mergedResults[$submissionId]);
186 return $mergedResults;
192 function _getMergedPhraseResults($context, &$phrase, $type, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours) {
193 if (isset($phrase[
'+'])) {
194 return $this->
_getMergedKeywordResults($context, $phrase, $type, $publishedFrom, $publishedTo, $resultsPerKeyword, $resultCacheHours);
197 $mergedResults = array();
200 return $searchDao->getPhraseResults(
231 function retrieveResults($request, $context, $keywords, &$error, $publishedFrom =
null, $publishedTo =
null, $rangeInfo =
null, $exclude = array()) {
233 if ($rangeInfo && $rangeInfo->isValid()) {
234 $page = $rangeInfo->getPage();
235 $itemsPerPage = $rangeInfo->getCount();
238 $itemsPerPage = SUBMISSION_SEARCH_DEFAULT_RESULT_LIMIT;
245 $totalResults =
null;
247 'SubmissionSearch::retrieveResults',
248 array(&$context, &$keywords, $publishedFrom, $publishedTo, $orderBy, $orderDir, $exclude, $page, $itemsPerPage, &$totalResults, &$error, &$results)
253 if ($hookResult ===
false) {
255 foreach($keywords as $searchType => $query) {
256 $keywords[$searchType] = $this->
_parseQuery($query);
263 $mergedResults = $this->
_getMergedArray($context, $keywords, $publishedFrom, $publishedTo);
271 $results = $this->
getSparseArray($mergedResults, $orderBy, $orderDir, $exclude);
272 $totalResults = count($results);
275 $offset = $itemsPerPage * ($page-1);
276 $length = max($totalResults - $offset, 0);
277 $length = min($itemsPerPage, $length);
281 $results = array_slice(
291 $results = $this->
formatResults($results, $request->getUser());
294 import(
'lib.pkp.classes.core.VirtualArrayIterator');
305 'asc' => __(
'search.results.orderDir.asc'),
306 'desc' => __(
'search.results.orderDir.desc')
320 $orderBy = $request->getUserVar(
'orderBy');
322 if (is_null($orderBy) || !in_array($orderBy, array_keys($orderByOptions))) {
327 $orderDir = $request->getUserVar(
'orderDir');
329 if (is_null($orderDir) || !in_array($orderDir, array_keys($orderDirOptions))) {
333 return array($orderBy, $orderDir);
363 abstract protected function getSparseArray($unorderedResults, $orderBy, $orderDir, $exclude);