Skip to main content
Inspiring
January 19, 2007
Answered

Search form troubles

  • January 19, 2007
  • 6 replies
  • 1541 views
Here is the code the previous guy wrote. It never worked. Help! :

<form name="search" id="search_engine" action="/main/index.cfm?category=search_results&sort=search" method="post">
<h5><font color="##FFFFFF">Search Our Site</font></h5><br />
<input type="text" name="searchstring" size="10" /> <input type="submit" value="Go!" /><br />
<font color="ffffff">Choose maximum row display:</font><br /> <font color="ffffff">10</font> <input type="radio" name="MaxRow" value="10" /> <font color="ffffff">25</font> <input type="radio" name="MaxRow" value="25" /> <font color="ffffff">50</font> <input type="radio" name="MaxRow" value="50" /> <font color="ffffff">100</font> <input type="radio" name="MaxRow" value="100" />

</form>
    This topic has been closed for replies.
    Correct answer coldandconfused
    finally fixed the thing after looking at http://coldfusion.sys-con.com/read/41800.htm and http://www.adobe.com/devnet/server_archive/articles/understanding_verity_collections_in_cf.html finally and tweaking the code.

    6 replies

    Inspiring
    January 23, 2007
    it duplicates part of the directory leading to the found fule in the url
    coldandconfusedAuthorCorrect answer
    Inspiring
    January 24, 2007
    Inspiring
    January 22, 2007
    This is on your action page?

    <cfsearch name="GetResults" collection="Search_Engine" criteria="#criteria#" type="simple" >

    Where does the criteria variable come from? The closest thing I see on your form is:
    <input type="text" name="searchstring" size="10" />
    and the name is not criteria.
    Inspiring
    January 22, 2007
    <cfinclude template="css_definitions.cfm">
    <cfparam name="FORM.search" default="">
    <cfparam name="FORM.pdf" default="">
    <cfparam name="URL.StartRow" default="1">
    <cfparam name="FORM.criteria" default="">
    <cfparam name="URL.criteria" default="">
    <cfparam name="FORM.maxrows" default="">
    <cfparam name="URL.MaxRows" default="">
    <cfparam name="MaxRows" default="10">

    are the parameters loaded first. Does "criteria" need a value specified above?

    Bob
    Inspiring
    January 23, 2007
    <cfinclude template="css_definitions.cfm">
    <cfparam name="FORM.search" default="">
    <cfparam name="FORM.pdf" default="">
    <cfparam name="URL.StartRow" default="1">
    <cfparam name="FORM.criteria" default="">
    <cfparam name="URL.criteria" default="">
    <cfparam name="FORM.maxrows" default="">
    <cfparam name="URL.MaxRows" default="">
    <cfparam name="MaxRows" default="10">

    <h4>Search Results Page</h4>
    <br />
    <!--- Run the search against the Verity collection --->
    <!---
    <cflock type="exclusive" timeout="30">
    <cfcollection action="create" collection="Search_Engine" path="C:\CFUSION\Verity\Collections\">
    </cflock>--->

    <!---
    <cfif #FORM.search# eq "simple">
    --->
    <cfoutput>
    <cfset criteria = #FORM.criteria#>
    <cfif URL.criteria neq ''>
    <cfset criteria = #URL.criteria#>
    </cfif>
    <cfset MaxRows = #FORM.MaxRows#>
    <cfif URL.MaxRows neq ''>
    <cfset MaxRows = #URL.MaxRows#>
    </cfif>

    </cfoutput>

    <cfsearch name="GetResults" collection="searchengine" criteria="#criteria#" type="simple" >

    <!--- Display the results --->
    <!--- no files found for specified criteria? --->
    <cfif GetResults.RecordCount is 0>
    <b>No files found for specified criteria</b>
    <cfelseif #criteria# eq ''>
    <b>There were no KEYWORDS entered into the search field</b>
    <cfelse>
    <!--- at least one file found --->
    <table cellpadding="2" cellspacing="0" border="0" class="basic_text">
    <tr>
    <td colspan="3">
    <cfoutput>
    You are searching for: "<b>#criteria#</b>"<br />
    #GetResults.RecordCount# items found matching your search.

    <!--- #GetResults.RecordCount# out of #GetResults.RecordsSearched# documents found.--->
    </cfoutput>

    <div style="float:right;">
    <br />
    Page #
    <cfset ThisPage = 1>
    <cfset TotalRows = GetResults.RecordCount>
    <cfset EndRow = Min(URL.StartRow + MaxRows - 1, TotalRows)>
    <cfloop from="1" to="#TotalRows#" step="#MaxRows#" index="PageRow">
    <cfset IsCurrentPage = (PageRow GTE URL.StartRow) AND (PageRow LTE EndRow)>
    <cfif IsCurrentPage>
    <cfoutput><b>#ThisPage#</b></cfoutput>
    <cfelse>
    <cfoutput>
    <a href="/main/index.cfm?category=search_results&StartRow=#PageRow#&MaxRows=#MaxRows#&criteria=#criteria#">#ThisPage#</a>
    </cfoutput>
    </cfif>
    <cfset ThisPage = ThisPage + 1>
    </cfloop>
    </div>

    </tr>
    <tr bgcolor="cccccc">

    <td><b>File</b></td>
    <td><b>Title</b></td>
    </tr>
    <cfoutput query="GetResults" maxrows="#Val(MaxRows)#" startrow="#URL.StartRow#">
    <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('ffffcf'))#">
    <!--- current row information --->

    <!--- file name with the link returning the file --->
    <td>#Evaluate(1 + CurrentRow - 1)#  
    <!--- HREF to file is produced using either FILE protocol
    of HTTP, depending on whether this is a web docuement. We'll
    look at the file ext to determine if it's a web doc or not --->
    <cfset FileName=GetFileFromPath(key)>

    <cfset Ext=Right(FileName, Evaluate(Find(".", Reverse(FileName))-1))>

    <!---<a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>--->

    <!---
    <cfif #FORM.pdf# neq ''>
    <cfif ( Find(Ext,"pdf") GT 0)>
    <a href="#Key#">#GetFileFromPath(Key)#</a>
    </cfif>
    <cfelse>
    --->
    <!--- <cfset PathName = "/main/index.cfm?category="> --->
    <cfif ( Find(Ext,"htm, html, cfm, asp, dbm") GT 0)>
    <!--- If it's a web doc, use URL returned --->
    <a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>
    <cfelse>
    <!--- It's not a web doc, use file path in KEY from result --->
    <a href="#Key#">#GetFileFromPath(Key)#</a>
    </cfif>
    <!---</cfif>--->
    </td>
    <!--- title for HTML files --->
    <td>
    #Title#  
    </td>
    </tr>
    </cfoutput>
    </table>
    <div style="float:right;">
    Page #
    <cfset ThisPage = 1>
    <cfset TotalRows = GetResults.RecordCount>
    <cfset EndRow = Min(URL.StartRow + MaxRows - 1, TotalRows)>
    <cfloop from="1" to="#TotalRows#" step="#MaxRows#" index="PageRow">
    <cfset IsCurrentPage = (PageRow GTE URL.StartRow) AND (PageRow LTE EndRow)>
    <cfif IsCurrentPage>
    <cfoutput><b>#ThisPage#</b></cfoutput>
    <cfelse>
    <cfoutput>
    <a href="/main/index.cfm?category=search_results&StartRow=#PageRow#&MaxRows=#MaxRows#&criteria=#criteria#">#ThisPage#</a>
    </cfoutput>
    </cfif>
    <cfset ThisPage = ThisPage + 1>
    </cfloop>
    </div>

    <p> </p>


    <!---
    <cfif GetResults.RecordCount gt FORM.MaxRows>
    <form action="/main/index.cfm?category=search_results&sort=none" method="post">
    <cfoutput>
    <input type="hidden" name="criteria" value="#Replace(FORM.Criteria, """", "'", "ALL")#">
    <input type="hidden" name="MaxRows" value="#FORM.MaxRows#">
    <input type="hidden" name="StartRow" value="#Evaluate(Form.StartRow + Form.MaxRows)#">
    <input type="submit" value=" More ...">

    </cfoutput>
    </form>
    </cfif>
    --->
    </cfif>
    <!---
    </cfif>

    <cfif #FORM.search# eq "explicit">
    <cfsearch name="GetResults" collection="Search_Engine" criteria="#FORM.criteria#" type="explicit">

    <!--- Display the results --->
    <!--- no files found for specified criteria? --->
    <cfif GetResults.RecordCount is 0>
    <b>No files found for specified criteria</b>
    <cfelse>
    <!--- at least one file found --->
    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    <td colspan="4">
    <cfoutput>
    #GetResults.RecordCount# out of #GetResults.RecordsSearched# documents found.
    </cfoutput>
    </tr>
    <tr bgcolor="cccccc">
    <td><b>File</b></td>
    <td><b>Title</b></td>
    </tr>
    <cfoutput query="GetResults">
    <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('ffffcf'))#">
    <!--- current row information --->

    <!--- file name with the link returning the file --->
    <td>
    <!--- HREF to file is produced using either FILE protocol
    of HTTP, depending on whether this is a web docuement. We'll
    look at the file ext to determine if it's a web doc or not --->
    <cfset FileName=GetFileFromPath(key)>
    <cfset Ext=Right(FileName, Evaluate(Find(".", Reverse(FileName))-1))>
    <a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>
    <!---
    <cfif ( Find(Ext,"htm, html, cfm, asp, dbm") GT 0)>
    <!--- If it's a web doc, use URL returned --->
    <a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>
    <cfelse>
    <!--- It's not a web doc, use file path in KEY from result --->
    <a href="#Key#">#GetFileFromPath(Key)#</a>
    </cfif>
    --->
    </td>
    <!--- title for HTML files --->
    <td>
    #Title#
    </td>
    </tr>
    </cfoutput>
    </table>
    </cfif>
    </cfif>
    --->

    is my new code that returns results...but won't make the urls in the right format. Aargh!
    Inspiring
    January 20, 2007
    To start, I'd get rid of the url variables in the form action attribute. If the action page can be accessed by either a form or hyperlink, write some code at the start of the action page that checks this, sets local variables accordingly, and carries on.
    Inspiring
    January 19, 2007
    What doesn't work? Any error messages?
    Inspiring
    January 22, 2007
    quote:

    Originally posted by: Dinghus
    What doesn't work? Any error messages?


    Yes. It says "The following information is meant for the website developer for debugging purposes. Error While Processing Request.

    The Collection search engine does not exist

    The collection you specified does not exist or is not registered with the ColdFusion Search Service.

    The error occurred in search_results.cfm line 34:

    32 : </cfoutput>
    33 :
    34 : <cfsearch name="GetResults" collection="Search_Engine" criteria="#criteria#" type="simple" >
    35 :
    36 <!--- Display the results --->:

    Inspiring
    January 22, 2007
    Ok. I used all of your suggestions. I appreciate the help tremendously! Also, I corrected an error I found that was looking for a collection in the wrong place. Now every search comes back with no results at all. What can I do?
    Inspiring
    January 19, 2007
    next part of search results page (sorry about fragmenting. Characters are limited as you know):


    <!---
    <cfif GetResults.RecordCount gt FORM.MaxRows>
    <form action="/main/index.cfm?category=search_results&section=none" method="post">
    <cfoutput>
    <input type="hidden" name="criteria" value="#Replace(FORM.Criteria, """", "'", "ALL")#">
    <input type="hidden" name="MaxRows" value="#FORM.MaxRows#">
    <input type="hidden" name="StartRow" value="#Evaluate(Form.StartRow + Form.MaxRows)#">
    <input type="submit" value=" More ...">

    </cfoutput>
    </form>
    </cfif>
    --->
    </cfif>
    <!---
    </cfif>

    <cfif #FORM.search# eq "explicit">
    <cfsearch name="GetResults" collection="Search_Engine" criteria="#FORM.criteria#" type="explicit">

    <!--- Display the results --->
    <!--- no files found for specified criteria? --->
    <cfif GetResults.RecordCount is 0>
    <b>No files found for specified criteria</b>
    <cfelse>
    <!--- at least one file found --->
    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    <td colspan="4">
    <cfoutput>
    #GetResults.RecordCount# out of #GetResults.RecordsSearched# documents found.
    </cfoutput>
    </tr>
    <tr bgcolor="cccccc">
    <td><b>File</b></td>
    <td><b>Title</b></td>
    </tr>
    <cfoutput query="GetResults">
    <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('ffffcf'))#">
    <!--- current row information --->

    <!--- file name with the link returning the file --->
    <td>
    <!--- HREF to file is produced using either FILE protocol
    of HTTP, depending on whether this is a web docuement. We'll
    look at the file ext to determine if it's a web doc or not --->
    <cfset FileName=GetFileFromPath(key)>
    <cfset Ext=Right(FileName, Evaluate(Find(".", Reverse(FileName))-1))>
    <a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>
    <!---
    <cfif ( Find(Ext,"htm, html, cfm, asp, dbm") GT 0)>
    <!--- If it's a web doc, use URL returned --->
    <a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>
    <cfelse>
    <!--- It's not a web doc, use file path in KEY from result --->
    <a href="#Key#">#GetFileFromPath(Key)#</a>
    </cfif>
    --->
    </td>
    <!--- title for HTML files --->
    <td>
    #Title#
    </td>
    </tr>
    </cfoutput>
    </table>
    </cfif>
    </cfif>
    --->
    Inspiring
    January 19, 2007
    The search results page:

    <h4>Search Results Page</h4>
    <br />
    <!--- Run the search against the Verity collection --->
    <!---
    <cflock type="exclusive" timeout="30">
    <cfcollection action="create" collection="Search_Engine" path="C:\CFUSION\Verity\Collections\">
    </cflock>--->

    <!---
    <cfif #FORM.search# eq "simple">
    --->
    <cfoutput>
    <cfset criteria = #FORM.criteria#>
    <cfif URL.criteria neq ''>
    <cfset criteria = #URL.criteria#>
    </cfif>
    <cfset MaxRows = #FORM.MaxRows#>
    <cfif URL.MaxRows neq ''>
    <cfset MaxRows = #URL.MaxRows#>
    </cfif>

    </cfoutput>

    <cfsearch name="GetResults" collection="Search_Engine" criteria="#criteria#" type="simple" >

    <!--- Display the results --->
    <!--- no files found for specified criteria? --->
    <cfif GetResults.RecordCount is 0>
    <b>No files found for specified criteria</b>
    <cfelseif #criteria# eq ''>
    <b>There were no KEYWORDS entered into the search field</b>
    <cfelse>
    <!--- at least one file found --->
    <table cellpadding="2" cellspacing="0" border="0" class="basic_text">
    <tr>
    <td colspan="3">
    <cfoutput>
    You are searching for: "<b>#criteria#</b>"<br />
    #GetResults.RecordCount# items found matching your search.

    <!--- #GetResults.RecordCount# out of #GetResults.RecordsSearched# documents found.--->
    </cfoutput>

    <div style="float:right;">
    <br />
    Page #
    <cfset ThisPage = 1>
    <cfset TotalRows = GetResults.RecordCount>
    <cfset EndRow = Min(URL.StartRow + MaxRows - 1, TotalRows)>
    <cfloop from="1" to="#TotalRows#" step="#MaxRows#" index="PageRow">
    <cfset IsCurrentPage = (PageRow GTE URL.StartRow) AND (PageRow LTE EndRow)>
    <cfif IsCurrentPage>
    <cfoutput><b>#ThisPage#</b></cfoutput>
    <cfelse>
    <cfoutput>
    <a href="/main/index.cfm?category=search_results&StartRow=#PageRow#&MaxRows=#MaxRows#&criteria=#criteria#">#ThisPage#</a>
    </cfoutput>
    </cfif>
    <cfset ThisPage = ThisPage + 1>
    </cfloop>
    </div>

    </tr>
    <tr bgcolor="cccccc">

    <td><b>File</b></td>
    <td><b>Title</b></td>
    </tr>
    <cfoutput query="GetResults" maxrows="#Val(MaxRows)#" startrow="#URL.StartRow#">
    <tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('ffffcf'))#">
    <!--- current row information --->

    <!--- file name with the link returning the file --->
    <td>#Evaluate(1 + CurrentRow - 1)#  
    <!--- HREF to file is produced using either FILE protocol
    of HTTP, depending on whether this is a web docuement. We'll
    look at the file ext to determine if it's a web doc or not --->
    <cfset FileName=GetFileFromPath(key)>

    <cfset Ext=Right(FileName, Evaluate(Find(".", Reverse(FileName))-1))>

    <!---<a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>--->

    <!---
    <cfif #FORM.pdf# neq ''>
    <cfif ( Find(Ext,"pdf") GT 0)>
    <a href="#Key#">#GetFileFromPath(Key)#</a>
    </cfif>
    <cfelse>
    --->
    <cfset PathName = "/main/index.cfm?category=">
    <cfif ( Find(Ext,"htm, html, cfm, asp, dbm") GT 0)>
    <!--- If it's a web doc, use URL returned --->
    <a href="#GetResults.URL#">#GetFileFromPath(Key)#</a>
    <cfelse>
    <!--- It's not a web doc, use file path in KEY from result --->
    <a href="#Key#">#GetFileFromPath(Key)#</a>
    </cfif>
    <!---</cfif>--->
    </td>
    <!--- title for HTML files --->
    <td>
    #Title#  
    </td>
    </tr>
    </cfoutput>
    </table>
    <div style="float:right;">
    Page #
    <cfset ThisPage = 1>
    <cfset TotalRows = GetResults.RecordCount>
    <cfset EndRow = Min(URL.StartRow + MaxRows - 1, TotalRows)>
    <cfloop from="1" to="#TotalRows#" step="#MaxRows#" index="PageRow">
    <cfset IsCurrentPage = (PageRow GTE URL.StartRow) AND (PageRow LTE EndRow)>
    <cfif IsCurrentPage>
    <cfoutput><b>#ThisPage#</b></cfoutput>
    <cfelse>
    <cfoutput>
    <a href="/main/index.cfm?category=search_results&StartRow=#PageRow#&MaxRows=#MaxRows#&criteria=#criteria#">#ThisPage#</a>
    </cfoutput>
    </cfif>
    <cfset ThisPage = ThisPage + 1>
    </cfloop>
    </div>

    <p> </p>