wiki:DocManualsearchFive

>> Back to manual

Attribute search

Define attribute search via /config/.../search.xml

<searchlist version="1.0">

    <searchitem name="cities" description="City">
        <layer type="shape" name="cities">
            <field type="s" name="CITY_NAME" description="City"  wildcard="0" />
        </layer>
    </searchitem>  
 
</searchlist> 

Create new <searchitem> for every layer you want to search.

Parameters:

<searchitem>
  name: unique identifier, typically the same as layer name
  description: name visible in GUI
<layer> 
  type: data source type; possible values: "shape", "postgis", "xy", "oracle"  
  name: layer name in map file
<field>
  type: "s" for string field, "n" for numeric field
  name: field name in dataset
  description: name visible in GUI
  wildcard: "0": search always uses a 'non-exact' pattern matching; 
            "1": requires that the user explicitly adds "*" for wildcards to his search string 
            "2": exact search, usually just appropriate for 'suggest' or 'options'

Pmapper 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\.

An XML schema file for validating the search.xml is available here. It can also be used to facilitate the creation of the XML file using a more advanced XML editor tools like the Eclipse framework.

In 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.

A sample using these extended functionality on shape and Postgres layers:

<?xml version="1.0" ?> 
<!--  <?xml-stylesheet href="style.xsl" type="text/xsl" ?>   --> 
<searchlist version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="search.xsd">
  <dataroot>$</dataroot> 
    <searchitem name="cities" description="City">
        <layer type="shape" name="cities10000eu">
            <field type="s" name="NAME" description="City" wildcard="0" /> 
        </layer>
    </searchitem>
    <searchitem name="countries" description="Country">
        <layer type="shape" name="countries">
            <field type="s" name="ISO2_CODE" description="Country" wildcard="2">
                <definition type="options" connectiontype="ms" sort="asc" firstoption="*">
                    <mslayer encoding="ISO-8859-1" keyfield="ISO2_CODE" showfield="NAME" /> 
                </definition>
            </field>
        </layer>
  </searchitem>

  <!--  Sample for suggest function --> 


    <searchitem name="cities_suggest_pg" description="Cities Suggest PG">
        <layer type="postgis" name="cities10000eu_pg">
            <field type="s" name="name" description="City" wildcard="2">
                <definition type="suggest" connectiontype="db" sort="asc" minlength="1" dependfld="cmcncd">
                    <dsn encoding="UTF-8">pgsql://postgres:postgres@localhost/gisdb</dsn>
                    <sql>SELECT DISTINCT name FROM cities1000 WHERE population > 10000 AND name ~* '^[search]' ORDER BY name</sql>
                    </definition> 
            </field> 
        </layer>
    </searchitem>
    


    <searchitem name="cities_suggest_dbf" description="Cities Suggest">
        <layer type="shape" name="cities10000eu">
            <field type="s" name="NAME" description="Citt&agrave;à" wildcard="2">
                <definition type="suggest" connectiontype="dbase" minlength="1" startleft="1" sort="asc">
                    <dbasefile encoding="UTF-8" searchfield="NAME">$/cities10000eu.dbf</dbasefile> 
                </definition>
            </field>
        </layer>
    </searchitem>
    <searchitem name="cities_hidden_suggest_dbf" description="Cities Hidden Suggest DBF">
        <layer type="shape" name="cities10000eu">
            <field type="s" name="ISO2_CODE" description="Country" wildcard="0">
                <definition type="hidden" connectiontype="session" value="gLanguage"/>
            </field>
            <field type="s" name="NAME" description="City" wildcard="2">
                <definition type="suggest" connectiontype="dbase" minlength="1" startleft="1" dependfld="ISO2_CODE">
                    <dbasefile encoding="UTF-8" searchfield="NAME">$/cities10000eu.dbf</dbasefile>
                </definition> 
            </field> 
        </layer>
    </searchitem>
    


    <searchitem name="cities_options_suggest_dbf" description="Cities Options Suggest">
        <layer type="shape" name="cities10000eu">
            <field type="s" name="ISO2_CODE" description="Country" wildcard="2">
                <definition type="options" connectiontype="dbase" sort="asc" firstoption="*">
                    <dbasefile encoding="UTF-8" keyfield="ISO2_CODE" showfield="NAME">$/countries.dbf</dbasefile> 
                    <events>onchange="resetSuggestCache();$('#pmsfld_NAME').val('')"</events> 
                </definition>
            </field>
            <field type="s" name="NAME" description="City" wildcard="2">
                <definition type="suggest" connectiontype="dbase" minlength="1" startleft="1" dependfld="ISO2_CODE">
                    <dbasefile encoding="UTF-8" searchfield="NAME">$/cities10000eu.dbf</dbasefile> 
                </definition>
            </field>
        </layer>
    </searchitem>
    
    <searchitem name="cities_options_suggest_pg" description="Communes Suggest PG">
        <layer type="postgis" name="cmeu01">
            <field type="s" name="cmcncd" description="Country" wildcard="2">
                <definition type="options" connectiontype="db" sort="asc">
                    <dsn encoding="UTF-8">pgsql://postgres:postgres@localhost/gisdb</dsn>
                      <!--  Attention! Two fields to fill the options list: in this case: -->
                      <!--  cnty_id is the bound value for dependfldval, name_en is the display value in the option list--> 
                    <sql>SELECT DISTINCT cnty_id, name_en FROM countries WHERE name_en IS NOT NULL ORDER BY name_en</sql>
                    <events>onchange="resetSuggestCache();$('#pmsfld_CITY_NAME').val('')"</events>
                </definition>
            </field>
            <field type="s" name="cmsbname" description="Name" wildcard="2">
                <definition type="suggest" connectiontype="db" sort="asc" minlength="3" dependfld="cmcncd">
                    <dsn encoding="UTF-8">pgsql://postgres:postgres@localhost/gisdb</dsn>
                    <sql>SELECT DISTINCT cmsbname FROM cmeu01 WHERE cmsbname ~* '^[search]' {and cmcncd = '[dependfldval]'} ORDER BY cmsbname</sql>
                </definition>
            </field> 
        </layer>
    </searchitem>
    
    
    <searchitem name="cities_suggest_ms" description="Cities Suggest MS">
        <layer type="shape" name="cities10000eu">
            <field type="s" name="NAME" description="City" wildcard="2">
                <definition type="suggest" connectiontype="ms" minlength="2" startleft="0" sort="asc">
                    <mslayer encoding="UTF-8"/>
                </definition>
            </field> 
        </layer>
    </searchitem>
    
    
    <searchitem name="cities_options_suggest_ms" description="Cities Options Suggest MS">
        <layer type="shape" name="cities10000eu">
            <field type="s" name="ISO2_CODE" description="Country" wildcard="2">
                <definition type="options" connectiontype="dbase" sort="asc" firstoption="pippo">
                    <dbasefile encoding="UTF-8" keyfield="ISO2_CODE" showfield="NAME">$/countries.dbf</dbasefile>
                    <events>onchange="resetSuggestCache();$('#pmsfld_NAME').val('')"</events>
                </definition>
            </field>
            <field type="s" name="NAME" description="City" wildcard="2">
                <definition type="suggest" connectiontype="ms" minlength="1" startleft="1" sort="asc" dependfld="ISO2_CODE">
                    <mslayer encoding="UTF-8"/>
                </definition>
            </field> 
        </layer>
    </searchitem>
    

    
    <searchitem name="cities_population_1_operator" description="Cities population">
        <layer type="shape" name="cities10000eu">
            <field type="n" name="POPULATION" description="Cities with Population">
                <definition type="operator">
                    <option name=">" value=">" /> 
                    <option name="=" value="=" /> 
                    <option name="<" value="<" /> 
                </definition>
            </field>
        </layer>
    </searchitem>

    <searchitem name="cities_population_2_operator" description="Cities population 2">
        <layer type="shape" name="cities10000eu">
            <field type="n" name="POPULATION" alias="POPULATION1" description="Cities with Population">
                <definition type="operator">
                    <option name="&gt;" value="&gt;"/>
                    <option name="=" value="="/>
                    <option name="&lt;" value="&lt;"/>
                </definition>
            </field>
            <field type="n" name="POPULATION" alias="POPULATION2" description="and population">
                <definition type="operator">
                    <option name="&gt;" value="&gt;"/>
                    <option name="=" value="="/>
                    <option name="&lt;" value="&lt;"/>
                </definition>
            </field>
        </layer>
    </searchitem>
    
</searchlist>

See 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.

    <searchitem name="Item" description="Items">
        <layer type="xy" name="Items">
            <field type="s" name="ItemSysNo" description="ItemSysNo: "  wildcard="0" />
            <field type="s" name="CATEGORY" description="Category: "  wildcard="0">
                <definition type="options" connectiontype="db" sort="asc" firstoption="*" >
                     <dsn encoding="UTF-8">odbc://'':''/localhost@databasename</dsn>
                     <sql>SELECT DISTINCT CATEGORY,CATEGORY FROM table_Item ORDER BY CATEGORY</sql>
                     <events>onchange="resetSuggestCache();$('#pmsfld_CITY').val('')"</events>
                </definition>
            </field>
            <field type="s" name="CITY" description="Plaats: "  wildcard="0" >
                <definition type="suggest" connectiontype="db" minlength="2" startleft="0" sort="asc" dependfld="CATEGORY">
                     <dsn encoding="UTF-8">odbc://'':''/localhost@databasename</dsn>
                     <sql>SELECT DISTINCT CITY FROM table_Item WHERE X>0 AND UPPER(CITY) LIKE UPPER('[search]%') and ISNULL(CATEGORY,'') = '[dependfldval]' ORDER BY CITY</sql>
                </definition>
            </field>
            <field type="s" name="NAME" description="Naam: "  wildcard="0">
                <definition type="suggest" connectiontype="db" minlength="2" startleft="0" sort="asc" dependfld="CITY">
                     <dsn encoding="UTF-8">odbc://'':''/localhost@databasename</dsn>
                     <sql>SELECT DISTINCT NAME FROM table_Item WHERE X>0 AND UPPER(NAME) LIKE UPPER('[search]%') and CITY = '[dependfldval]' ORDER BY NAME</sql>
                </definition>
            </field> 
        </layer>
    </searchitem>

For search multi-items in one database column:

  • Use alias="alias_name" for the search column & add operator="OR" in each field, ex:
    <searchitem name="Item" description="Items">
        <layer type="shape" name="Layer">
            <field type="s" name="DB_Column" description="Item_1" wildcard="0" operator="OR" />
            <field type="s" name="DB_Column" alias="DB_Column_2" description="Item_2" wildcard="0" operator="OR" />
            <field type="s" name="DB_Column" alias="DB_Column_3" description="Item_3" wildcard="0" operator="OR" />
              ...
              
        </layer>
    </searchitem>
Last modified 2 years ago Last modified on Nov 21, 2014, 10:31:13 AM