Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Geothesaurus Searching Closes #1396 #1404

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions classes/GeographicThesaurus.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,11 @@ public function getGeoLevelString(int $geolevel) {
}
}

public function searchGeothesaurus(string $geoterm, int|null $geolevel = null, string|null $parent = null): array {
$sql = <<<'SQL'
public function searchGeothesaurus(string $geoterm, int|null $geolevel = null, string|null $parent = null, bool $distict_geoterms = false): array {
$sql = <<<SQL
SELECT g.geoThesID, g.geoterm, g.geoLevel, g.parentID, g2.geoterm AS parentterm, g2.geoLevel AS parentlevel FROM geographicthesaurus g
LEFT JOIN geographicthesaurus g2 ON g2.geoThesID = g.parentID
WHERE g.geoterm LIKE ? ORDER BY g.geoterm, CHAR_LENGTH(g.geoterm)
WHERE g.geoterm LIKE ?
SQL;

$params = ['%' . $geoterm . '%'];
Expand All @@ -772,8 +772,14 @@ public function searchGeothesaurus(string $geoterm, int|null $geolevel = null, s
if($parent !== null) {
$sql .= ' and g2.geoterm like ?';
array_push($params, '%' . $parent . '%');
}

if($distict_geoterms) {
$sql .= ' GROUP BY geoterm ';
}

$sql .= ' ORDER BY g.geoterm, CHAR_LENGTH(g.geoterm)';

$result = $this->conn->execute_query($sql, $params);

$geoterms = $result->fetch_all(MYSQLI_ASSOC);
Expand Down
3 changes: 2 additions & 1 deletion geothesaurus/rpc/searchGeothesaurus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
$geoterm = array_key_exists('geoterm',$_REQUEST)? $_REQUEST['geoterm']:'';
$geolevel = array_key_exists('geolevel',$_REQUEST) && is_numeric($_REQUEST['geolevel'])? intval($_REQUEST['geolevel']): null;
$parent = array_key_exists('parent',$_REQUEST)? $_REQUEST['parent']: null;
$distict = array_key_exists('distict',$_REQUEST)? true: false;

$geoManager = new GeographicThesaurus();
$geoterms = $geoManager->searchGeothesaurus($geoterm, $geolevel, $parent);
$geoterms = $geoManager->searchGeothesaurus($geoterm, $geolevel, $parent, $distict);
echo json_encode($geoterms);
?>
5 changes: 4 additions & 1 deletion js/symb/localitySuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function geothesaurusSource(params) {
response(data.map(v => ({ label: v.geoterm, value: v.geoterm })))
}

if (params.parent) {
if (parent_selector) {
const el = document.getElementById(parent_selector)
if (el) {
params.parent = el.value
Expand All @@ -14,6 +14,9 @@ function geothesaurusSource(params) {

const url = "../../geothesaurus/rpc/searchGeothesaurus.php";
params.geoterm = request.term;

//Always Reduce to unique geoterms for locality suggestions
params.distict = true;
$.getJSON(url, params, optionize)
}
}
Expand Down