Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Enhancing Verity Search Results

Enhancing Verity Search Results

Your customer says, "I want my site search to include all of my regular site pages and my data-based items as well. When my customer clicks on the link, I want it to show the correct page. Oh, and I want all occurrences of the searched phrase to be highlighted in yellow."

Back at your desk, you follow the book and plug in the parameters for each page. The databased entries are a little more difficult, but you figure it out and run the program to populate the Verity search engine.

The items in the static pages are found okay, but none of the data-based content appears correctly - although sometimes you see your ColdFusion code show up in the results page (Oy!). You mess around a little more and get the data-based items into Verity, but clicking on the link keeps taking you back to the home page or to the root of the data-based page, ignoring your URL options.

And what's this about a yellow highlight?

Review of the Basics
This article assumes you know the basics of ColdFusion programming and have at least tried to get the Verity search engine working. I am not going to delve into an in-depth explanation of what Verity is, but I will start with a very quick overview of how to get rolling. I suggest you pick up a copy of Ben Forta's ColdFusion Web Database Construction Kit books if you haven't yet attempted Verity.

To further illustrate this story, I will refer you to a client site, www.pcamn.org (Prevent Child Abuse Minnesota), which I have received permission to use. I recently upgraded their site search to do everything that will be discussed in this article, and it will serve as my working example.

To begin, we'll first add our static pages to the Verity search engine. Every time I update a Verity search engine collection, I like to wipe it clean to make sure nothing old hangs around to haunt me. To do this, I use the action "refresh" when I add the first page:

<CFINDEX collection="PCAMN" action="REFRESH" type="FILE"

key="d:webclientswww.pcamn.orgwwwabout.cfm"
language="English"
urlPath="http://www.pcamn.org">about *

There is a server-oriented path to the file and a Web-oriented URL to the root location of that page (Verity handles adding the "about.cfm"). I also added the name of the file with an asterisk separator after the CFINDEX operation because I have the Verity search engine update script automated (more on that later) with the "Write Results to a File" option selected. I send myself a daily report that includes all of the text files from all of my automated systems in one combined daily report. This allows me to check every morning for any problems with my automated systems.

Next, we want to add the rest of our static pages to the Verity index using the "action=update" option. You can copy and paste to add them all, or you can make life simpler for yourself by putting the names of the files in a list and looping through that list to add the files to the index:

<cfloop index="ii" list="abuse.cfm,
advocacy.cfm, radiothon.cfm, campaign.cfm,
involved.cfm, resources.cfm, give.cfm,
links.cfm, marketplace.cfm, programs.cfm, members.cfm,
involved.cfm, walk.cfm, prevention.cfm">
<CFINDEX collection="PCAMN" action="UPDATE" type="FILE"

key="d:webclientswww.pcamn.orgwww#TRIM(ii)#"
language="English"
urlPath="http://www.pcamn.org">
<cfoutput>#TRIM(ii)#</cfoutput> *
</cfloop>

Using a list will keep your script shorter and will make it much easier on the next person to update the list of indexed static pages when the clients' needs change. You could set type="path" and index the entire directory, but I usually have a few files in the directory that I don't want to index and this method allows me to be more selective.

Make sure you do not include your allcode- only pages in the list or you'll end up with code examples in the search output. Verity seems to be unhappy with pages that do not have output, and appears to revert to indexing your source code in those cases. At least that's what I've experienced. Perhaps a Verity expert could explain to us why code sometimes gets indexed and ends up in our search results.

Tricking Verity for the Data-Based Entries
We have taken care of the static pages, but how do we merge in the data-based entries and tie them to the appropriate page when the site visitor clicks on the search results link?

I use a little trick for this because Verity seems to ignore my pleadings. Now, this is going to get just a little complicated because we use a common table for this particular client. A common table allows us to plug in a custom tag for both display and administration of their content for multiple pages containing different topics. Modifying the attributes that the tag sends makes it easy to add additional functionality on short notice. Perhaps I'll write an article on that at a later date, but suffice it to say for now that data is displayed based on a key field, and the table also has an "active" column (triggering whether the data can be displayed on the public site) as well as "start showing" and "stop showing" date fields (meaning that if today's date is outside of those dates, the data is not to be made available to the public).

In operation, we refer to a common keyword in the column "itemtext1" of this table for different pages of the site. For example, county_resources.cfm only needs records from the table where itemtext1 is "resources". Additionally, some of our data-based pages employ an additional keyword to narrow down the results better, and those are in a field named "freeform2". For instance, if we want to display all county resources for Becker County, we would call: www.pcamn.org/county_resources.cfm?itemtext=resources&freeform2=Becker .

Please refer now to Listing 1.

Similar to the static pages, we use the names of the items to loop through the CFLOOP list. Additionally, we have the names of the page URLs in the list URLLIST and a Y/N indicator in CUSTOM1LIST to tell us whether or not the page needs the FREEFORM2 parameter added. We keep track of which item in the list to use via the variable THECOUNTER.

Now, as we loop through this script we increment the counter and collect the appropriate items from these two lists into the ADDCUSTOM1 and THEURL variables. We determine what the CFINDEX parameter "title" will contain depending on the contents of ADDCUSTOM1. Study the setting of the variable THETITLE for a moment. Notice the use of the piping character "|". We will use this to our advantage when we display the search results.

Continuing, we collect the "searchresults" recordset by querying the database using ITEMTEXT1 and checking to make sure the record is active and within the date range to make sure we only index those database items that are relevant. Notice in the query how we are combining all of the usable fields from each record by putting them into a commadelimited list in the BODY tag. This allows us to let site visitors search on all of the database fields that contain usable data. Your search will need to be refined to your clients' needs.

You could create a customized search field to combine data in the search result if you needed to. For example, my query in Listing 1 could have combined all of my search fields into one like this:

SELECT itemid, freeform2, itemtitle,
RTRIM(ISNULL(itemtitle, ' ')) + ' ' +
RTRIM(ISNULL(CAST(itemdesc AS varchar(
8000)), ' ')) + ' ' +
RTRIM(ISNULL(freeform2, ' ')) + ' ' +
RTRIM(ISNULL(itemtext1, ' ')) + ' ' +
RTRIM(ISNULL(itemtext2, ' ')) + ' ' +
RTRIM(ISNULL(freeform1, ' ')) AS searchfield
FROM tblFSN_dynamic_new …

and then I would have used BODY= "searchfield" in CFINDEX. The problem here is that the "itemdesc" field is a large text field and not all of the data will be indexed. It also makes for more complex code to maintain than is needed.

Moving forward to the CFINDEX function in Listing 1, notice that we are using the "custom1" and "custom2" parameters. These will come into play in the search results page.

'Custom' Tricks
Please now refer to Listing 2. This is the script for processing the search results. When the search form calls this script, one of the first things we do is remove all angle brackets and pound signs from the searcher's phrase in an attempt to keep hackers at bay. If there is nothing left in the search phrase (or if it was empty to begin with), we simply return the site visitor unceremoniously to the home page.

Next, we conduct the Verity search. This script should be old hat to you until you reach the output area where we are setting the variable THETITLE. If the title has "PUT-CUSTOM2-HERE," we replace it with the contents of the CUSTOM2 variable from the Verity search.

Then, proceeding down a little further, if there is more than one list item in the title, using the piping character as the delimiter we set up our HREF variable to use everything after the first piping character as our URL, and if we run into any "PUT-CUSTOM1-HERE" strings we replace those with the contents of the CUSTOM1 variable from the Verity search.

This has allowed us to customize the results of the Verity search on the fly without having to custom code and index every single variation of the database. We are letting Verity do the work of indexing, and we are forcing it to output the page references that we want our program to call based on the data retrieved.

Yellow Highlights of Search Listing Results
After getting the above indexing working, highlighting the search results in yellow is actually the easy part. By performing a ReplaceNoCase on the search results for the searched-for phrase (we do this on both title and summary information, but that's up to you) and replacing that phrase with one wrapped with a standard HTML <font style="background-color: yellow;"></font> call (remember the "all" parameter on ReplaceNoCase!), you have effectively highlighted the search phrase in your results.

Post Page Yellow
After this worked properly, we thought it fell a little short because sometimes the summary returned by Verity did not contain the actual searched-for phrase. We wanted the referenced page to have the search phrase highlighted in yellow as well, but how, short of rewriting all of our pages to accept a highlight-in-yellow parameter?

If you were observant in reviewing Listing 2, you would have noticed near the middle that the URL that is actually called is "showme.cfm". Notice, also, the URL parameters "SP" and "PAGE".

Please refer now to Listing 3.

Listing 3 accepts as parameters all of the possible fields we may search on, as well as the SP and PAGE parameters. It first checks to see in what format the URL was sent (via the PAGE parameter) and if it needs to prepend "http://"-related information.

Why? Because we're going to make use of the CFHTTP function, and CFHTTP is picky about the URL format.

After setting up the variables for CFHTTP, we call for the page using the parameters passed. When the results return, we simply do the same ReplaceNoCase call that wraps the search phrase ("SP") with the <font style="background-color: yellow;"></font> code. Output the resulting variable and voila! your page now has the search phrase highlighted everywhere it was found.

Keeping It All Up to Date
Alas, having a super search engine won't help much if you don't keep the data fresh, and if you have written administrative tools for your clients to manage content and/or you allow for active/not and start/stop showing dates, you need to refresh the Verity index at least daily.

Two methods come to mind for keeping the clients' Verity index fresh. You could provide them with an administrative link to the script that populates the collection. This would let them update it whenever they updated the data. Because we all know of the human tendency to either forget or put it off, this is not the best solution.

Your best solution is to set up your ColdFusion Administrator's Scheduler to automatically run the update in the wee hours every day or week (depending on how frequently your client updates their content). Make sure you test it first by running it directly from the Administrator, and make sure your timeout value is high enough to cover an ever-expanding database of content.

Limitations
I am expecting e-mail from those of you with better ideas or criticism. Great! If they contribute to the improvement of this method, I'll submit a follow-up article.

More Stories By Randy Smith

Randy L. Smith is president/CEO of Midwest Computer Programming and Internet (www.mcpi.com), an Internet/intranet database solution provider based in Hudson, Wisconsin. He has been developing large-scale, Web-based applications for businesses and nonprofits of all sizes, as well as state and federal entities, since 1993. Randy has been working in the computer industry since 1978, and with ColdFusion since 1996.

Comments (1)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
AI and machine learning disruption for Enterprises started happening in the areas such as IT operations management (ITOPs) and Cloud management and SaaS apps. In 2019 CIOs will see disruptive solutions for Cloud & Devops, AI/ML driven IT Ops and Cloud Ops. Customers want AI-driven multi-cloud operations for monitoring, detection, prevention of disruptions. Disruptions cause revenue loss, unhappy users, impacts brand reputation etc.
The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get tailored market studies; and more.
As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations. Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility. As they do so, IT professionals are also embr...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures. Offering private, hybrid, and public cloud solutions, Atmosera works closely with customers to engineer, deploy, and operate cloud architectures with advanced services that deliver strategic business outcomes. Atmosera's expertise simplifies the process of cloud transformation and our 20+ years of experience managing complex IT environments provides our customers with the confidence and trust tha...
As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations. Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility.
Today's workforce is trading their cubicles and corporate desktops in favor of an any-location, any-device work style. And as digital natives make up more and more of the modern workforce, the appetite for user-friendly, cloud-based services grows. The center of work is shifting to the user and to the cloud. But managing a proliferation of SaaS, web, and mobile apps running on any number of clouds and devices is unwieldy and increases security risks. Steve Wilson, Citrix Vice President of Cloud,...
When Enterprises started adopting Hadoop-based Big Data environments over the last ten years, they were mainly on-premise deployments. Organizations would spin up and manage large Hadoop clusters, where they would funnel exabytes or petabytes of unstructured data.However, over the last few years the economics of maintaining this enormous infrastructure compared with the elastic scalability of viable cloud options has changed this equation. The growth of cloud storage, cloud-managed big data e...
Artificial intelligence, machine learning, neural networks. We're in the midst of a wave of excitement around AI such as hasn't been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. This time is (mostly) different. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Pattern recognition can equal or exceed the ability of human experts in some domains. It's devel...