TomRed.net

  • Increase font size
  • Default font size
  • Decrease font size
Subscribe Bookmark and Share
Home Tutorials CSS FatWire Retrieving Search Results

FatWire Retrieving Search Results

User Rating: / 0
PoorBest 

The searchstate:create tag specifies the name of the search. This name is then referenced by the searchstate:addsimplestandardconstraint and assetset:setsearchedassets tags.
The searchstate:addsimplestandardconstraint is used to specify simple constraints of the search; in this case I have called the constraint searchCriteria and applied it to the attribute JobReferenceNumber, where the value of JobReferenceNumber is equal to ref2823. assetset:setsearchedassets then allows you to assign the results of your assettypes to a variable using the contraints referenced by the name given in the searchstate:create tag.
The results can then be iterated using a standard listloop.

<%-- setting search params & output variable --%>
<searchstate:create name="vacancySearch" /><%-- AND search --%>
<searchstate:addsimplestandardconstraint name="vacancySearch" bucket="searchCriteria" 
	attribute="JobReferenceNumber" value="ref2823" typename="asset" />
<assetset:setsearchedassets name="searchResults" constraint="vacancySearch" assettypes="vacancyAsset"/>

<ics:if condition='<%=ics.GetVar("searchResults")!=null%>'>
	<br />Results...<br />
	<assetset:getattributevalues name="searchResults" attribute="JobReferenceNumber" listvarname="resultlist" typename="asset"/>
	<ics:listloop listname="resultlist">
		<ics:listget listname="resultlist" fieldname="value"/><br/>
	</ics:listloop>
</ics:if>

The search above is an AND search it is possible to do an OR by adding op="OR" to the searchstate:create tag.

<searchstate:create name="vacancySearch" op="OR" /><%-- OR search --%>

There are other options available in the search, such as searchstate:addsimplelikeconstraint. This allows you to specify a LIKE query using the % as the wild card character. If we wanted to find a JobReferenceNumber but were unsure as to the exact value (often occurring in search).

<searchstate:addsimplelikeconstraint name="vacancySearch" bucket="searchCriteria" attribute="JobReferenceNumber" value="ref28%"/>

Applying this to the first example we get:

<%-- setting search params & output variable --%>
<searchstate:create name="vacancySearch" /><%-- AND search --%>
<searchstate:addsimplelikeconstraint name="vacancySearch" bucket="searchCriteria" attribute="JobReferenceNumber" value="ref28%"/>
<assetset:setsearchedassets name="searchResults" constraint="vacancySearch" assettypes="vacancyAsset"/>

<ics:if condition='<%=ics.GetVar("searchResults")!=null%>'>
	<br />Results...<br />
	<assetset:getattributevalues name="searchResults" attribute="JobReferenceNumber" listvarname="resultlist" typename="asset"/>
	<ics:listloop listname="resultlist">
		<ics:listget listname="resultlist" fieldname="value"/><br/>
	</ics:listloop>
</ics:if>

This will return all assets with a ref that starts with 'ref28' but can finish with anything.