/** * Support method for initGenericRangeFilters() -- build a filter query based on * a range of values. * * @param string $field field to use for filtering. * @param string $from start of range. * @param string $to end of range. * @param bool $cs Should ranges be case-sensitive? * * @return string filter query. */ protected function buildGenericRangeFilter($field, $from, $to, $cs = true) { // Assume Solr syntax -- this should be overridden in child classes where // other indexing methodologies are used. $range = "{$field}:[{$from} TO {$to}]"; if (!$cs) { // Flip values if out of order: if (strcmp(strtolower($from), strtolower($to)) > 0) { $range = "{$field}:[{$to} TO {$from}]"; } $helper = new LuceneSyntaxHelper(false, false); $range = $helper->capitalizeRanges($range); } return $range; }
/** * Test capitalizeRanges functionality. * * @return void */ public function testCapitalizeRanges() { $lh = new LuceneSyntaxHelper(); // Set up an array of expected inputs and outputs: // @codingStandardsIgnoreStart $tests = [['"{a to b}"', '"{a to b}"'], ['"[a to b]"', '"[a to b]"'], ['[a to b]', '([a TO b] OR [A TO B])'], ['[a TO b]', '([a TO b] OR [A TO B])'], ['[a To b]', '([a TO b] OR [A TO B])'], ['[a tO b]', '([a TO b] OR [A TO B])'], ['{a to b}', '({a TO b} OR {A TO B})'], ['{a TO b}', '({a TO b} OR {A TO B})'], ['{a To b}', '({a TO b} OR {A TO B})'], ['{a tO b}', '({a TO b} OR {A TO B})'], ['[1900 to 1910]', '[1900 TO 1910]'], ['[1900 TO 1910]', '[1900 TO 1910]'], ['{1900 to 1910}', '{1900 TO 1910}'], ['{1900 TO 1910}', '{1900 TO 1910}'], ['[a to b]', '([a TO b] OR [A TO B])'], ['[1900-01-01t00:00:00z to 1900-12-31t23:59:59z]', '[1900-01-01T00:00:00Z TO 1900-12-31T23:59:59Z]'], ['{1900-01-01T00:00:00Z TO 1900-12-31T23:59:59Z}', '{1900-01-01T00:00:00Z TO 1900-12-31T23:59:59Z}']]; // @codingStandardsIgnoreEnd // Test all the operations: foreach ($tests as $current) { $this->assertEquals($lh->capitalizeRanges($current[0]), $current[1]); } }