diff --git a/Classes/Domain/Search/QueryFactory.php b/Classes/Domain/Search/QueryFactory.php
index 978d88a..dcf6ce5 100644
--- a/Classes/Domain/Search/QueryFactory.php
+++ b/Classes/Domain/Search/QueryFactory.php
@@ -121,6 +121,10 @@ class QueryFactory
return;
}
+ if (trim($searchRequest->getSearchTerm()) === '') {
+ return;
+ }
+
$boostQueryParts = [];
foreach ($fields as $fieldName => $boostValue) {
@@ -238,6 +242,18 @@ class QueryFactory
}
}
+ if (isset($config['raw'])) {
+ $filter = array_merge($config['raw'], $filter);
+ }
+
+ if ($config['type'] === 'range') {
+ return [
+ 'range' => [
+ $config['field'] => $filter,
+ ],
+ ];
+ }
+
return [$config['field'] => $filter];
}
diff --git a/Documentation/source/configuration/searching.rst b/Documentation/source/configuration/searching.rst
index bfed51e..857aa74 100644
--- a/Documentation/source/configuration/searching.rst
+++ b/Documentation/source/configuration/searching.rst
@@ -119,20 +119,48 @@ E.g. you submit a filter in form of:
.. code-block:: html
-
-
-
+
+ Due to TYPO3 7.x fluid limitations, we build this input ourself.
+ No longer necessary in 8 and above
+
+
+
This will create a ``distance`` filter with subproperties. To make this filter actually work, you
can add the following TypoScript, which will be added to the filter::
mapping {
filter {
- distance {
- field = geo_distance
+ month {
+ type = range
+ field = released
+ raw {
+ format = yyyy-MM
+ }
+
fields {
- distance = distance
- location = location
+ gte = from
+ lte = to
}
}
}
@@ -143,9 +171,12 @@ in elasticsearch. In above example they do match, but you can also use different
On the left hand side is the elasticsearch field name, on the right side the one submitted as a
filter.
-The ``field``, in above example ``geo_distance``, will be used as the elasticsearch field for
+The ``field``, in above example ``released``, will be used as the elasticsearch field for
filtering. This way you can use arbitrary filter names and map them to existing elasticsearch fields.
+Everything that is configured inside ``raw`` is passed, as is, to search service, e.g.
+elasticsearch.
+
.. _fields:
fields
diff --git a/Tests/Unit/Domain/Search/QueryFactoryTest.php b/Tests/Unit/Domain/Search/QueryFactoryTest.php
index 881cd8b..dc824c5 100644
--- a/Tests/Unit/Domain/Search/QueryFactoryTest.php
+++ b/Tests/Unit/Domain/Search/QueryFactoryTest.php
@@ -86,6 +86,58 @@ class QueryFactoryTest extends AbstractUnitTestCase
);
}
+ /**
+ * @test
+ */
+ public function rangeFilterIsAddedToQuery()
+ {
+ $this->configureConfigurationMockWithDefault();
+ $this->configuration->expects($this->any())
+ ->method('getIfExists')
+ ->will($this->returnCallback(function ($configName) {
+ if ($configName === 'searching.mapping.filter.month') {
+ return [
+ 'type' => 'range',
+ 'field' => 'released',
+ 'raw' => [
+ 'format' => 'yyyy-MM',
+ ],
+ 'fields' => [
+ 'gte' => 'from',
+ 'lte' => 'to',
+ ],
+ ];
+ }
+
+ return [];
+ }));
+
+ $searchRequest = new SearchRequest('SearchWord');
+ $searchRequest->setFilter([
+ 'month' => [
+ 'from' => '2016-03',
+ 'to' => '2017-11',
+ ],
+ ]);
+
+ $query = $this->subject->create($searchRequest);
+ $this->assertSame(
+ [
+ [
+ 'range' => [
+ 'released' => [
+ 'format' => 'yyyy-MM',
+ 'gte' => '2016-03',
+ 'lte' => '2017-11',
+ ],
+ ],
+ ]
+ ],
+ $query->toArray()['query']['bool']['filter'],
+ 'Filter was not added to query.'
+ );
+ }
+
/**
* @test
*/