Datasource Searcher - Septima/spatialsuite-s4 GitHub Wiki

The Datasource Searcher allows the user to search datasources.

  • The search is done in real time and therefore reflects the current contents of the database.
  • This is different from searching an index which reflects the contents of the database at the time of indexing.

Therefore: If you have real-time needs and yor database is sufficiently fast in searching you may use the Datasource Searcher.

Datasource requirements

The datasource to search MUST have the following command: read_search.

  • The read_search command MUST return the following fields:
  • heading, which is use as title in the search result
  • The read_search command MAY return the following fields:
  • description
  • url
  • shape_wkt, wkt representation of the geometry.
  • The command will be called with two url-parameters
  • query, the query string
  • limit, the maximum number of rows to return

Example of datasource and command:

<datasource endpoint="ep_kbh" name="ds_park_monumenter">
    <table geometrycolumn="wkb_geometry"  name="park.monumenter" pkcolumn="ogc_fid"/>
	<sql command="read_search">
		select
		distinct navn as heading,
		'http://www.kk.dk/monumentbasen.aspx?&amp;id=' || web_id:: character varying as url,
		astext(wkb_geometry) as shape_wkt
		from park.monumenter
		where navn ilike '[query]%'
		order by navn
		limit [limit];
	</sql>
</datasource>       

Searcher options

The Datasource Searcher accepts the following options:

  • datasource, mandatory
  • onSelect, mandatory. Function to call when a result is selected (function OnSelect(result))
  • matchesPhrase, optional
  • hyperLinkLabel, optional
  • iconUrl, optional

Example of usage of Datasource Searcher:

<?xml version="1.0" encoding="UTF-8"?> 
<tool type="plugin">
    <requires>
	    [if: ModuleDefined("s4") ] // Don't do anything if s4 is not installed
	    	<include src="[module:s4.dir]/tools/s4-requires.xml" nodes="/tool/requires/*" mustexist="true"/>
		[endif]
   </requires>
    <src/>
    <jssrc><![CDATA[
	    [if: ModuleDefined("s4") ]
            var _s4Searchers = _s4Searchers || [];
            var options = {
                datasource: "ds_park_monumenter",    // Obligatorisk
                onSelect: s4Hit,                     // valgfri. Angiv egen funktion eller brug den indbyggede (s4Hit(result))
                source: "Monumenter",    // Obligatorisk
                type: "Monumenter",    // Obligatorisk
                matchesPhrase: "matcher",            // Valgfri. Angiv et ord
                hyperLinkLabel: "Læs om monumentet", // Valgfri. Angiv en henvisningstekst
                iconUrl: "data:image/gif;base64,R0lGODlhGQAZAMZQAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCw0NDRERERQUFBUVFRgYGBoaGh0dHR4eHiAgICkpKTQ0NDc3Nzg4ODk5OTo6Ojs7Ozw8PExMTFJSUllZWVxcXF1dXV9fX2FhYWJiYmNjY2RkZGVlZWZmZmdnZ21tbW5ubm9vb3FxcXJycnNzc3Z2dnl5eXp6eoCAgIGBgYaGhpGRkZiYmJmZmaOjo6WlpampqaysrK+vr7Gxsbi4uMDAwMLCwsXFxcrKysvLy8zMzM/Pz9TU1NXV1dbW1tfX1+Hh4eLi4uXl5fPz8/7+/v///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEKAH8ALAAAAAAZABkAAAe7gH+Cg4SFhoeIiYqHTU6LikszDRc5j4geAAIAAD6WhUgWmwUAOp6ERxUDmwA4poNFEQAEAAM2roJEEKsCNbd/Qw6bAQAvvkIMqpsqvkEEmpoovkDJmyK+PwPZmx9Ptz3Dqx2+SiIpJykkN648GhsZFxocGRgZNJ48CQ8TFBQTEhMFYFjCEQPECBMlSIwgUSLEixpJFDFpYGCBAgQHECRAYGCjgB2LZLBo4aKkixcvSrJYYcSXy5cwYxYKBAA7"
			};
           	_s4Searchers.push({
           		searcher : new Septima.Search.DatasourceSearcher(options),
           		info: true                          //Valgfri. Angiver om, der skal kunne søges info p� objektet
           	});
		[endif]
    ]]>
    </jssrc>
</tool>

Read about the s4 API (s4Hit, _s4Searchers, _s4OnSelect) Here

⚠️ **GitHub.com Fallback** ⚠️