Translate

Sunday, December 8, 2013

Example 5: Searching Assets

Searching assets is very basic functionality required in various online sites whether be a content search, tagged-content search or even media asset search. Content (Assets) can be any assets like product assets, article assets, etc.

Following instructions are for searching FLEX assets using searchstate tags.

GENERAL STEPS TO FOLLOW:
  1. For using searchstate tag, add the searchstate taglib at starting of your JSP/XML. 
  2. Create an empty searchstate object (using searchstate:create tag), which can contain 2 operations: "and" & "or".
  3. Add constraint to the searchstate i.e. adding a condition for restricting search based on single attribute or another searchstate (also called as nested constraint). For adding constraint, use anyone of the following tag as required: searchstate:addlikeconstraint, searchstate:addnestedconstraint, searchstate:addrangeconstraint, searchstate:addsimpleconstraint, searchstate:addsimplestandardconstraint, searchstate:addstandardconstraint, etc. according to you requirement. 
  4. Set the searchstate (Using assetset:setsearchedassets tag)
  5. Get the required attribute values (Using assetset:getmultiplevalues or assetset:getattributevalues)
  6. Then list through the result (Using ics:listloop and ics:listget tag)
CASE 1: A simple case: Finding attributes of a flex asset to search against value of one attribute

<searchstate:create name="ss" />
<searchstate:addsimplelikeconstraint name="ss" attribute="cat2" value="Watt%"/>
<assetset:setsearchedassets name="as" constraint="ss" assettypes="Products"/>
<assetset:getattributevalues name="as" attribute="productdesc" listvarname="resultlist"/>
<ics:listloop listname="resultlist">
<ics:listget listname="resultlist" fieldname="value"/><br/>
</ics:listloop>


Apart from using searchstate tags, there are other tags which can be used for searching assets (flex or basic or table data) which are described briefly below:
  1. ics:sql - It executes inline SQL statement. You can write a SQL query and search against tablename which should be registered SYTEMINFO table.
  2. ics:callsql - It retrieves and executes a SQL query stored in the SYSTEMSQL table
  3. ics:sqlexp - This tag is used only to build where clause based on given set of parameters. It does not execute any statement. It passes a column name and an expression that contains the column name to be used as the left side in the where clause.
  4. ics:selectto - It executes a simple query from a table, which is equivalent to run a simple SQL query like select * from tablename
  5. asset:search - It locates a list of asset primary table rows based on the asset type and a set of search criteria. Criteria can be defined which can narrow your search. Not recommended for searching FLEX assets.
  6. asset:list - This tag queries the database and retrieve a list of assets that meets the specified criteria. It creates a list of assets of one type. Specific criteria could be against field/value of certain tablename, passing argument in field name/value pairs, etc. to restrict the list.
Detailed explanation is provided in Tag Reference/Developer guide.

INFO:
  • The above case is very simple case provided by tag reference itself.
  • Check the examples and details of every searchstate tag in TagReference and Developer Guide
  • Following is the list which shows which searchstate tags to use for what case:
    • searchstate:addsimplestandardconstraint - Adds an attribute name/single value constraint to an existing searchstate object.
    • searchstate:addlikeconstraint - Adds a list of attribute like name/value constraints into a new or existing searchstate object.
    • searchstate:addnestedconstraint - Nests a searchstate as a constraint within another searchstate.
    • searchstate:addrangeconstraint - Adds a range constraint to a searchstate on a specific attribute.
    • searchstate:addsimplelikeconstraint - Adds an attribute like name/value constraint into a new or existing searchstate object.
    • searchstate:addstandardconstraint - Adds a list of attribute name/value constraints into a new or existing searchstate object.

----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------