I'm going out of my mind... this used to work, and I can't figure out
what I've changed to make it stop. What -should- be happening: the
first 25 search results show, click 'next' and the next 25 show, etc.
Instead, ALL results show on the first page... when somebody clicks
next, they get ALL the results PLUS the 25 'next' results they should be
seeing.
My code:
<!--- Advanced Search Include --->
<!--- Determine the collection(s) to use for the search. --->
<cfif IsDefined('form.collection')>
<cfset collection_list = form.collection>
<cfelseif IsDefined('url.collection')>
<cfset collection_list = url.collection>
</cfif>
<cflock timeout="30" throwontimeout="no" name="timeperiod">
<!---
Have we paginated past results?
If so, use URL variables instead
of the old form variables.
--->
<cfif IsDefined("url.timeperiod")>
<cfset timeperiod = "#url.timeperiod#">
<cfelse>
<cfset timeperiod = "#form.timeperiod#">
</cfif>
<cfif ((IsDefined("url.startdate"))
AND (len(url.startdate) is not 0))>
<cfset startdate = "#url.startdate#">
<cfelse>
<cfset startdate = "None">
</cfif>
<cfif ((IsDefined("url.enddate"))
AND (len(url.enddate) is not 0))>
<cfset enddate = "#url.enddate#">
<cfelse>
<cfset enddate = "None">
</cfif>
<cfif ((IsDefined("form.startdate"))
AND (len(form.enddate) is not 0))>
<cfset startdate = "#form.startdate#">
<cfelse>
<cfset startdate = "None">
</cfif>
<cfif ((IsDefined("form.enddate"))
AND (len(form.enddate) is not 0))>
<cfset enddate = "#form.enddate#">
<cfelse>
<cfset enddate = "None">
</cfif>
</cflock>
<!--- search for special char . is delimiter --->
<cfset BadCharacterList =
",.&[EMAIL PROTECTED](.)._.=.:.;.<.>./.\.|.].[.}.{.~">
<cfloop index="BadChar" list="#BadCharacterList#" delimiters=".">
<cfif SearchInput CONTAINS BadChar>
<!--- View the Bad Character (for testing) --->
<cfoutput>BAD: #BadChar#</cfoutput>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<span class="small">
Search text cannot contain special characters
such as [EMAIL PROTECTED]&<br>
<br />Special characters allowed are ".*'
</span>
</td>
</tr>
</table>
<cfinclude
template="/epi_root/templates/generic_footer.cfm">
</td></tr></table></td></tr></table></td></tr></table>
<cfabort />
</cfif>
</cfloop>
<cflock timeout="30" throwontimeout="no" name="search1">
<cfset newzzz = "">
<!--- make input sting all lower case --->
<!--- cut begining and ending spaces --->
<!--- standardize input quotes used --->
<cfset newzzz = Replace(trim(lcase(SearchInput)),"'",'"',"ALL")>
<!--- count quotes in input --->
<!--- divide quote count by 2 --->
<!--- drop decimal if odd quote and add 1 more loop --->
<cfset qoutecount =
SpanExcluding(ArrayLen(ListToArray(newzzz,'"'))/2, ".")+1>
</cflock>
<!--- use for testing
<cfoutput>
Loop Count: #qoutecount#<br />
Newzzz: #newzzz#
</cfoutput>
--->
<!--- start loop here --->
<!--- loop to reformat search phrases --->
<cflock timeout="30" throwontimeout="no" name="search2">
<cfloop index="LoopCount" from="1" to="#qoutecount#">
<!--- find info quoted --->
<cfset str =
ReFind('"[[:alnum:][:space:]\*\.\?-]*"',newzzz,1,true)>
<!--- use for testing positon in input
string pos = #str.pos[1]#<br>
string length = #str.len[1]#<br>
--->
<cfif str.pos[1] neq 0>
<!--- cut info quoted --->
<cfset theString = Mid(newzzz, str.pos[1],
str.len[1])>
<!--- if space found in cut quote replace with ~
--->
<cfset theString1 = Replace(theString,"
","~","ALL")>
<!--- change cut quote from double to single
--->
<cfset theString1 =
Replace(theString1,'"',"'","ALL")>
<!--- replace found phrase with cut phrase --->
<cfset newzzz =
Replace(newzzz,theString,theString1,"ALL")>
<!--- use for testing
Cut String: #theString#<BR>
--->
</cfif>
</cfloop>
</cflock>
<!--- delete non-paired quote --->
<cflock timeout="30" throwontimeout="no" name="search3">
<cfset newzzz = trim(Replace(newzzz,'"','',"ALL"))>
<!--- convert search operatives --->
<cfset newzzz = ReplacenoCase(newzzz," AND ","~AND~","ALL")>
<cfset newzzz = ReplacenoCase(newzzz," OR ","~OR~","ALL")>
<cfset newzzz = ReplacenoCase(newzzz," NOT ","~NOT~","ALL")>
<!--- replace spaces with AND --->
<cfset newzzz = ReplacenoCase(newzzz," ","~AND~","ALL")>
<!--- replace ~ with spaces --->
<cfset newzzz = ReplacenoCase(newzzz,"~"," ","ALL")>
<!--- removes pairs of AND OR NOT --->
<cfset newzzz = REReplace(newzzz,"([[:alnum:]]+) [
]+\1","\1","ALL")>
<cfset newzzz = REReplace(newzzz,"([[:alnum:]]+) [
]+\1","\1","ALL")>
<cfset newzzz = REReplace(newzzz,"([[:alnum:]]+) [
]+\1","\1","ALL")>
</cflock>
<!--- use for testing
Original Input: #SearchInput#<br />
New String: #newzzz#<br />
--->
<br />
<cfparam name="url.startrow" default="1">
<cftry>
<cfsearch
name="testSearch"
collection="#collection_list#"
type="Simple"
criteria = "#newzzz#"
maxrows="25"
startrow="#url.startrow#">
<!--- if search error display info --->
<cfcatch type="Any">
<span class="small">
<cfoutput>
Search Error Occurred
<cfif cfcatch.Type IS NOT "unknown">
- #CFCATCH.Type#
</cfif>
<br /><br />
<cfif cfcatch.Detail CONTAINS "Invalid search criteria
entered.">
Invalid search criteria entered.
<br />The error was most likely caused by using
one of the following:
<br /><br />
AND OR NOT *
<br /><br />
Try removing one of these words and search
again.<br />
<cfelse>
#cfcatch.Detail#
</cfif>
<br />
</cfoutput>
</span>
<cfabort />
</cfcatch>
</cftry>
<cfsearch
name="testSearch1"
collection="#collection_list#"
type="Simple"
criteria = "#newzzz#">
<!---
Set delimiters for highlighting by
cutting quotes and search operators
--->
<cflock timeout="30" throwontimeout="no" name="search4">
<cfset newzzz = ReplaceNoCase(newzzz," ",',',"ALL")>
<cfset newzzz = ReplaceNoCase(newzzz,"*","","ALL")>
<cfset newzzz = ReplaceNoCase(newzzz,",or,", ",","ALL")>
<cfset newzzz = ReplaceNoCase(newzzz,",and,", ",","ALL")>
<cfset newzzz = ReplaceNoCase(newzzz,",not,", ",","ALL")>
<cfset newzzz = ReplaceNoCase(newzzz,'"',"","ALL")>
<cfset newzzz = ReplaceNoCase(newzzz,"'","","ALL")>
</cflock>
<!---
If timeperiod is not 'anytime',
we need to return documents found
only between those dates specified
--->
<cfif NOT timeperiod EQ 'anytime'>
<cfif timeperiod EQ 'range'>
<!--- Establish time range based on the date today --->
<cfquery name="tp" datasource="#DSN#">
SELECT id
FROM content
WHERE <cfif form.created EQ 'OneWeek'>
date_created >=
#CreateODBCDate(DateAdd("ww", -1, Now()))#
<cfelseif form.created EQ 'TwoWeeks'>
date_created >=
#CreateODBCDate(DateAdd("ww", -2, Now()))#
<cfelseif form.created EQ 'OneMonth'>
date_created >=
#CreateODBCDate(DateAdd("m", -1, Now()))#
<cfelseif form.created EQ 'ThreeMonths'>
date_created >=
#CreateODBCDate(DateAdd("m", -3, Now()))#
<cfelseif form.created EQ 'OneYear'>
date_created >=
#CreateODBCDate(DateAdd("yyyy", -1, Now()))#
</cfif>
</cfquery>
<cfelseif timeperiod EQ 'between'>
<!--- Check to be sure start and end date are defined.
If not, redirect back to form. --->
<cfif startdate IS ''>
<cflocation url="search.cfm" addtoken="no">
<cfelseif enddate IS ''>
<cflocation url="search.cfm" addtoken="no">
</cfif>
<cfquery name="tp" datasource="#DSN#">
SELECT id
FROM content
WHERE date_created > '#startdate#'
AND date_created < '#enddate#'
</cfquery>
</cfif>
<cfset tp_count = 0 />
<cfloop query="tp">
<cfquery name="testSearch_date" dbtype="query">
SELECT *
FROM testSearch1
WHERE key = #tp.id#
</cfquery>
<cfif testSearch_date.recordcount>
<cfset tp_count = tp_count + 1 />
<cfelse>
<cfset tp_count = tp_count />
</cfif>
</cfloop>
<!---Available Match Information--->
<table border="0" cellspacing="0" cellpadding="0" width="606">
<tr>
<td>
<span class="small">
<!--- if search match found display details --->
<cfif testSearch.RECORDCOUNT GT "0">
<cfoutput>
Records Searched:
#testSearch.RECORDSSEARCHED#<br />
Matches Found: #tp_count#<br />
Searched For: #SearchInput#<br />
</cfoutput>
<cfelse>
<!--- if no match found give search help --->
<cfoutput>
Matches Found: #tp_count#<br />
<br />Searched For: #SearchInput#<br />
</cfoutput>
<br />
<hr width="100%">
<cfinclude
template="/epi_root/searchtips_inc.cfm" />
<cfabort />
</cfif>
</span>
</td>
</tr>
</table>
<br />
<cfset search_display_count = 0 />
<cfloop query="tp">
<cfquery name="search_display" dbtype="query">
SELECT *
FROM testSearch1
WHERE key = #tp.id#
</cfquery>
<cfif search_display.recordcount>
<cfset search_display_count =
search_display_count + 1 />
<table border="0" cellspacing="0"
cellpadding="0" width="606">
<tr>
<td>
<span class="small">
<!--- delete html tags contained in
summary --->
<!--- deliver reduced summary from 500
to 165 --->
<cflock timeout="30" throwontimeout="no"
name="search5">
<!--- delete trailing html tags
that might have been cut --->
<cfset newSummary =
SpanExcluding("#MID("#REReplace(search_display.summary,"<[^>]*>","","ALL
")#",1,165)#...", "<")>
<!--- Check if title placed at
summary end and if so cut it --->
<cfif
"#search_display.Title#..." IS
right(newSummary,len(search_display.title)+3)>
<cfset newSummary =
trim(ReplaceNoCase(newSummary,"#search_display.Title#...","","ALL"))>
<!--- After cut check if
summary is empty --->
<cfif newSummary IS ""
OR newSummary IS " ">
<cfset
newSummary = "No Content">
</cfif>
</cfif>
</cflock>
<!--- create list for case sensitive
input word highlights --->
<cflock timeout="30" throwontimeout="no"
name="search6">
<cfset Newlist = "">
<cfloop index="i"
list="#newzzz#">
<cfset Newlist =
ListAppend(Newlist, Lcase(i))>
<!--- check if search
word more than 1 letter --->
<cfif len(i) GT 1>
<cfset Newlist =
ListAppend(Newlist, Ucase(left(i,1)) & Lcase(right(i, len(i)-1)))>
</cfif>
<cfset Newlist =
ListAppend(Newlist, Ucase(i))>
</cfloop>
<cfset newTITLE =
search_display.TITLE>
</cflock>
<!--- replace words in list with
highlight formating --->
<cflock timeout="30" throwontimeout="no"
name="search7">
<cfloop index="i"
list="#NewList#">
<cfset newSummary =
REReplace(newSUMMARY,i,"<font class='hlyellow'>#i#</font>","ALL")>
<cfset newTITLE =
REReplace(newTITLE,i,"<font class='hlyellow'>#i#</font>","ALL")>
</cfloop>
<!--- set matchcount display
--->
<cfset matchcount =
CURRENTROW+url.startrow-1>
</cflock>
<!--- output search results --->
<cfinclude
template="date_search_output.cfm" />
<br /><br />
</span>
</td>
</tr>
</table>
</cfif>
</cfloop>
<br />
<table border="0" cellspacing="0" cellpadding="0" width="606">
<tr>
<td align="right">
<span class="small">
<cfoutput>
<cfif val(url.startrow-25) gt 0>
<a
href="test.cfm?type=all&startrow=#val(url.startrow-25)#&FindMe=#URLEncod
edFormat(SearchInput)#"><<Previous</a>
</cfif>
<cfif val(url.startrow+25) gte
ceiling(search_display.recordcount)>
<font
color="white"> Next>></font>
<cfelse>
<a
href="test.cfm?collection=#collection_list#&startrow=#val(url.startrow+2
5)#&FindMe=#URLEncodedFormat(SearchInput)#">Next>></a>
</cfif>
</cfoutput>
</span>
</td>
</tr>
</table>
<!--- If timeperiod is not specified, return all documents matching the
search criteria. --->
<cfelse>
<cfquery name="get_distinct" dbtype="query">
SELECT DISTINCT key
FROM testSearch1
</cfquery>
<!---Available Match Information--->
<table border="0" cellspacing="0" cellpadding="0" width="606">
<tr>
<td>
<span class="small">
<!--- if search match found display details --->
<cfif testSearch.RECORDCOUNT GT "0">
<cfoutput>
Records Searched:
#testSearch.RECORDSSEARCHED#<br />
Matches Found:
#get_distinct.RECORDCOUNT#<br />
Searched for... #SearchInput#<br />
</cfoutput>
<cfelse>
<!--- if no match found give search help --->
<cfoutput>
Matches Found:
#testSearch1.RECORDCOUNT#<br />
<br />Searched for... #SearchInput#<br
/>
</cfoutput>
<br />
<hr width="100%">
<cfinclude
template="/epi_root/searchtips_inc.cfm" />
<cfabort />
</cfif>
</span>
</td>
</tr>
</table>
<br />
<cfloop query="get_distinct">
<cfif get_distinct.key CONTAINS ':\'>
<cfquery name="search_display2" dbtype="query">
SELECT *
FROM testSearch1
WHERE key = '#get_distinct.key#'
</cfquery>
<cfelse>
<cfquery name="search_display2" dbtype="query">
SELECT *
FROM testSearch1
WHERE key = #get_distinct.key#
</cfquery>
</cfif>
<table border="0" cellspacing="0" cellpadding="0"
width="606">
<tr>
<td>
<span class="small">
<!--- delete html tags contained in summary --->
<!--- deliver reduced summary from 500 to 165
--->
<cflock timeout="30" throwontimeout="no"
name="search5">
<!--- delete trailing html tags that
might have been cut --->
<cfset newSummary =
SpanExcluding("#MID("#REReplace(search_display2.summary,"<[^>]*>","","AL
L")#",1,165)#...", "<")>
<!--- Check if title placed at summary
end and if so cut it --->
<cfif "#search_display2.Title#..." IS
right(newSummary,len(search_display2.title)+3)>
<cfset newSummary =
trim(ReplaceNoCase(newSummary,"#search_display2.Title#...","","ALL"))>
<!--- After cut check if summary
is empty --->
<cfif newSummary IS "" OR
newSummary IS " ">
<cfset newSummary = "No
Content">
</cfif>
</cfif>
</cflock>
<!--- create list for case sensitive input word
highlights --->
<cflock timeout="30" throwontimeout="no"
name="search6">
<cfset Newlist = "">
<cfloop index="i" list="#newzzz#">
<cfset Newlist =
ListAppend(Newlist, Lcase(i))>
<!--- check if search word more
than 1 letter --->
<cfif len(i) GT 1>
<cfset Newlist =
ListAppend(Newlist, Ucase(left(i,1)) & Lcase(right(i, len(i)-1)))>
</cfif>
<cfset Newlist =
ListAppend(Newlist, Ucase(i))>
</cfloop>
<cfset newTITLE = search_display2.TITLE>
</cflock>
<!--- replace words in list with highlight
formating --->
<cflock timeout="30" throwontimeout="no"
name="search7">
<cfloop index="i" list="#NewList#">
<cfset newSummary =
REReplace(newSUMMARY,i,"<font class='hlyellow'>#i#</font>","ALL")>
<cfset newTITLE =
REReplace(newTITLE,i,"<font class='hlyellow'>#i#</font>","ALL")>
</cfloop>
<!--- set matchcount display --->
<cfset matchcount =
CURRENTROW+url.startrow-1>
</cflock>
<!--- output search results --->
<cfinclude template="search_output.cfm" />
<br /><br />
</span>
</td>
</tr>
</table>
</cfloop>
<br />
<table border="0" cellspacing="0" cellpadding="0" width="606">
<tr>
<td align="right">
<span class="small">
<cfoutput>
<cfif val(url.startrow-25) gt 0>
<a
href="search.cfm?type=all&Action=advanced&timeperiod=anytime&startrow=#v
al(url.startrow-25)#&FindMe=#URLEncodedFormat(SearchInput)#"><<Pre
vious</a>
</cfif>
<cfif val(url.startrow+25) gte
ceiling(get_distinct.recordcount)>
<font
color="white"> Next>></font>
<cfelse>
<a
href="search.cfm?collection=#collection_list#&Action=advanced&timeperiod
=anytime&startrow=#val(url.startrow+25)#&FindMe=#URLEncodedFormat(Search
Input)#">Next>></a>
</cfif>
</cfoutput>
</span>
</td>
</tr>
</table>
</cfif>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:183758
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54