Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFSEARCH + VERITY + StartRow

0 views
Skip to first unread message

coreygrimm

unread,
Apr 1, 2004, 4:02:36 PM4/1/04
to
Im trying to figure out how to query a collection that produces 20 results then
at the bottom of the page Im able to make a link or button "next". When
clicked it gives the use the next 50 results. The documentation hints at using
the startrow to accomplish this but I has yet to find any documentation that
even comes close to explaining how to do this.

startRow = "row_number"


-------------------------------
search_results.cfm
-------------------------------
<!--- Define a search name and specify the COLLECTION name used in the CF
Admin.--->
<CFSEARCH NAME="search_boxcar"
COLLECTION="boxcar"
CRITERIA="#FORM.criteria#">

<html>
<head>
<title>Search Results</title>
</head>

<body>
<h3>Your search results </h3>

<!--- Output search results complete with score --->
<CFOUTPUT QUERY="search_boxcar">
<a href="#URL#">#Title#</a><br>
Score: #Score#<p>
</CFOUTPUT>

</body>
</html>

jdbrosan

unread,
Apr 2, 2004, 4:19:31 PM4/2/04
to
[q][i]Originally posted by: [b][b]coreygrimm[/b][/b][/i]

Im trying to figure out how to query a collection that produces 20 results
then at the bottom of the page Im able to make a link or button "next". When
clicked it gives the use the next 50 results. The documentation hints at using
the startrow to accomplish this but I has yet to find any documentation that
even comes close to explaining how to do this.

startRow = "row_number"[/q]

Hey Corey,

I think I may be able to you out. I just finished doing this. It may not be
the best way, but I'm still very new to ColdFusion. So here goes.

Basically, I do a check to see if the total number of records returned was
greater than the number of items I want to display per page, if so I display my
second form. My second form consists of nothing but some navigation buttons and
some hidden fields.

<CFOUTPUT>
<CFIF #rsSearchResults.RecordCount# gt #CONST_ITEMS_PER_PAGE#>
<form id="navSearch" name="FrmNavSearch" action="searchaction.cfm"
method="post">
<input type="hidden" name="hfSearchWord" value="#strSearchPhrase#">
<input type="hidden" name="hfStartRecord" value="#iMyIncrement#">
<input type="hidden" name="hfTotalResult" value="#session.iTotalResultCnt#">
<input type="submit" name="btnSearchFirst" value="First">
<input type="submit" name="btnSearchPrev" value="Previous">
<input type="submit" name="srchNext" value="Next">
<input type="submit" name="btnSearchLast" value="Last">
</form>
</CFIF>
</CFOUTPUT>

Its important to note that I store off my search term so that I can pick up
the search from where I left off. I also keep the original total number of
records returned in a hidden field as well. I do that so I can display where
in the total records the user is on each navigation.

When the user clicks on any nav button I check to see if the button is defined
and if the value of the button is equal to what I'm looking for. From there its
simple math.

CONST_INCREMENT_COUNTER is simply another name for how many items per page, or
how many items I want to bump my counter up by.

<CFELSEIF IsDefined("btnSearchPrev")>
<CFIF btnSearchPrev eq "Previous">
<CFSET iMyIncrement = "#Form.hfStartRecord#">
<CFSET strSearchPhrase =
REReplaceNoCase(Form.hfSearchWord,"[[:punct:]]", "", "All")>
<CFSET iMyIncrement = evaluate(iMyIncrement - CONST_INCREMENT_COUNTER)>
<CFSET iEndIncrement = evaluate(iMyIncrement + CONST_END_INCREMENT)>
</CFIF>

I know this isnt the best way to do things with this search, but being, more
of a C#, VB, Java guy, this tag language is really kind of strange to me, but
I'm working with it. ;-)

I hope this helped.

coreygrimm

unread,
Apr 2, 2004, 4:27:57 PM4/2/04
to
jdbrosan

Hey thanks for the follow up. I posted in the advanced area and was working
with a guy that helped me out with the attached Code.
The attached code works really well and solved my dilema.

Thanks!
Corey

<cfif isdefined("Form.criteria") AND (Form.criteria is not "")>

<cfif NOT IsDefined("FORM.Criteria")>
<form name="myForm" action="<cfoutput>#CGI.SCRIPT_NAME#</cfoutput>"
method="post">
<input type="text" name="criteria" value="">
<input type="submit" name="submit" value="GO">
</form>
<cfabort>
</cfif>
<cfif Not IsDefined("FORM.Maxrows")>
<cfset FORM.Maxrows = 20>
</cfif>
<cfif NOT IsDefined("FORM.Startrow")>
<cfset FORM.Startrow = 1>
</cfif>


<!--- Define a search name and specify the COLLECTION name used in the CF
Admin.--->

<cfsearch name="codecoll_results" collection="admin_policies" type="simple"
criteria="#form.criteria#">


<html>
<head>
<title>Search Results</title>

<LINK href="/css/global.css" rel="stylesheet" type="text/css" />


</head>
<body>
<h3>Your search results </h3>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10">&nbsp;</td>
<td>


<!--- Output search results complete with score --->

<cfoutput query="codecoll_results" startrow="#Form.startrow#"
maxrows="#maxrows#">
<strong>Title: <a href="#url#">#title#</a></strong><br>
<strong>Score:</strong> #score#<br>
<strong>Summary:</strong> #summary#<br>
<em>#url#</em><br>
#CurrentRow# out of #RecordCount# found<br><br>
</cfoutput></td>
<td width="10">&nbsp;</td>
</tr>
</table>
<table width="20%" border="0" align="left" cellpadding="0" cellspacing="0">
<cfoutput>
<tr>
<td width="10">&nbsp;</td>
<td>
<cfif startrow gt 20>
<cfset BackStartrow = startrow - 20>
<form name="myForm" action="#CGI.SCRIPT_NAME#" method="post">
<input type="hidden" name="criteria" value="#FORM.Criteria#">
<input type="hidden" name="maxrows" value="20">
<input type="hidden" name="startrow" value="#BackStartrow#">
<input type="submit" name="submit" value="PREV">
</form>
</cfif>
</td>
<td>
<cfif codecoll_results.recordcount GT 20>
<cfset ForwardStartrow = startrow + 20>
<form name="myForm" action="#CGI.SCRIPT_NAME#" method="post">
<input type="hidden" name="criteria" value="#FORM.Criteria#">
<input type="hidden" name="maxrows" value="20">
<input type="hidden" name="startrow" value="#ForwardStartrow#">
<input type="submit" name="submit" value="NEXT">
</form>
</cfif>
</td>
</tr></cfoutput>
</table>
<cfelse>
Please enter somthing in the searchbox
</cfif>
</body>
</html>

0 new messages