The search plugin aim is to offer standards search features (like recentering, result offset, guided search, ajax features...) in a generic way. Take note that in his current state the plugin only offers a server framework. There is not yet any generic JavaScript framework.
Warning
The following examples only work with AJAX mode on !
Introduction
The search plugin must be activated on both CartoClient and CartoServer side ie. the loadPlugins
parameter must contain search
in your project client_conf/client.ini
and server_conf/<mapId>/<mapId>.ini
.
Search use is mainly based on three files. client_conf/search.ini
, plugins/search/htdocs/js/Search.ajax.js
and plugins/search/templates/search.tpl
.
The search plugin uses the PEAR DB abstraction class and should be able to handle all databases supported by PEAR DB.
The data set and the query specification are set in the search.ini
file. The design and the fields of the search form is set in the search.tpl
file. The search behavior mainly reside in the Search.ajax.js.
Let's imagine that we want to do a search with a recenter on data that are represented on a layer Addresses. The source of the data is a table in a PostGIS database.
The data are stored in a table "addresses" with the followings rows: num, street, zipcode, town, gid and the_geom. Primary key is gid.
First we have to set the configuration in the client_conf/client.ini/search.ini
like this:
dsn = SEARCHDSN encodingContext = myencoding_context ; Do not forget to add EncoderClass.myencoding_context = EncoderISO (or any other context) ; in your client_conf/client.ini config.Adresses.provider.type = fulltextTable config.Adresses.provider.table = addresses config.Adresses.provider.aliases = adr_num, num, adr_street, street, adr_zip, zipcode, adr_town, town config.Adresses.provider.id = gid config.Adresses.provider.columns = adr_num, adr_street, adr_zip, adr_town, config.Adresses.provider.fulltextColumns = adr_num, adr_street, adr_zip, adr_town config.Adresses.provider.sortColumn = adr_num config.Adresses.provider.sortDirection = asc config.Adresses.provider.sortPriorities = adr_num, adr_street, adr_zip, adr_town config.Adresses.provider.labels = adr_num, adr_street, adr_zip, adr_town config.Adresses.formatter.type = smarty config.Adresses.formatter.template = search_results
- The dsn correspond to your dsn dataBase connexion string. For more information please see the php PEAR corresponding page
-
The encodingContext correspond to the context in your
client_conf/client.ini
see below code - The config.XXXX is used for making a differentiation on tables.
- The config.Adresses.provider.type defines the type of query that should be done on the table. Value can be :
- fulltextTable: That means the search is a textual search (ilike clause) that will be done on the fields listed in the config.Adresses.provider.fulltextColumns.
- table: In this case a where clause should be set. (see Section 24.3.1.1, “Guided Search”)
- user-defined (see <a class="xref" h