From 3631ea1983251f4d9e8aab4099def21d9dfb2ee9 Mon Sep 17 00:00:00 2001 From: Sebastian Gutzeit Date: Tue, 26 Jun 2018 12:53:26 +0200 Subject: [PATCH] Adressensuche via Such-API geocodr realisiert --- README.md | 37 ++- app/assets/javascripts/autocomplete.coffee | 2 +- app/controllers/places_controller.rb | 13 +- app/models/place.rb | 4 +- app/views/places/mobile/_index.html.erb | 16 +- config/settings.sample.yml | 5 + public/search/Search.php | 143 ---------- public/search/conf/config.sample.php | 25 -- public/search/lib/ColognePhonetic.php | 222 --------------- public/search/lib/SolrClient2/README.md | 26 -- public/search/lib/SolrClient2/composer.json | 23 -- public/search/lib/SolrClient2/doc/conf.md | 68 ----- public/search/lib/SolrClient2/doc/query.md | 30 -- .../lib/ARP/SolrClient2/CurlBrowser.php | 95 ------- .../lib/ARP/SolrClient2/Paging.php | 82 ------ .../lib/ARP/SolrClient2/SolrClient.php | 154 ---------- .../lib/ARP/SolrClient2/SolrCore.php | 264 ------------------ .../lib/ARP/SolrClient2/SolrDocument.php | 114 -------- .../lib/ARP/SolrClient2/SolrQuery.php | 247 ---------------- public/search/server.php | 72 ----- public/search/updateIndex.php | 119 -------- 21 files changed, 53 insertions(+), 1708 deletions(-) delete mode 100644 public/search/Search.php delete mode 100644 public/search/conf/config.sample.php delete mode 100644 public/search/lib/ColognePhonetic.php delete mode 100644 public/search/lib/SolrClient2/README.md delete mode 100644 public/search/lib/SolrClient2/composer.json delete mode 100644 public/search/lib/SolrClient2/doc/conf.md delete mode 100644 public/search/lib/SolrClient2/doc/query.md delete mode 100644 public/search/lib/SolrClient2/lib/ARP/SolrClient2/CurlBrowser.php delete mode 100644 public/search/lib/SolrClient2/lib/ARP/SolrClient2/Paging.php delete mode 100644 public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrClient.php delete mode 100644 public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrCore.php delete mode 100644 public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrDocument.php delete mode 100644 public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrQuery.php delete mode 100755 public/search/server.php delete mode 100644 public/search/updateIndex.php diff --git a/README.md b/README.md index cd08751d..d8f14289 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,6 @@ Für die Konfigurationsdateien mit vertraulichem Inhalt gibt es versionierbare V #### Block 'urls' Zentrale Konfiguration von im Frontend genutzten URLs. - - `ks_frontend_search_url` (Pflichtfeld): - - URL zur Straßen- und Adresssuche - `ks_server_url` (Pflichtfeld): - URL zum Klarschiff-Frontend - `ks_backend_vorgang_url` (Pflichtfeld): @@ -92,13 +90,13 @@ Zentrale Konfiguration von im Frontend genutzten URLs. Konfiguration des entsprechenden Clients, den Außendienst-Client (Prüf- und Protokoll-Client, PPC) oder mobilen Client: - `animate_refresh` (Pflichtfeld): - Zeitabstand (in Sekunden) zwischen der letzten und der nächsten Animation für den "Neue Meldung"-Marker - - `service_code` (Optional): + - `service_code` (optional): - ID der Unterkategorie, auf die die Funktionalitäten des PC-Clients beschränkt werden sollen - `key` (Pflichtfeld): - Kurzwort für die zugehörige Stadt/Gemeinde (z.B. hro, hgw, sn) - `login_required` (Pflichtfeld): - wenn auf `true` gesetzt, wird der PPC konfiguriert, ansonsten der mobile Client - - `multi_requests_enabled` (Optional): + - `multi_requests_enabled` (optional): - ermöglicht das Anlegen von Multimeldungen (Es werden einzelne "normale" Meldungen erzeugt, welche in den wesentlichen Eigenschaften identisch sind, allerdings unterschiedlichen Kategorien zugeordnet sind. Diese verbleiben nach der Erstellung vollständig eigentständig) - `name` (Pflichtfeld): - Name des Clients @@ -112,37 +110,37 @@ Konfiguration des entsprechenden Clients, den Außendienst-Client (Prüf- und Pr - Pfad in dem die automatisch generierten statischen Dateien der Vorgangslisten abgelegt wurden - `logo_url` (Pflichtfeld): - Pfad zum Gemeinde-Logo - - `show_email` (Optional): + - `show_email` (optional): - steuert die Darstellung der e-Mail-Felder in den Formularen für Meldungen und interne Kommentare - auf `true` gesetzt, wenn der mobile Client konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_abuses` (Optional): + - `show_abuses` (optional): - steuert die Darstellung der `Missbrauch`-Schaltfläche für Meldungen - auf `true` gesetzt, wenn der mobile Client konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_votes` (Optional): + - `show_votes` (optional): - steuert die Darstellung der Schaltfläche zum Unterstützen einer Meldung sowie die Anzahl der bisherigen Unterstützungen der Meldung - auf `true` gesetzt, wenn der mobile Client konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_create_comments` (Optional): + - `show_create_comments` (optional): - steuert die Darstellung der Schaltfläche `Lob, Hinweise oder Kritik` - auf `true` gesetzt, wenn der mobile Client konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_comments` (Optional): + - `show_comments` (optional): - steuert die Darstellung der Kommentare einer Meldung - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_edit_request` (Optional): + - `show_edit_request` (optional): - steuert die Darstellung der Bearbeiten-Schaltfläche einer Meldung - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_edit_status` (Optional): + - `show_edit_status` (optional): - steuert die Darstellung der Schaltfläche zum Ändern des Status eines Auftrags - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_protocol` (Optional): + - `show_protocol` (optional): - steuert die Darstellung der Schaltfäche zur Erstellung eines KOD-Protokolls einer Meldung - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_notes` (Optional): + - `show_notes` (optional): - steuert die Dartsellung der Schaltfläche zur Erstellung und Anzeige von internen Kommentaren - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_trust` (Optional): + - `show_trust` (optional): - steuert die Darstelling der Trust-Level-Sterne - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - - `show_d3_document_url` (Optional): + - `show_d3_document_url` (optional): - steuert die Dartsellung der Schaltfläche zum Aufruf der Vorgangs-Akte im d.3-Client - auf `true` gesetzt, wenn der PPC konfiguriert ist und der Parameter nicht mit einem Wert belegt wurde - `additional_content` (Pflichtfeld): @@ -184,6 +182,15 @@ Konfiguration des entsprechenden Clients, den Außendienst-Client (Prüf- und Pr - `api_key` - API-Key zur Authentifizierung des Clients +#### Block 'address_search' +Konfiguration der Adressensuche: + - `url` (Pflichtfeld): + - URL zur Adressensuche + - `api_key` (Pflichtfeld): + - API-Key für Adressensuche + - `localisator` (optional): + - String zur Voreingrenzung der Resultate der Adressensuche (z.B. `rostock`, um Resultate der Adressensuche auf Rostock voreinzugrenzen) + #### Block 'protocol_mail' - `recipient` (Pflichtfeld für PPC): - E-Mail-Empfänger der Protokoll-Benachrichtigungen diff --git a/app/assets/javascripts/autocomplete.coffee b/app/assets/javascripts/autocomplete.coffee index d57f224e..7209f722 100644 --- a/app/assets/javascripts/autocomplete.coffee +++ b/app/assets/javascripts/autocomplete.coffee @@ -11,6 +11,6 @@ $ -> ) minLength: 2 select: (event, ui) -> - $.get("/map?#{ ui.item.id.map( (obj) -> "bbox[]=#{ obj }").join('&') }", + $.get("/map?#{ ui.item.bbox.map( (obj) -> "bbox[]=#{ obj }").join('&') }", null, null, 'script') false diff --git a/app/controllers/places_controller.rb b/app/controllers/places_controller.rb index 4f96b3b4..3238fecc 100644 --- a/app/controllers/places_controller.rb +++ b/app/controllers/places_controller.rb @@ -9,11 +9,16 @@ def index return head(:ok) if params[:pattern] else require 'open-uri' - uri = URI(Settings::Url.ks_frontend_search_url) - uri.query = URI.encode_www_form(searchtext: @pattern) - + uri = URI(Settings::AddressSearch.url) + if !(localisator = Settings::AddressSearch.localisator).blank? + query = Settings::AddressSearch.localisator + ' ' + @pattern + else + query = @pattern + end + uri.query = URI.encode_www_form(key: Settings::AddressSearch.api_key, query: query, type: 'search', class: 'address', shape: 'bbox', limit: '5') + if (res = open(uri, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE)) && res.status.include?('OK') - @places = Array.wrap(JSON.parse(res.read).try(:[], 'array')).map do |p| + @places = Array.wrap(JSON.parse(res.read).try(:[], 'features')).map do |p| Place.new p end end diff --git a/app/models/place.rb b/app/models/place.rb index 4884d975..50d214a8 100644 --- a/app/models/place.rb +++ b/app/models/place.rb @@ -1,9 +1,9 @@ class Place include ActiveModel::Model - attr_accessor :label, :bbox + attr_accessor :type, :properties, :geometry def as_json(options = {}) - { id: bbox, label: label } + { label: properties['objektgruppe'] == 'Gemeindeteil' ? properties['_title_'].split(', ')[-1] : properties['abkuerzung'].blank? ? properties['_title_'].split(', ')[-1] : properties['_title_'].split(', ')[-1] + ' (' + properties['abkuerzung'] + ')', bbox: geometry['type'] == 'Point' ? [geometry['coordinates'][0],geometry['coordinates'][1],geometry['coordinates'][0],geometry['coordinates'][1]] : [geometry['coordinates'][0][0][0],geometry['coordinates'][0][0][1],geometry['coordinates'][0][2][0],geometry['coordinates'][0][2][1]] } end end diff --git a/app/views/places/mobile/_index.html.erb b/app/views/places/mobile/_index.html.erb index 71e7088c..7db405b0 100644 --- a/app/views/places/mobile/_index.html.erb +++ b/app/views/places/mobile/_index.html.erb @@ -21,8 +21,20 @@
<%= t('.results') %>
<% @places.each do |place| -%> - <%= link_to(map_path(bbox: place.bbox, mobile: @mobile), remote: true, class: 'list-group-item') do %> - <%= place.label %> + <% if place.geometry['type'] == 'Point' %> + <% @bbox = [place.geometry['coordinates'][0],place.geometry['coordinates'][1],place.geometry['coordinates'][0],place.geometry['coordinates'][1]] -%> + <% else %> + <% @bbox = [place.geometry['coordinates'][0][0][0],place.geometry['coordinates'][0][0][1],place.geometry['coordinates'][0][2][0],place.geometry['coordinates'][0][2][1]] -%> + <% end %> + <%= link_to(map_path(bbox: @bbox, mobile: @mobile), remote: true, class: 'list-group-item') do %> + <% if place.properties['objektgruppe'] == 'Gemeindeteil' %> + <%= place.properties['_title_'].split(', ')[-1] %> + <% elsif not place.properties['abkuerzung'].blank? %> + <%= place.properties['_title_'].split(', ')[-1] + ' (' + place.properties['abkuerzung'] + ')' %> + <% else %> + <%= place.properties['_title_'].split(', ')[-1] %> + <% end %> + <% end %> <% end -%>
diff --git a/config/settings.sample.yml b/config/settings.sample.yml index 86cd940d..10dddbcc 100644 --- a/config/settings.sample.yml +++ b/config/settings.sample.yml @@ -56,6 +56,11 @@ resource_servers: format: :json api_key: 1234567890abcdefghijklmnopqrstuv +address_search: + url: https://geo.sv.rostock.de/geocodr/query? + api_key: 1234567890abcdefghijklmnopqrstuv + localisator: rostock + protocol_mail: recipient: recipient@klarschiff.de sender: sender@klarschiff.de diff --git a/public/search/Search.php b/public/search/Search.php deleted file mode 100644 index 053b8653..00000000 --- a/public/search/Search.php +++ /dev/null @@ -1,143 +0,0 @@ -solr = new SolrClient($solrConf); - $this->phonetic = Text_ColognePhonetic::singleton(); - } - - /** - * Search - * @param $string - * @return Object - */ - public function find($string) - { - $array = $this->tokenize($string); - $query = $array['query']; - if(defined('ORT')){ - $ortArr = $this->tokenize(ORT); - $query = $ortArr['query'] . " AND " . $query; - } - return $this->solr->exec($query); - } - - /** - * Truncates the index. - */ - public function openIndex() - { - $this->solr->deleteAll(); - $this->solr->commit(); - } - - /** - * Add or update a document in the index. - * @param $string - * @param array $data - */ - public function updateIndex($string, array $data) - { - $array = $this->tokenize($string); - - $doc = $this->solr->newDocument(); - $doc->id = ++$this->id; - $doc->text = trim($array['terms']); - $doc->json = json_encode($data); - - $this->solr->appendDocument($doc); - } - - /** - * Commit all documents into the index and optimize. - */ - public function closeIndex() - { - $this->solr->commit(); - $this->solr->optimize(); - } - - /** - * Create tokens from string. - * @param $string - * @return array - */ - public function tokenize($string) - { - $terms = ""; - $query = ""; - - // Tokenize - $array = array_unique( - array_filter( - preg_split("/[^a-z0-9äöüÄÖÜßé]/i", strtolower($string)) - ) - ); - - // Prepare street - $tmp = array(); - - foreach ($array as $token) { - // Ignore street string. - if (in_array($token, array('str', 'straße', 'strasse'))) { - continue; - } - - // Cut street string at the end of the file. - $term = preg_replace("/strasse$|straße$|str$/i", "", $token); - - // House number or house number addition - if (preg_match("/^[\d]+$/", $term) || strlen($term) <= 2) { - $tmp[] = $term; - $terms .= " $term"; - $query .= " $term^2.5"; - continue; - } - - // Normal word - $phon = $this->phonetic->encode($term); - $tmp[] = $term; - $terms .= " $term $phon"; - $query .= " ($term^31.0 OR $term*^30.5 OR *$term*^30.0 OR $phon^1.5 OR $phon*^1.0 OR *$phon*^0.5)"; - - // Street - if ($term !== $token) { - $tmp[] = "str"; - $terms .= " str"; - $query .= " str^2.5"; - } - } - - $array = $tmp; - - unset($tmp); - - return array( - 'array' => $array, - 'query' => trim($query), - 'terms' => trim($terms), - ); - } -} diff --git a/public/search/conf/config.sample.php b/public/search/conf/config.sample.php deleted file mode 100644 index 2891d4c0..00000000 --- a/public/search/conf/config.sample.php +++ /dev/null @@ -1,25 +0,0 @@ - 'localhost', - 'port' => 8080, - 'path' => 'solr', - 'core' => 'klarschiff', - 'version' => 4, - 'params' => array( - 'rows' => 5 - ) -); diff --git a/public/search/lib/ColognePhonetic.php b/public/search/lib/ColognePhonetic.php deleted file mode 100644 index 56940424..00000000 --- a/public/search/lib/ColognePhonetic.php +++ /dev/null @@ -1,222 +0,0 @@ - - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * The names of the authors may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @category Text - * @package Text_ColognePhonetic - * @author Marco Graetsch - * @copyright 2008 magdev - * @version Release: @package_version@ - * @link http://pear.magdev.de/package/Text_ColognePhonetic - * @license http://opensource.org/licenses/bsd-license.php New BSD License - */ - - -/** - * Implementation of the 'Koelner Phonetik' algorithm - * - * @category Text - * @package Text_ColognePhonetic - * @author Marco Graetsch - * @link http://pear.magdev.de/package/Text_ColognePhonetic - * @link http://de.wikipedia.org/wiki/K%C3%B6lner_Phonetik - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @example example.php - */ -class Text_ColognePhonetic -{ - /** - * Store the singleton instance - * @var Text_ColognePhonetic - */ - private static $_inst = null; - - /** - * Store the rules for conversion - * @var array - */ - private $_rules = array( - array('/[aejiouyäöüÄÖÜ]/i', '0'), - array('/[b]/i', '1'), - array('/[p][^h]/i', '1'), - array('/[dt]([csz])/i', '8$1'), - array('/[dt](?<=[^csz])/i', '2$1'), - array('/[fvw]/i', '3'), - array('/p([h])/i', '3$1'), - array('/[gkq]/i', '4'), - array('/^c([ahkloqrux])/i', '4$1'), - array('/([^sz])c([ahkoqux])/i', '${1}4$2'), - array('/([^ckq]??)x/i', '${1}48'), - array('/[l]/i', '5'), - array('/[mn]/i', '6'), - array('/[r]/i', '7'), - array('/([sz])c/i', '${1}8'), - array('/[szß]/i', '8'), - array('/^c([^ahkloqrux]??)/i', '8$1'), - array('/([ckq])x/i', '${1}8'), - array('/[h]/i', ''), - ); - - - /** - * Get a singleton-instance of Text_ColognePhonetic - * - * @return Text_ColognePhonetic - */ - public static function singleton() - { - if (is_null(self::$_inst)) { - self::$_inst = new Text_ColognePhonetic(); - } - return self::$_inst; - } - - - - /** - * Compare two strings - * - * @param string $string1 - * @param string $string2 - * @return string - */ - public static function staticCompare($string1, $string2) - { - return self::singleton()->compare($string1, $string2); - } - - - /** - * Encode a string - * - * @param string $string The string to encode - * @return string - */ - public static function staticEncode($string) - { - return self::singleton()->encode($string); - } - - - - /** - * Compare two strings - * - * @param string $string1 - * @param string $string2 - * @return string - */ - public function compare($string1, $string2) - { - if ($string1 == $string2 || strtolower($string1) === strtolower($string2)) { - return true; - } - if ($this->encode($string1) === $this->encode($string2)) { - return true; - } - return false; - } - - - /** - * Encode a string - * - * @param string $string The string to encode - * @return string - */ - public function encode($string) - { - // First pass: Strip non-alpha - $string = preg_replace('/[^a-zöäüÖÄÜß]/i', '', $string); - // Second pass: Apply conversion-rules - $string = $this->_applyRules($string); - // Third pass: Strip double occurrences - $string = $this->_stripDoubles($string); - // Fourth pass: Strip all zeros except a leading one - $string = $this->_stripZeros($string); - - return $string; - } - - - - /** - * Apply the ruleset for conversion - * - * @param string $string - * @return string - */ - private function _applyRules($string) - { - foreach ($this->_rules as $rule) { - $string = preg_replace($rule[0], $rule[1], $string); - } - return $string; - } - - - /** - * Strip double occurrences of numbers - * - * @param string $string - * @return string - */ - private function _stripDoubles($string) - { - $i = 0; - while ($i <= 9) { - $string = preg_replace('/['.$i.']{2,}/', $i, $string); - $i++; - } - return $string; - } - - - /** - * Strip all zeros except a leading one - * - * @param string $string - * @return string - */ - private function _stripZeros($string) - { - $first = ''; - if ($string[0] === '0') { - $first = '0'; - $string = substr($string, 1); - } - return $first.str_replace('0', '', $string); - } - - - /** - * Protect the constructor - */ - protected function __construct() {} -} -?> \ No newline at end of file diff --git a/public/search/lib/SolrClient2/README.md b/public/search/lib/SolrClient2/README.md deleted file mode 100644 index 50e5bb3a..00000000 --- a/public/search/lib/SolrClient2/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# SolrClient2 - - - - - - - - - - - - - - - -
Getting StartedQueryDocuments
-* [Configuration][conf] - -* [Query][query] - -* [Dokuments][docs] -
-[conf]:doc/conf.md -[query]:doc/query.md -[docs]:doc/docs.md \ No newline at end of file diff --git a/public/search/lib/SolrClient2/composer.json b/public/search/lib/SolrClient2/composer.json deleted file mode 100644 index 7d9bb8f1..00000000 --- a/public/search/lib/SolrClient2/composer.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "arp/solrclient2", - "description": "PHP solr client", - "keywords": ["solr client", "solr"], - "type": "library", - "license": "LGPL", - "authors": [ - { - "name": "A.R.Pour" - } - ], - "require": { - "php": ">=5.3.0" - }, - "config": { - "bin-dir": "bin" - }, - "autoload": { - "psr-0": { - "ARP\\SolrClient2": "lib/" - } - } -} diff --git a/public/search/lib/SolrClient2/doc/conf.md b/public/search/lib/SolrClient2/doc/conf.md deleted file mode 100644 index a8b9019f..00000000 --- a/public/search/lib/SolrClient2/doc/conf.md +++ /dev/null @@ -1,68 +0,0 @@ -# Configuration -* [Simple](#simple) -* [Extended](#extended) - -## Simple -This example ... - -```php -use ARP\SolrClient2\SolrClient; -$client = new SolrClient(); -``` -... is equal to ... - -```php -use ARP\SolrClient2\SolrClient; - -$client = new SolrClient(array( - 'host' => 'localhost', - 'port' => 8080, - 'path' => 'solr', - 'version' => 4 -)); -``` -... or ... - -```php -use ARP\SolrClient2\SolrClient; - -$client = new SolrClient(); -$client ->host('localhost') - ->port(8080) - ->path('solr') - ->version(4); -``` -... or ... -```php -use ARP\SolrClient2\SolrClient; - -... or - -```php -use ARP\SolrClient2\SolrClient; - -$client = new SolrClient("http:\\localhost:8080\solr"); -``` - -## Extended -```php -use ARP\SolrClient2\SolrClient; - -$client = new SolrClient(array( - 'port' => 80, - 'core' => 'core0', - 'params' => array( - 'fq' => 'category:user' - ) -)); -``` -... is equal to ... -```php -use ARP\SolrClient2\SolrClient; - -$client ->port(80) - ->fromCore('core0') - ->params(array( - 'fq' => 'category:user' - )); -``` diff --git a/public/search/lib/SolrClient2/doc/query.md b/public/search/lib/SolrClient2/doc/query.md deleted file mode 100644 index 58deceb0..00000000 --- a/public/search/lib/SolrClient2/doc/query.md +++ /dev/null @@ -1,30 +0,0 @@ -# Query -* [Simple](#simple) -* [Extended](#extended) - -## Simple -This example ... -```php -$result = $client->find(); -``` - -... is equal to ... - -```php -$result = $client ->select('*') - ->limit(20) - ->page(1) - ->exec('*:*'); -``` - -## Extended -```php -$result = $client ->select('*,score') - ->limit(10) - ->page(2) - ->where('document', 'valid') - ->where('user', array('superuser', 'admin')) - ->orderBy('name') - ->facet(array('category')) - ->find(); -``` \ No newline at end of file diff --git a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/CurlBrowser.php b/public/search/lib/SolrClient2/lib/ARP/SolrClient2/CurlBrowser.php deleted file mode 100644 index a609cb4e..00000000 --- a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/CurlBrowser.php +++ /dev/null @@ -1,95 +0,0 @@ -doRequest('GET', $url, array(), null); - } - - public function httpPost($url, array $header, $data) - { - return $this->doRequest('POST', $url, $header, $data); - } - - public function timeout($timeout) - { - $this->timeout = (int)$timeout; - } - - public function proxy($host, $port) - { - if (trim($host) === "" || trim($port) === '') { - return false; - } - - $this->proxy_host = trim($host); - $this->proxy_port = trim($port); - return true; - } - - public function excludeHost($host) - { - if (trim($host) === "") { - return false; - } - - $this->proxy_exclude[] = trim($host); - return true; - } - - private function doRequest($method, $url, array $header, $data) - { - $curlInit = curl_init(); - - $parsed_url = parse_url($url); - - if (isset($parsed_url['scheme']) - && $parsed_url['scheme'] !== 'http' - && $parsed_url['scheme'] !== 'https') { - return false; - } - - if ($method === 'GET') { - curl_setopt($curlInit, CURLOPT_POST, 0); - } elseif ($method === 'POST') { - curl_setopt($curlInit, CURLOPT_POST, 1); - curl_setopt($curlInit, CURLOPT_POSTFIELDS, $data); - } - - curl_setopt($curlInit, CURLOPT_URL, $url); - curl_setopt($curlInit, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curlInit, CURLINFO_HEADER_OUT, true); - curl_setopt($curlInit, CURLOPT_TIMEOUT, $this->timeout); - - if (!empty($header)) { - curl_setopt($curlInit, CURLOPT_HTTPHEADER, $header); - } - - if (!empty($this->proxy_host) && !in_array($parsed_url["host"], $this->proxy_exclude)) { - curl_setopt($curlInit, CURLOPT_PROXY, $this->proxy_host); - curl_setopt($curlInit, CURLOPT_PROXYPORT, $this->proxy_port); - } - - $response = new stdClass(); - $response->content = curl_exec($curlInit); - $response->header = curl_getInfo($curlInit, CURLINFO_HEADER_OUT); - $response->status = (int)curl_getInfo($curlInit, CURLINFO_HTTP_CODE); - $response->contentType = curl_getInfo($curlInit, CURLINFO_CONTENT_TYPE); - $response->error = curl_error($curlInit); - - curl_close($curlInit); - return $response; - } -} diff --git a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/Paging.php b/public/search/lib/SolrClient2/lib/ARP/SolrClient2/Paging.php deleted file mode 100644 index 962bc71e..00000000 --- a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/Paging.php +++ /dev/null @@ -1,82 +0,0 @@ -count = (int)$count; - $this->limit = (int)$limit; - - if (!is_null($page)) { - $this->offset = (int)($page * $limit) - $limit; - } - - elseif (!is_null($offset)) - $this->offset = (int)$offset; - } - - public function length($length) - { - $this->length = (int)$length; - - return $this; - } - - public function calculate() - { - $response = new stdClass(); - - $response->count = $this->count; - $response->offset = $this->offset; - $response->pages = $this->limit > 0 - ? ceil($response->count / $this->limit) - : 0; - $response->currentPage = floor(($response->offset / $this->limit)) + 1; - - if ($response->pages >= 1) { - // INDEX START - if ($response->currentPage > ($this->length / 2)) { - $response->startPage = $response->currentPage - floor($this->length / 2); - } else { - $response->startPage = 1; - } - - // INDEX END - if (($response->startPage + $this->length - 1) > $response->pages - && $response->pages > ($this->length - 1)) { - $response->endPage = ceil($response->pages); - } else { - $response->endPage = $response->startPage + $this->length - 1; - } - - // END OF LIST? - if ($response->endPage - $response->startPage < $this->length) { - $response->startPage = $response->startPage - - ($this->length - ($response->endPage - $response->startPage)); - } - - if ($response->startPage < 1) { - $response->startPage = 1; - } - - if ($response->currentPage < $response->pages) { - $response->nextPage = $response->currentPage + 1; - } - - if ($response->currentPage > 1) { - $response->prevPage = $response->currentPage - 1; - } - } - return $response; - } -} diff --git a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrClient.php b/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrClient.php deleted file mode 100644 index 68b73be1..00000000 --- a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrClient.php +++ /dev/null @@ -1,154 +0,0 @@ -version >= 4) { - $this->fuzzy = '~' . $percent; - } - - return $this; - } - - public function pagingLength($length) - { - $this->pagingLength = (int)$length; - return $this; - } - - public function wordWildcard($wordWildcard) - { - $this->wordWildcard = (boolean)$wordWildcard; - return $this; - } - - public function numericWildcard($numericWildcard) - { - $this->numericWildcard = (boolean)$numericWildcard; - return $this; - } - - public function leftWildcard($leftWildcard) - { - $this->leftWildcard = (boolean)$leftWildcard; - return $this; - } - - public function wildcardMinStrlen($wildcardMinStrlen) - { - $this->wildcardMinStrlen = (int)$wildcardMinStrlen; - return $this; - } - - public function autocomplete($field, $limit = 10, $sort = 'count') - { - $this->autocompleteField = trim($field); - $this->autocompleteLimit = (int)$limit; - $this->autocompleteSort = $sort; - return $this; - } - - public function find($string = '') - { - $this->searchTerms = array_filter(explode(' ', $string)); - - if ($this->autocompleteField !== '') { - $this->params['facet'] = 'on'; - - if (!isset($this->params['facet.field'])) { - $this->params['facet.field'] = array($this->autocompleteField); - } else { - $this->params['facet.field'][] = $this->autocompleteField; - } - - $this->params['f.' . $this->autocompleteField . '.facet.sort'] = $this->autocompleteSort; - $this->params['f.' . $this->autocompleteField . '.facet.limit'] = $this->autocompleteLimit; - $this->params['f.' . $this->autocompleteField . '.facet.prefix'] = end($this->searchTerms); - $this->params['f.' . $this->autocompleteField . '.facet.mincount'] = 1; - } - - $response = $this->exec($this->buildQuery('standardQuery')); - - // PREPAIR PAGING - if (isset($response->count) && isset($response->offset)) { - $paging = new Paging($response->count, $this->params['rows'], null, $response->offset); - - foreach ($paging->calculate() as $key => $val) { - $response->$key = $val; - } - } - - return $response; - } - - private function buildQuery($method, $terms = null) - { - if (is_null($terms)) { - $terms = $this->searchTerms; - } - - if (count($terms) !== 0) { - array_walk($terms, 'self::' . $method); - return implode(' ', $terms); - } - - return null; - } - - private function standardQuery(&$term) - { - $rawTerm = trim($term); - - // NORMAL - $term = $this->escape($rawTerm) . '^1'; - - // WILDCARD - if ((is_numeric($rawTerm) && $this->numericWildcard) - || (!is_numeric($rawTerm) && $this->wordWildcard) - && strlen($rawTerm) >= $this->wildcardMinStrlen) { - - $term .= ' OR ' - . ($this->leftWildcard ? '*' : '') - . $this->escape($rawTerm) - . '*^0.6'; - } - - // FUZZY - if (!empty($this->fuzzy) - && strlen($rawTerm) >= $this->wildcardMinStrlen - && !is_numeric($rawTerm)) { - - $term .= ' OR ' - . $this->escape($rawTerm) - . $this->fuzzy - . '^0.3'; - } - - $term = '(' . $term . ')'; - } -} diff --git a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrCore.php b/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrCore.php deleted file mode 100644 index d1ed7ccb..00000000 --- a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrCore.php +++ /dev/null @@ -1,264 +0,0 @@ -options($options); - } - - public function options($options) - { - if (is_string($options)) { - $options = parse_url($options); - $path = array_filter(explode('/', $options['path'])); - if (count($path) === 2) { - $options['core'] = array_pop($path); - $options['path'] = array_pop($path); - } - } - - $this->host = isset($options['host']) ? $options['host'] : 'localhost'; - $this->port = isset($options['port']) ? $options['port'] : 8080; - $this->path = isset($options['path']) ? $options['path'] : 'solr'; - $this->core = isset($options['core']) ? $options['core'] : ''; - $this->version = isset($options['version']) ? (int)$options['version'] : 4; - - $this->params = array( - 'fl' => '*', - 'wt' => 'json', - 'json.nl' => 'map', - 'start' => 0, - 'rows' => 20, - 'q' => '*:*' - ); - - if (isset($options['params'])) { - $this->params = $this->mergeRecursive($this->params, $options['params']); - } - - return $this; - } - - public function host($host) - { - $this->host = $host; - return $this; - } - - public function port($port) - { - $this->port = $port; - return $this; - } - - public function path($path) - { - $this->path = $path; - return $this; - } - - public function core($core) - { - $this->core = $core; - return $this; - } - - /** - * @deprecated - * @param string $core - * @return SolrCore - */ - public function fromCore($core) - { - trigger_error("Method 'fromCore' is deprecated use 'core' instead.", E_USER_DEPRECATED); - return $this->core($core); - } - - public function version($version) - { - $this->version = $version; - return $this; - } - - public function params(array $params) - { - $this->params = $params; - return $this; - } - - public function cacheSize($size) - { - $this->cacheSize = (int)$size; - return $this; - } - - public function newDocument() - { - return new SolrDocument(); - } - - public function addDocument(SolrDocument $document) - { - $this->jsonUpdate($document->toJson()); - return $this; - } - - public function addDocuments($documents) - { - $json = ''; - - foreach ($documents as $document) { - $json .= substr($document->toJson(), 1, -1) . ','; - } - - $this->jsonUpdate('{' . substr($json, 0, -1) . '}'); - return $this; - } - - public function appendDocument(SolrDocument $document) - { - $this->cache .= substr($document->toJson(), 1, -1) . ','; - if (strlen($this->cache) >= $this->cacheSize) { - return $this->commitCachedDocuments(); - } - return $this; - } - - public function deleteByQuery($query) - { - $this->jsonUpdate('{"delete": { "query":"' . $query . '" }}'); - return $this; - } - - public function deleteAll() - { - $this->deleteByQuery('*:*'); - return $this; - } - - public function commit() - { - $this->commitCachedDocuments(); - $this->jsonUpdate('{"commit": {}}'); - return $this; - } - - public function optimize($waitSearcher = false) - { - $this->jsonUpdate('{"optimize": {"waitSearcher":' . $waitSearcher ? 'true' : 'false' . '}}', false); - return $this; - } - - public function queryInfo() - { - return urldecode($this->content) . - '
' . print_r($this->params, true) . '
'; - } - - protected function solrSelect($params) - { - $this->content = http_build_query($params); - $this->content = preg_replace('/%5B([\d]{1,2})%5D=/', '=', $this->content); - - $response = $this->httpPost( - $this->generateURL('select'), - array('Content-type: application/x-www-form-urlencoded'), - $this->content - ); - - if ($response->status !== 200) { - throw new RuntimeException("\nStatus: $response->status\nContent: $response->content"); - } - - return $response; - } - - protected function mergeRecursive($arr1, $arr2) - { - foreach (array_keys($arr2) as $key) { - if (isset($arr1[$key]) && is_array($arr1[$key]) && is_array($arr2[$key])) { - $arr1[$key] = $this->mergeRecursive($arr1[$key], $arr2[$key]); - } else { - $arr1[$key] = $arr2[$key]; - } - } - return $arr1; - } - - protected function appendToFilter($string, $cached = true) - { - if (!$cached) { - $string = '{!cache=false}' . $string; - } - - if (!isset($this->params['fq'])) { - $this->params['fq'] = array($string); - } else { - $this->params['fq'][] = $string; - } - } - - private function generateURL($path = '') - { - return 'http://' - . $this->host - . ($this->port === null ? '' : ':' . $this->port) - . ($this->path === null ? '' : '/' . $this->path) - . ($this->core === null ? '' : '/' . $this->core) - . ($path == '' ? '' : '/' . $path); - } - - private function jsonUpdate($content, $checkStatus = true) - { - if ($this->version == 4) { - $url = $this->generateURL('update'); - } else { - $url = $this->generateURL('update/json'); - } - - $response = $this->httpPost( - $url, - array('Content-type: application/json'), - $content - ); - - if ($checkStatus && $response->status !== 200) { - throw new RuntimeException("\nStatus: $response->status\nContent: $response->content"); - } - - return $response; - } - - private function commitCachedDocuments() - { - if (strlen($this->cache) > 1) { - $response = $this->jsonUpdate('{' . substr($this->cache, 0, -1) . '}'); - $this->cache = ''; - return $response; - } - return null; - } -} diff --git a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrDocument.php b/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrDocument.php deleted file mode 100644 index e73b5106..00000000 --- a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrDocument.php +++ /dev/null @@ -1,114 +0,0 @@ -_doc['commitWithin'] = 0; - /* - Not implemented - allowDups - overwritePending - overwriteCommitted - */ - } - - /** - * Document boost - * @param float $boost - */ - public function setBoost($boost) - { - $this->_doc['boost'] = (float)$boost; - } - - /** - * Field boost - * @param string $field - * @param float $boost - */ - public function setFieldBoost($field, $boost) - { - if (isset($this->_doc['doc'][$field])) { - if (is_array($this->_doc['doc'][$field]) && isset($this->_doc['doc'][$field]['boost'])) { - $this->_doc['doc'][$field]['boost'] = (float)$boost; - } else { - $this->_doc['doc'][$field] = array( - 'boost' => (float)$boost, - 'value' => $this->_doc['doc'][$field] - ); - } - } - } - - /** - * Add field - * @param string $field field - * @param string $value value - * @param float $boost field boost - */ - public function add($field, $value, $boost = false) - { - if ($boost) { - $this->_doc['doc'][$field] = array( - 'boost' => (float)$boost, - 'value' => $value - ); - } else { - $this->_doc['doc'][$field] = $value; - } - } - - /** - * Solr json update string - * @return string json update string - */ - public function toJson() - { - return json_encode(array( - 'add' => $this->_doc - )); - } - - // TODO: parseDate in eine andere Datei verlagern. - public function solrDate($date = null) - { - $return = ''; - $dateObj = null; - - if (is_string($date) && preg_match('/[\d]{4}\-[\d]{2}\-[\d]{2}/', $date)) { - $dateObj = new DateTime($date); - } else { - $dateObj = new DateTime(); - } - - if (is_object($dateObj)) { - $return = $dateObj->format('Y-m-d\TH:i:s\Z'); - } - - return $return; - } - - public function __get($field) - { - if (isset($this->_doc['doc'][$field])) { - if (is_array($this->_doc['doc'][$field]) && isset($this->_doc['doc'][$field]['value'])) { - return $this->_doc['doc'][$field]['value']; - } - return $this->_doc['doc'][$field]; - } - return null; - } - - public function __set($field, $value) - { - $this->add($field, $value); - } -} diff --git a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrQuery.php b/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrQuery.php deleted file mode 100644 index 00edcec6..00000000 --- a/public/search/lib/SolrClient2/lib/ARP/SolrClient2/SolrQuery.php +++ /dev/null @@ -1,247 +0,0 @@ -params = $this->mergeRecursive($this->params, $params); - - if (!is_null($hits)) { - $this->params['rows'] = (int)$hits; - } - if (!empty($query)) { - $this->params['q'] = $query; - } - if (!is_null($page)) { - $this->page($page); - } - - // calculate offset - if ($this->params['start'] === 0 && $this->page > 1) { - $this->offset(($this->page * $this->params['rows']) - $this->params['rows']); - } - - $response = $this->solrSelect($this->params); - - $content = json_decode($response->content); - - unset($response); - - /*********************************************************************** - * PREPAIR SOLR SEARCH RESULT - ***********************************************************************/ - $result = new stdClass(); - - if (isset($content->response->numFound)) { - $result->count = $content->response->numFound; - } - - if (isset($content->response->start)) { - $result->offset = $content->response->start; - } - - if (isset($content->response->docs) && !empty($content->response->docs)) { - $result->documents = $content->response->docs; - } - - if (isset($content->facet_counts->facet_fields)) { - foreach ($content->facet_counts->facet_fields as $key => $val) { - if ($this->autocompleteField === $key) { - $result->autocomplete = (array)$val; - } else { - $result->facets[$key] = (array)$val; - } - } - } - - return $result; - } - - /** - * Enable debug query - * @param boolean $debug - */ - public function debug($debug) - { - if ($debug) { - $this->params['deubgQuery'] = 'true'; - } elseif (isset($this->params['deubgQuery'])) { - unset($this->params['deubgQuery']); - } - - return $this; - } - - /** - * Set result page - * @param integer $page Result page - */ - public function page($page) - { - $this->page = (int)$page > 0 ? (int)$page : 1; - return $this; - } - - /** - * Set start offset. - * @param integer $offset Start position. - */ - public function offset($offset) - { - $this->params['start'] = (int)$offset; - return $this; - } - - /** - * Set result limit. - * @param integer $limit Result limit. - */ - public function limit($limit) - { - $this->params['rows'] = (int)$limit; - return $this; - } - - /** - * Select result fields. - * @param string $select Fields - */ - public function select($select) - { - $this->params['fl'] = $select; - return $this; - } - // TODO: REMOVE DEFAULT OPERATOR - public function where($key, $value = null, $cached = true, $innerOperator = 'OR') - { - $tmp = ""; - - // many fields ... - if (is_array($key) && is_null($value)) { - foreach ($key as $k => $v) { - // ... and many values - if (is_string($k) && is_array($v)) { - foreach ($v as $val) { - $tmp .= ' ' . $innerOperator . ' ' . $k . ':"' . $this->escapePhrase($val) . '"'; - } - - // ... one value - } elseif (is_string($k)) { - $tmp .= ' ' . $innerOperator . ' ' . $k . ':"' . $this->escapePhrase((string)$v) . '"'; - } - } - - if ($tmp !== "") { - $this->appendToFilter(trim(substr($tmp, 4)), $cached); - } - - // one field and many values - } elseif (is_string($key) && is_array($value)) { - foreach ($value as $val) { - $tmp .= ' ' . $innerOperator . ' ' . $key . ':"' . $this->escapePhrase($val) . '"'; - } - - $this->appendToFilter(trim(substr($tmp, 4)), $cached); - - // one field an one value - } elseif (is_string($key) && !is_null($value)) { - $this->appendToFilter($key . ':"' . $this->escapePhrase((string)$value) . '"', $cached); - - // raw filterquery - } elseif (is_string($key)) { - $this->appendToFilter($key, $cached); - } - - return $this; - } - - public function orderBy($sort, $direction = 'asc') - { - $this->params['sort'] = $sort . ' ' . $direction; - return $this; - } - - /** - * Queryparser. - * @param string $queryParser Queryparser - */ - public function queryParser($queryParser) - { - $this->params['defType'] = $queryParser; - return $this; - } - - /** - * Faceting - * @param mixed $fields Fields - * @param integer $mincount Returns only fileds more than mincount. - * @param string $sort Fields. - * http://wiki.apache.org/solr/SimpleFacetParameters - */ - public function facet($fields, $mincount = 1, $sort = 'index') - { - if (is_string($fields)) { - $fields = array($fields); - } - - $this->params['facet'] = 'on'; - $this->params['facet.field'] = $fields; - $this->params['facet.mincount'] = $mincount; - $this->params['facet.sort'] = $sort; - return $this; - } - - /** - * Escape searchstring. - * @param string $string Searchstring. - * @return string Escaped searchstring. - */ - public function escape($string) - { - return preg_replace( - '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\/|\\\)/', - '\\\$1', - $string - ); - } - - /** - * Escape search phrase. - * @param string $string Phrase string. - * @return string Escaped phrase. - */ - public function escapePhrase($string) - { - return preg_replace( - '/("|\\\)/', - '\\\$1', - $string - ); - } -} diff --git a/public/search/server.php b/public/search/server.php deleted file mode 100755 index 6052d4c2..00000000 --- a/public/search/server.php +++ /dev/null @@ -1,72 +0,0 @@ -find( - isset($_GET["searchtext"]) ? $_GET["searchtext"] : "*" -); - -$backend = isset($_GET["backend"]) && strtolower($_GET["backend"]) === 'true'; - -$resultJson = array("result" => "", "array" => array()); - -function generateHtml($href, $name, $type, $title, $backend) { - $class = $backend ? "resultElement" : "result-element"; - return '
 ' . $title . '' . $type . '
'; -} - -function generateJson($bbox_array, $type, $title) { - return array( - "label" => $title, - "bbox" => $bbox_array - ); -} - -foreach ($result->documents as $doc) { - $data = json_decode($doc->json, true); - $type = strtolower($data["type"]); - - $bbox_array = array(); - if (substr($data['geom'], 0, 3) == "BOX") { - foreach (explode(",", substr($data['geom'], 4, -1)) AS $i) { - foreach (explode(" ", $i) AS $j) { - $bbox_array[] = $j; - } - } - } - - if ($type === "ort") { - $title = $data['ort_name']; - } elseif ($type === "ortsteil") { - $title = $data['stadtteil_name']; - } elseif ($type === "straße") { - $title = $data['strasse_name'] . " " . $data["zusatz"];; - } elseif ($type === "adresse") { - $title = $data["strasse"] . " " . $data["hausnummer"] . $data["hausnummerzusatz"] . " " . $data["zusatz"]; - } elseif ($type === "poi") { - $title = $data['poi_titel']; - } else { - $title = ""; - } - - $bbox_string = implode(",", $bbox_array); - if ($backend) { - $href = 'javascript:map.zoomToExtent(new OpenLayers.Bounds(' . $bbox_string . '));'; - } else { - $href = URL . '?BBOX=' . $bbox_string; - } - - $resultJson["result"] .= generateHtml($href, $bbox_string, $data["type"], $title, $backend); - $resultJson["array"][] = generateJson($bbox_array, $data["type"], $title); -} - -header('Content-Type: application/json'); -echo json_encode($resultJson); - -?> diff --git a/public/search/updateIndex.php b/public/search/updateIndex.php deleted file mode 100644 index 2cc57bff..00000000 --- a/public/search/updateIndex.php +++ /dev/null @@ -1,119 +0,0 @@ -openIndex(); - -echo "
\nclear index.\n"; -$conn = pg_connect("host=" . HOST . " port=" . PORT . " dbname=" . NAME . " user=" . USER . " password=" . PASS . ""); -if (!$conn) die("Error: pg_connect!"); -echo "
connect ok"; - -/* * ********************************************************************* - * O R T S T E I L S E A R C H - * ********************************************************************* */ -$sql = "SELECT ot.id AS id,ot.stadtteil_name AS stadtteil_name,box2d(ot.geom) AS bbox" - . ",st_dimension(ot.geom) AS dimension FROM " . SCHEMA . ".standortsuche ot WHERE ot.stadtteil_name IS NOT NULL;"; -$result = pg_query($conn, $sql); -$num = 0; -while ($row = pg_fetch_assoc($result)) { - if ($row["bbox"] === null) { - continue; - } - if ($row["dimension"] == 0 AND strpos($row["bbox"], "BOX") === 0) { - $tmp = split(",", substr($row["bbox"], 4, -1)); - $row["geom"] = "BOX(" . $tmp[0] . "," . $tmp[0] . ")"; - } else { - $row["geom"] = $row["bbox"]; - } - $search->updateIndex( - $row["stadtteil_name"], - array( - "type" => "Ortsteil", - "stadtteil_name" => $row["stadtteil_name"], - "geom" => $row["geom"] - ) - ); - $num++; -} - -echo "

Tables :" . SCHEMA . "standortsuche"; -echo "
Rows all :" . pg_num_rows($result); -echo "
Rows accepted :" . $num; -echo "
Last error : " . pg_last_error(); -/* * ********************************************************************* - * S T R A S S E S E A R C H - * ********************************************************************* */ -$sql = "SELECT s.id, s.strasse_name, s.zusatz" - . ",box2d(s.geom) AS bbox, st_dimension(s.geom) AS dimension FROM " . SCHEMA . ".standortsuche s WHERE s.strasse_name IS NOT NULL"; -$result = pg_query($conn, $sql); -$num = 0; -while ($row = pg_fetch_assoc($result)) { - if ($row["bbox"] === null) { - continue; - } - if ($row["dimension"] == 0 AND strpos($row["bbox"], "BOX") === 0) { - $tmp = split(",", substr($row["bbox"], 4, -1)); - $row["geom"] = "BOX(" . $tmp[0] . "," . $tmp[0] . ")"; - } else { - $row["geom"] = $row["bbox"]; - } - $search->updateIndex( - $row["strasse_name"], - array( - "type" => "Straße", - "strasse_name" => $row["strasse_name"], - "zusatz" => $row["zusatz"], - "geom" => $row["geom"] - ) - ); - $num++; -} - -echo "

Tables :" . SCHEMA . ".standortsuche"; -echo "
Rows all :" . pg_num_rows($result); -echo "
Rows accepted :" . $num; -echo "
Last error : " . pg_last_error(); -/* * ********************************************************************* - * A D R E S S E S E A R C H - * ********************************************************************* */ -$sql = "SELECT a.id, a.strasse, a.hausnummer, a.hausnummerzusatz, a.zusatz" - . ",box2d(a.geom) AS bbox, st_dimension(a.geom) AS dimension" - . " FROM " . SCHEMA . ".standortsuche a WHERE a.hausnummer IS NOT NULL"; -$result = pg_query($conn, $sql); -$num = 0; -while ($row = pg_fetch_assoc($result)) { - if ($row["bbox"] === null) { - continue; - } - if ($row["dimension"] == 0 AND strpos($row["bbox"], "BOX") === 0) { - $tmp = split(",", substr($row["bbox"], 4, -1)); - $row["geom"] = "BOX(" . $tmp[0] . "," . $tmp[0] . ")"; - } else { - $row["geom"] = $row["bbox"]; - } - $search->updateIndex( - $row["strasse"] . " " . $row["hausnummer"] . $row["hausnummerzusatz"], - array( - "type" => "Adresse", - "strasse" => $row["strasse"], - "hausnummer" => $row["hausnummer"], - "hausnummerzusatz" => $row["hausnummerzusatz"], - "zusatz" => $row["zusatz"], - "geom" => $row["geom"] - ) - ); - $num++; -} - -echo "

Tables :" . SCHEMA . ".standortsuche"; -echo "
Rows all :" . pg_num_rows($result); -echo "
Rows accepted :" . $num; -echo "
Last error : " . pg_last_error(); - - -$search->closeIndex();