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
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...