Skip to content

Commit dfc1f1b

Browse files
committed
Fixed map distance range
1 parent 5718bcd commit dfc1f1b

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

.github/init_solr.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/usr/bin/env bash
22

3+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
4+
35
SOLR_VERSION=${SOLR_VERSION:-'9.8.1'}
46

57
if [[ "${SOLR_VERSION}" =~ ^9\. ]]; then
6-
default_config_files[1]='src/lib/Resources/config/solr/managed-schema.xml'
8+
default_config_files[1]="${SCRIPT_DIR}/../src/lib/Resources/config/solr/managed-schema.xml"
79
else
8-
default_config_files[1]='src/lib/Resources/config/solr/schema.xml'
10+
default_config_files[1]="${SCRIPT_DIR}/../src/lib/Resources/config/solr/schema.xml"
911
fi
1012

11-
default_config_files[2]='src/lib/Resources/config/solr/custom-fields-types.xml'
12-
default_config_files[3]='src/lib/Resources/config/solr/language-fieldtypes.xml'
13+
default_config_files[2]="${SCRIPT_DIR}/../src/lib/Resources/config/solr/custom-fields-types.xml"
14+
default_config_files[3]="${SCRIPT_DIR}/../src/lib/Resources/config/solr/language-fieldtypes.xml"
1315

1416
default_cores[0]='core0'
1517
default_cores[1]='core1'
@@ -119,8 +121,8 @@ copy_file() {
119121
create_dir() {
120122
local dir_name=$1
121123

122-
if [ ! -d ${dir_name} ] ; then
123-
mkdir ${dir_name} || exit_on_error "Couldn't create directory '${dir_name}'"
124+
if [ ! -d "${dir_name}" ] ; then
125+
mkdir -p "${dir_name}" || exit_on_error "Couldn't create directory '${dir_name}'"
124126
echo "Created directory '${dir_name}'"
125127
fi
126128
}

src/lib/Query/Common/CriterionVisitor/MapLocation/MapLocationDistanceRange.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public function canVisit(Criterion $criterion)
2929
return
3030
$criterion instanceof Criterion\MapLocationDistance &&
3131
($criterion->operator === Operator::LT ||
32-
$criterion->operator === Operator::LTE ||
33-
$criterion->operator === Operator::GT ||
34-
$criterion->operator === Operator::GTE ||
35-
$criterion->operator === Operator::BETWEEN);
32+
$criterion->operator === Operator::LTE ||
33+
$criterion->operator === Operator::GT ||
34+
$criterion->operator === Operator::GTE ||
35+
$criterion->operator === Operator::BETWEEN);
3636
}
3737

3838
/**
@@ -47,15 +47,18 @@ public function canVisit(Criterion $criterion)
4747
*/
4848
public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null)
4949
{
50-
$criterion->value = (array)$criterion->value;
51-
52-
$start = $criterion->value[0];
53-
$end = isset($criterion->value[1]) ? $criterion->value[1] : 63510;
50+
if (is_array($criterion->value)) {
51+
$minDistance = $criterion->value[0];
52+
$maxDistance = $criterion->value[1] ?? 63510;
53+
} else {
54+
$minDistance = 0;
55+
$maxDistance = $criterion->value;
56+
}
5457

55-
if (($criterion->operator === Operator::LT) ||
56-
($criterion->operator === Operator::LTE)) {
57-
$end = $start;
58-
$start = null;
58+
$sign = '';
59+
if (($criterion->operator === Operator::GT) ||
60+
($criterion->operator === Operator::GTE)) {
61+
$sign = '-';
5962
}
6063

6164
$searchFields = $this->getSearchFields(
@@ -77,17 +80,25 @@ public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null)
7780

7881
$queries = [];
7982
foreach ($searchFields as $name => $fieldType) {
80-
// @todo in future it should become possible to specify ranges directly on the filter (donut shape)
81-
$query = sprintf('{!geofilt sfield=%s pt=%F,%F d=%s}', $name, $location->latitude, $location->longitude, $end);
82-
if ($start !== null) {
83-
$query = sprintf("{!frange l=%F}{$query}", $start);
83+
if ($criterion->operator === Operator::BETWEEN) {
84+
$query = sprintf(
85+
'{!geofilt sfield=%s pt=%F,%F d=%s} AND -{!geofilt sfield=%s pt=%F,%F d=%s}',
86+
$name,
87+
$location->latitude,
88+
$location->longitude,
89+
$maxDistance,
90+
$name,
91+
$location->latitude,
92+
$location->longitude,
93+
$minDistance
94+
);
95+
} else {
96+
$query = sprintf('%s{!geofilt sfield=%s pt=%F,%F d=%s}', $sign, $name, $location->latitude, $location->longitude, $maxDistance);
8497
}
8598

86-
$queries[] = "{$query} AND {$name}_0_coordinate:[* TO *]";
99+
$queries[] = "{$query} AND {$name}:[* TO *]";
87100
}
88101

89102
return '(' . implode(' OR ', $queries) . ')';
90103
}
91104
}
92-
93-
class_alias(MapLocationDistanceRange::class, 'EzSystems\EzPlatformSolrSearchEngine\Query\Common\CriterionVisitor\MapLocation\MapLocationDistanceRange');

src/lib/Resources/config/solr/custom-fields-types.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<copyField source="user_first_name_value_s" dest="custom_field" />
1414
<copyField source="user_last_name_value_s" dest="custom_field" />
1515

16-
<field name="custom_geolocation_field" type="location" indexed="true" stored="false" required="false" />
17-
<field name="custom_geolocation_field_0_coordinate" type="double" indexed="true" stored="false"/>
18-
<field name="custom_geolocation_field_1_coordinate" type="double" indexed="true" stored="false"/>
16+
<field name="custom_geolocation_field" type="location" indexed="true" stored="false" docValues="true" required="false" />
17+
1918
<copyField source="testtype_maplocation_value_location_gl" dest="custom_geolocation_field" />

src/lib/Resources/config/solr/managed-schema.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ should not remove or drastically change the existing definitions.
8282

8383
<fieldtype name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" />
8484
<fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
85-
<fieldType name="location" class="solr.LatLonPointSpatialField" sortMissingLast="true"/>
85+
<fieldType name="location"
86+
class="solr.LatLonPointSpatialField"
87+
indexed="true"
88+
stored="true"
89+
docValues="true"
90+
sortMissingLast="true"/>
8691

8792
<!-- for 1536-dim models (ada-002 & 3-small) -->
8893
<fieldType name="vector_1536"
@@ -140,8 +145,6 @@ should not remove or drastically change the existing definitions.
140145
<dynamicField name="*_d" type="double" indexed="true" stored="true"/>
141146
<dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
142147
<dynamicField name="*_gl" type="location" indexed="true" stored="true"/>
143-
<dynamicField name="*_gl_0_coordinate" type="double" indexed="true" stored="true"/>
144-
<dynamicField name="*_gl_1_coordinate" type="double" indexed="true" stored="true"/>
145148

146149
<!--
147150
This field is required to allow random sorting

0 commit comments

Comments
 (0)