Changes between Initial Version and Version 1 of DocManualsearchFive


Ignore:
Timestamp:
Nov 21, 2014, 10:31:13 AM (4 years ago)
Author:
raffaele
Comment:

the first c/p from version4

Legend:

Unmodified
Added
Removed
Modified
  • DocManualsearchFive

    v1 v1  
     1[DocManualFive >> Back to manual ] 
     2 
     3= Attribute search = 
     4Define attribute search via /config/.../search.xml 
     5 
     6{{{ 
     7<searchlist version="1.0"> 
     8 
     9    <searchitem name="cities" description="City"> 
     10        <layer type="shape" name="cities"> 
     11            <field type="s" name="CITY_NAME" description="City"  wildcard="0" /> 
     12        </layer> 
     13    </searchitem>   
     14  
     15</searchlist>  
     16 
     17}}} 
     18 
     19Create new <searchitem> for every layer you want to search.  
     20 
     21Parameters: 
     22{{{ 
     23<searchitem> 
     24  name: unique identifier, typically the same as layer name 
     25  description: name visible in GUI 
     26}}} 
     27 
     28{{{ 
     29<layer>  
     30  type: data source type; possible values: "shape", "postgis", "xy", "oracle"   
     31  name: layer name in map file 
     32}}} 
     33 
     34{{{   
     35<field> 
     36  type: "s" for string field, "n" for numeric field 
     37  name: field name in dataset 
     38  description: name visible in GUI 
     39  wildcard: "0": search always uses a 'non-exact' pattern matching;  
     40            "1": requires that the user explicitly adds "*" for wildcards to his search string  
     41            "2": exact search, usually just appropriate for 'suggest' or 'options' 
     42}}} 
     43 
     44Pmapper version 3.2 supports extended definition of attribute search. The possibilities are described and restricted by the schema definition file search.xsd. This file can be found in the map \incphp\query\.   
     45 
     46An XML schema file for validating the search.xml is available [http://svn.pmapper.net/trac/browser/pmapper/trunk/incphp/query/search.xsd here]. It can also be used to facilitate the creation of the XML file using a more advanced XML editor tools like the [http://www.eclipse.org Eclipse] framework. 
     47 
     48In the Pmapper dev delivery is a sample search.xml in the map \config\dev. In this sample searchitems are defined with extended functionality, as suggest lists, option lists, and even the use of two search fields that depend on each other (like a suggest list that responds on a option list). There are sample searchitem definitions for use with shape files, db connections and Postgres databases. 
     49 
     50A sample using these extended functionality on shape and Postgres layers: 
     51 
     52{{{ 
     53<?xml version="1.0" ?>  
     54<!--  <?xml-stylesheet href="style.xsl" type="text/xsl" ?>   -->  
     55<searchlist version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="search.xsd"> 
     56  <dataroot>$</dataroot>  
     57    <searchitem name="cities" description="City"> 
     58        <layer type="shape" name="cities10000eu"> 
     59            <field type="s" name="NAME" description="City" wildcard="0" />  
     60        </layer> 
     61    </searchitem> 
     62    <searchitem name="countries" description="Country"> 
     63        <layer type="shape" name="countries"> 
     64            <field type="s" name="ISO2_CODE" description="Country" wildcard="2"> 
     65                <definition type="options" connectiontype="ms" sort="asc" firstoption="*"> 
     66                    <mslayer encoding="ISO-8859-1" keyfield="ISO2_CODE" showfield="NAME" />  
     67                </definition> 
     68            </field> 
     69        </layer> 
     70  </searchitem> 
     71 
     72  <!--  Sample for suggest function -->  
     73 
     74 
     75    <searchitem name="cities_suggest_pg" description="Cities Suggest PG"> 
     76        <layer type="postgis" name="cities10000eu_pg"> 
     77            <field type="s" name="name" description="City" wildcard="2"> 
     78                <definition type="suggest" connectiontype="db" sort="asc" minlength="1" dependfld="cmcncd"> 
     79                    <dsn encoding="UTF-8">pgsql://postgres:postgres@localhost/gisdb</dsn> 
     80                    <sql>SELECT DISTINCT name FROM cities1000 WHERE population > 10000 AND name ~* '^[search]' ORDER BY name</sql> 
     81                    </definition>  
     82            </field>  
     83        </layer> 
     84    </searchitem> 
     85     
     86 
     87 
     88    <searchitem name="cities_suggest_dbf" description="Cities Suggest"> 
     89        <layer type="shape" name="cities10000eu"> 
     90            <field type="s" name="NAME" description="Citt&agrave;à" wildcard="2"> 
     91                <definition type="suggest" connectiontype="dbase" minlength="1" startleft="1" sort="asc"> 
     92                    <dbasefile encoding="UTF-8" searchfield="NAME">$/cities10000eu.dbf</dbasefile>  
     93                </definition> 
     94            </field> 
     95        </layer> 
     96    </searchitem> 
     97    <searchitem name="cities_hidden_suggest_dbf" description="Cities Hidden Suggest DBF"> 
     98        <layer type="shape" name="cities10000eu"> 
     99            <field type="s" name="ISO2_CODE" description="Country" wildcard="0"> 
     100                <definition type="hidden" connectiontype="session" value="gLanguage"/> 
     101            </field> 
     102            <field type="s" name="NAME" description="City" wildcard="2"> 
     103                <definition type="suggest" connectiontype="dbase" minlength="1" startleft="1" dependfld="ISO2_CODE"> 
     104                    <dbasefile encoding="UTF-8" searchfield="NAME">$/cities10000eu.dbf</dbasefile> 
     105                </definition>  
     106            </field>  
     107        </layer> 
     108    </searchitem> 
     109     
     110 
     111 
     112    <searchitem name="cities_options_suggest_dbf" description="Cities Options Suggest"> 
     113        <layer type="shape" name="cities10000eu"> 
     114            <field type="s" name="ISO2_CODE" description="Country" wildcard="2"> 
     115                <definition type="options" connectiontype="dbase" sort="asc" firstoption="*"> 
     116                    <dbasefile encoding="UTF-8" keyfield="ISO2_CODE" showfield="NAME">$/countries.dbf</dbasefile>  
     117                    <events>onchange="resetSuggestCache();$('#pmsfld_NAME').val('')"</events>  
     118                </definition> 
     119            </field> 
     120            <field type="s" name="NAME" description="City" wildcard="2"> 
     121                <definition type="suggest" connectiontype="dbase" minlength="1" startleft="1" dependfld="ISO2_CODE"> 
     122                    <dbasefile encoding="UTF-8" searchfield="NAME">$/cities10000eu.dbf</dbasefile>  
     123                </definition> 
     124            </field> 
     125        </layer> 
     126    </searchitem> 
     127     
     128    <searchitem name="cities_options_suggest_pg" description="Communes Suggest PG"> 
     129        <layer type="postgis" name="cmeu01"> 
     130            <field type="s" name="cmcncd" description="Country" wildcard="2"> 
     131                <definition type="options" connectiontype="db" sort="asc"> 
     132                    <dsn encoding="UTF-8">pgsql://postgres:postgres@localhost/gisdb</dsn> 
     133                      <!--  Attention! Two fields to fill the options list: in this case: --> 
     134                      <!--  cnty_id is the bound value for dependfldval, name_en is the display value in the option list-->  
     135                    <sql>SELECT DISTINCT cnty_id, name_en FROM countries WHERE name_en IS NOT NULL ORDER BY name_en</sql> 
     136                    <events>onchange="resetSuggestCache();$('#pmsfld_CITY_NAME').val('')"</events> 
     137                </definition> 
     138            </field> 
     139            <field type="s" name="cmsbname" description="Name" wildcard="2"> 
     140                <definition type="suggest" connectiontype="db" sort="asc" minlength="3" dependfld="cmcncd"> 
     141                    <dsn encoding="UTF-8">pgsql://postgres:postgres@localhost/gisdb</dsn> 
     142                    <sql>SELECT DISTINCT cmsbname FROM cmeu01 WHERE cmsbname ~* '^[search]' {and cmcncd = '[dependfldval]'} ORDER BY cmsbname</sql> 
     143                </definition> 
     144            </field>  
     145        </layer> 
     146    </searchitem> 
     147     
     148     
     149    <searchitem name="cities_suggest_ms" description="Cities Suggest MS"> 
     150        <layer type="shape" name="cities10000eu"> 
     151            <field type="s" name="NAME" description="City" wildcard="2"> 
     152                <definition type="suggest" connectiontype="ms" minlength="2" startleft="0" sort="asc"> 
     153                    <mslayer encoding="UTF-8"/> 
     154                </definition> 
     155            </field>  
     156        </layer> 
     157    </searchitem> 
     158     
     159     
     160    <searchitem name="cities_options_suggest_ms" description="Cities Options Suggest MS"> 
     161        <layer type="shape" name="cities10000eu"> 
     162            <field type="s" name="ISO2_CODE" description="Country" wildcard="2"> 
     163                <definition type="options" connectiontype="dbase" sort="asc" firstoption="pippo"> 
     164                    <dbasefile encoding="UTF-8" keyfield="ISO2_CODE" showfield="NAME">$/countries.dbf</dbasefile> 
     165                    <events>onchange="resetSuggestCache();$('#pmsfld_NAME').val('')"</events> 
     166                </definition> 
     167            </field> 
     168            <field type="s" name="NAME" description="City" wildcard="2"> 
     169                <definition type="suggest" connectiontype="ms" minlength="1" startleft="1" sort="asc" dependfld="ISO2_CODE"> 
     170                    <mslayer encoding="UTF-8"/> 
     171                </definition> 
     172            </field>  
     173        </layer> 
     174    </searchitem> 
     175     
     176 
     177     
     178    <searchitem name="cities_population_1_operator" description="Cities population"> 
     179        <layer type="shape" name="cities10000eu"> 
     180            <field type="n" name="POPULATION" description="Cities with Population"> 
     181                <definition type="operator"> 
     182                    <option name=">" value=">" />  
     183                    <option name="=" value="=" />  
     184                    <option name="<" value="<" />  
     185                </definition> 
     186            </field> 
     187        </layer> 
     188    </searchitem> 
     189 
     190    <searchitem name="cities_population_2_operator" description="Cities population 2"> 
     191        <layer type="shape" name="cities10000eu"> 
     192            <field type="n" name="POPULATION" alias="POPULATION1" description="Cities with Population"> 
     193                <definition type="operator"> 
     194                    <option name="&gt;" value="&gt;"/> 
     195                    <option name="=" value="="/> 
     196                    <option name="&lt;" value="&lt;"/> 
     197                </definition> 
     198            </field> 
     199            <field type="n" name="POPULATION" alias="POPULATION2" description="and population"> 
     200                <definition type="operator"> 
     201                    <option name="&gt;" value="&gt;"/> 
     202                    <option name="=" value="="/> 
     203                    <option name="&lt;" value="&lt;"/> 
     204                </definition> 
     205            </field> 
     206        </layer> 
     207    </searchitem> 
     208     
     209</searchlist> 
     210}}} 
     211 
     212See also the sample using xy-layers with a database (odbc) connection (no passwords, also a trusted IWA connection in this case), and the use of an option list and suggest lists. The option list does have an index and a value part, in this case this is the field CATEGORY, which is used two times (!) in the SQL fields, in order to get the option list filled. Take in mind that in this case the definition of wildcards in the SQL phrase is leading in the behaviour of the wildcard ="0" setting and the startleft = "0" setting. Changing the SQL in the second field in 'LIKE UPPER ('%[search]%')' results in finding values in the database as if pattern matching is used: It is not enough only to set wildcard = "0" and startleft = "0", the SQL phrase has to be adjusted to the requested behaviour.   
     213 
     214{{{ 
     215    <searchitem name="Item" description="Items"> 
     216        <layer type="xy" name="Items"> 
     217            <field type="s" name="ItemSysNo" description="ItemSysNo: "  wildcard="0" /> 
     218            <field type="s" name="CATEGORY" description="Category: "  wildcard="0"> 
     219                <definition type="options" connectiontype="db" sort="asc" firstoption="*" > 
     220                     <dsn encoding="UTF-8">odbc://'':''/localhost@databasename</dsn> 
     221                     <sql>SELECT DISTINCT CATEGORY,CATEGORY FROM table_Item ORDER BY CATEGORY</sql> 
     222                     <events>onchange="resetSuggestCache();$('#pmsfld_CITY').val('')"</events> 
     223                </definition> 
     224            </field> 
     225            <field type="s" name="CITY" description="Plaats: "  wildcard="0" > 
     226                <definition type="suggest" connectiontype="db" minlength="2" startleft="0" sort="asc" dependfld="CATEGORY"> 
     227                     <dsn encoding="UTF-8">odbc://'':''/localhost@databasename</dsn> 
     228                     <sql>SELECT DISTINCT CITY FROM table_Item WHERE X>0 AND UPPER(CITY) LIKE UPPER('[search]%') and ISNULL(CATEGORY,'') = '[dependfldval]' ORDER BY CITY</sql> 
     229                </definition> 
     230            </field> 
     231            <field type="s" name="NAME" description="Naam: "  wildcard="0"> 
     232                <definition type="suggest" connectiontype="db" minlength="2" startleft="0" sort="asc" dependfld="CITY"> 
     233                     <dsn encoding="UTF-8">odbc://'':''/localhost@databasename</dsn> 
     234                     <sql>SELECT DISTINCT NAME FROM table_Item WHERE X>0 AND UPPER(NAME) LIKE UPPER('[search]%') and CITY = '[dependfldval]' ORDER BY NAME</sql> 
     235                </definition> 
     236            </field>  
     237        </layer> 
     238    </searchitem> 
     239}}} 
     240 
     241For search multi-items in one database column:[[BR]] 
     242 
     243- Use '''alias="alias_name"''' for the search column & add '''operator="OR"''' in each field, ex: 
     244 
     245{{{ 
     246    <searchitem name="Item" description="Items"> 
     247        <layer type="shape" name="Layer"> 
     248            <field type="s" name="DB_Column" description="Item_1" wildcard="0" operator="OR" /> 
     249            <field type="s" name="DB_Column" alias="DB_Column_2" description="Item_2" wildcard="0" operator="OR" /> 
     250            <field type="s" name="DB_Column" alias="DB_Column_3" description="Item_3" wildcard="0" operator="OR" /> 
     251              ... 
     252               
     253        </layer> 
     254    </searchitem> 
     255}}}