/** * Internal function to return a Journal object from a row. * @param $row array * @return Journal */ function &_returnJournalFromRow(&$row) { $journal = new Journal(); $journal->setId($row['journal_id']); $journal->setPath($row['path']); $journal->setSequence($row['seq']); $journal->setEnabled($row['enabled']); $journal->setPrimaryLocale($row['primary_locale']); HookRegistry::call('JournalDAO::_returnJournalFromRow', array(&$journal, &$row)); return $journal; }
/** * @covers SolrWebService::getAutosuggestions() */ public function testGetAutosuggestions() { // Fake a search request. $searchRequest = new SolrSearchRequest(); $journal = new Journal(); $journal->setId(2); $searchRequest->setJournal($journal); $searchRequest->setQuery(array('authors' => 'McAutomatic')); // Only the last word should be corrected. This also // checks whether suggestions come from different fields. self::assertEquals(array('chic (AND wings', 'chic (AND wide'), $this->solrWebService->getAutosuggestions($searchRequest, 'query', 'chic (AND wi', SOLR_AUTOSUGGEST_SUGGESTER)); // The faceting component will return no suggestions for // the same query as it wouldn't return any results. self::assertEquals(array(), $this->solrWebService->getAutosuggestions($searchRequest, 'query', 'chic (AND wi', SOLR_AUTOSUGGEST_FACETING)); // Even when we correct the first word, we'll not get // results due to the fact that there's no such article // with the author given in the search request. self::assertEquals(array(), $this->solrWebService->getAutosuggestions($searchRequest, 'query', 'chicken (AND wi', SOLR_AUTOSUGGEST_FACETING)); // We start to get a result from the faceting component // when we enter another author. But the result will only // include suggestions that actually return something. $searchRequest->setQuery(array('authors' => 'Peter Poultry')); self::assertEquals(array('chicken (AND wings'), $this->solrWebService->getAutosuggestions($searchRequest, 'query', 'chicken (AND wi', SOLR_AUTOSUGGEST_FACETING)); $searchRequest->setQuery(array()); foreach (array(SOLR_AUTOSUGGEST_FACETING, SOLR_AUTOSUGGEST_SUGGESTER) as $autosuggestType) { // When the last word cannot be improved then // return no results. self::assertEquals(array(), $this->solrWebService->getAutosuggestions($searchRequest, 'query', 'chicken AND dslgkhsi', $autosuggestType)); // Check whether results for index term suggestions // come from different sources (but not all sources). // The following search should not return 'lucene' for // example, which would come from a non-index field. self::assertEquals(array('lunch', 'lunchtime'), $this->solrWebService->getAutosuggestions($searchRequest, 'indexTerms', 'lu', $autosuggestType)); } // Check one of the "simple" search fields, e.g. authors. // This also shows that the suggester will propose terms // from other journals. The author "tester" does not appear // in the journal chosen for the search request above. self::assertEquals(array('tester'), $this->solrWebService->getAutosuggestions($searchRequest, 'authors', 'tes', SOLR_AUTOSUGGEST_SUGGESTER)); // In the case of the faceting component this should not return // any result as the author comes from a different journal. self::assertEquals(array(), $this->solrWebService->getAutosuggestions($searchRequest, 'authors', 'tes', SOLR_AUTOSUGGEST_FACETING)); // This changes when we look for author names that // exist in the journal. self::assertEquals(array('author', 'authorname'), $this->solrWebService->getAutosuggestions($searchRequest, 'authors', 'au', SOLR_AUTOSUGGEST_FACETING)); }