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
Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
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...
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.