Skip to content

Commit

Permalink
feat(Solr): Added multiple geojson point indexing
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Make sure your Solr managed-schema has a dynamic field named `*_ps` with type `location` multiValued:

```xml
<dynamicField name="*_ps" type="location" indexed="true" stored="true" multiValued="true"/>
```
  • Loading branch information
ambroisemaupate committed Sep 25, 2023
1 parent a62c29c commit 13041a2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/solr/managed-schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<dynamicField name="*_dtr" type="rdate" indexed="true" stored="true"/>
<dynamicField name="*_dts" type="pdate" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_p" type="location" indexed="true" stored="true"/>
<dynamicField name="*_ps" type="location" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_srpt" type="location_rpt" indexed="true" stored="true"/>

<!-- payloaded dynamic fields -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,28 @@ protected function formatGeoJsonFeature(mixed $geoJson): ?string
}
return null;
}

protected function formatGeoJsonFeatureCollection(mixed $geoJson): ?array
{
if (null === $geoJson) {
return null;
}
if (\is_string($geoJson)) {
$geoJson = \json_decode($geoJson, true);
}
if (!\is_array($geoJson)) {
return null;
}
if (
isset($geoJson['type']) &&
$geoJson['type'] === 'FeatureCollection' &&
isset($geoJson['features']) &&
\count($geoJson['features']) > 0
) {
return array_filter(array_map(function ($feature) {
return $this->formatGeoJsonFeature($feature);
}, $geoJson['features']));
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ function (Tag $tag) {
});
$this->indexSuffixedFields($dateTimeFields, '_dt', $nodeSource, $assoc);

/*
* Make sure your Solr managed-schema has a field named `*_p` with type `location` singleValued
* <dynamicField name="*_p" type="location" indexed="true" stored="true" multiValued="false"/>
*/
$pointFields = $node->getNodeType()->getFields()->filter(function (NodeTypeField $field) {
return $field->isGeoTag();
});
Expand All @@ -147,6 +151,21 @@ function (Tag $tag) {
$value = $nodeSource->$getter();
$assoc[$name] = $this->formatGeoJsonFeature($value);
}

/*
* Make sure your Solr managed-schema has a field named `*_ps` with type `location` multiValued
* <dynamicField name="*_ps" type="location" indexed="true" stored="true" multiValued="true"/>
*/
$multiPointFields = $node->getNodeType()->getFields()->filter(function (NodeTypeField $field) {
return $field->isMultiGeoTag();
});
foreach ($multiPointFields as $field) {
$name = $field->getName();
$name .= '_ps';
$getter = $field->getGetterName();
$value = $nodeSource->$getter();
$assoc[$name] = $this->formatGeoJsonFeatureCollection($value);
}
}

$searchableFields = $node->getNodeType()->getSearchableFields();
Expand Down

0 comments on commit 13041a2

Please sign in to comment.