/** * Build a string for onscreen display showing the * query used in the search (not the filters). * * @return string user friendly version of 'query' */ public function getDisplayQuery() { // Set up callbacks with no-op translator to keep the English // boolean operators: $translate = function ($str) { return $str; }; $showField = [$this->getOptions(), 'getHumanReadableFieldName']; // Build display query: return QueryAdapter::display($this->getQuery(), $translate, $showField); }
/** * Restore settings from a minified object found in the database. * * @param \VuFind\Search\Minified $minified Minified Search Object * * @return void */ public function deminify($minified) { // Some values will transfer without changes $this->filterList = $minified->f; $this->hiddenFilters = $minified->hf; $this->searchType = $minified->ty; // Deminified searches will always have defaults already applied; // we don't want to accidentally manipulate them further. $defaults = $this->getOptions()->getDefaultFilters(); if (!empty($defaults)) { $this->defaultsApplied = true; } // Search terms, we need to expand keys $this->query = QueryAdapter::deminify($minified->t); }
/** * Test display capabilities. * * @return void */ public function testDisplay() { // Array of fixture directory => expected display query $cases = ['basic' => 'john smith', 'advanced' => '(CallNumber:oranges AND toc:bananas AND ISN:pears) OR (Title:cars OR Subject:trucks) NOT ((AllFields:squid))']; // Create simple closure to fill in for translation callbacks: $echo = function ($str) { return $str; }; // Run the tests: $fixturePath = realpath(__DIR__ . '/../../../../fixtures/searches') . '/'; foreach ($cases as $case => $expected) { $q = unserialize(file_get_contents($fixturePath . $case . '/query')); $this->assertEquals($expected, QueryAdapter::display($q, $echo, $echo)); } }