Skip to content
Snippets Groups Projects
Commit 7132fe00 authored by hexaki's avatar hexaki
Browse files

Issue #3004866 : Updating to ES8 +fix tests

parent 0f5c1a0f
No related branches found
No related tags found
1 merge request!15Resolve #3004866 "Fix failing tests"
......@@ -56,13 +56,13 @@ phpunit:
services:
- !reference [.with-database]
- !reference [.with-chrome]
- name: elasticsearch:7.17.14
- name: elasticsearch:8.11.1
alias: elasticsearch
pull_policy: if-not-present
command:
- /bin/bash
- -c
- echo -Xms256m >> /usr/share/elasticsearch/config/jvm.options && echo -Xmx256m >> /usr/share/elasticsearch/config/jvm.options && /usr/local/bin/docker-entrypoint.sh elasticsearch -Ediscovery.type=single-node
- echo -Xms256m >> /usr/share/elasticsearch/config/jvm.options && echo -Xmx256m >> /usr/share/elasticsearch/config/jvm.options && /usr/local/bin/docker-entrypoint.sh elasticsearch -Ediscovery.type=single-node -Expack.security.enabled=false
###################################################################################
#
......
......@@ -408,6 +408,29 @@ class SearchBuilder {
return $ret;
}
/**
* Get args for range query.
*
* @param \Drupal\search_api\Query\ConditionInterface $condition
* Condition.
*
* @return array
* Range args.
*/
protected function getRangeArgs(ConditionInterface $condition) : array {
$field_type = $this->indexFields[$condition->getField()]?->getType() ?? "";
$args = [
'gte' => $condition->getValue()[0] ?? NULL,
'lte' => $condition->getValue()[1] ?? NULL,
];
if ($field_type == "date" && is_int($args["gte"]) && is_int($args["lte"])) {
$args["format"] = "epoch_second";
}
return $args;
}
/**
* Get query by Condition instance.
*
......@@ -482,24 +505,17 @@ class SearchBuilder {
case 'BETWEEN':
$filter = new Range(
$condition->getField(),
[
'gte' => !empty($condition->getValue()[0]) ? (float) $condition->getValue()[0] : NULL,
'lte' => !empty($condition->getValue()[1]) ? (float) $condition->getValue()[1] : NULL,
]
$this->getRangeArgs($condition),
);
break;
case 'NOT BETWEEN':
$filter = new BoolQuery();
$filter->addMustNot(
new Range(
$condition->getField(),
[
'gte' => !empty($condition->getValue()[0]) ? (float) $condition->getValue()[0] : NULL,
'lte' => !empty($condition->getValue()[1]) ? (float) $condition->getValue()[1] : NULL,
]
)
);
$filter->addMustNot(new Range(
$condition->getField(),
$this->getRangeArgs($condition),
));
break;
default:
......
......@@ -130,7 +130,6 @@ class MappingFactory {
case 'text':
$mappingConfig = [
'type' => 'text',
'boost' => $field->getBoost(),
'fields' => [
"keyword" => [
"type" => 'keyword',
......
......@@ -163,4 +163,48 @@ class ElasticsearchTest extends BackendTestBase {
// Aggregations are not allowed on text.
}
/**
* {@inheritdoc}
*/
protected function addTestEntity($id, array $values) {
$created = match ($id) {
1 => strtotime("2003-07-10"),
2 => strtotime("2008-06-28"),
3 => strtotime("2012-06-11"),
4 => strtotime("2016-09-16"),
5 => strtotime("2018-04-02"),
default => NULL,
};
if ($created) {
$values["created"] = $created;
}
return parent::addTestEntity($id, $values);
}
/**
* {@inheritdoc}
*/
protected function searchSuccess() {
parent::searchSuccess();
$results = $this->buildSearch()
->addCondition("created", [
"2008-06-27",
"2012-06-12",
], "BETWEEN")
->execute();
$this->assertEquals($this->getItemIds([2, 3]), array_keys($results->getResultItems()), 'Search for created range returned correct results.');
$results = $this->buildSearch()
->addCondition("created", [
strtotime("2008-06-27"),
strtotime("2012-06-12"),
], "BETWEEN")
->execute();
$this->assertEquals($this->getItemIds([2, 3]), array_keys($results->getResultItems()), 'Search for created range returned correct results.');
}
}
......@@ -79,7 +79,6 @@ class MappingFactoryTest extends UnitTestCase {
],
$field1Id => [
'type' => 'text',
'boost' => 1.1,
'fields' => [
'keyword' => ['type' => 'keyword', 'ignore_above' => 256],
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment