Free-Conversant Support / How to Exclude Words from Searches
 Home   About Conversant   Free Sites   Hosting   Support   XML-RPC 

Search



Documentation >> Outline of How-To Docs >> How to Exclude Words from Searches

How to Exclude Words from Searches

Some conversations (web sites) are focused on specific topics. When the site becomes very large, there are some words that shouldn't be searched for any longer because they're used in almost every message (page). Searching for those words slows the server down terribly as it works to process hundreds or thousands of messages in the search results.

This support site, for example, is focused on Conversant. Searching for the word "Conversant" takes a long time, because most of the messages include it.

The solution, at least in the short term, is to prevent incoming searches from including words that are extremely common in your conversation. This is done with a JavaScript, using a technique called "JavaScript form validation".

When a user submits a search form on your site, the javascript will run first. The script looks at each word in the text that the user is searching for (the "search string"), and compares it with a list of "ignored words" that you've provided it. If a word (in the search string) is included in the list of ignored words, it's removed from the search string, so that it's not included in what is sent to Conversant.

The JavaScript script to accomplish this is attached to this message. To use it on your site, follow these steps:

  1. Download the JavaScript file searchFormPreSubmit.js

  2. Open the file in a text editor, and make the following changes:

    • At the top of the file, change the list of words you want ignored. Words must be surrounded in quotes, and separated by a comma. Also separating them with white space, such as spaces or carriage returns, is optional. The list must end with the right bracket: ].

    • Near the bottom of the file, edit the function named preSubmitSearchForm so that it's checking the text fields in your search form. By default, it checks the body and subject fields. If you have other text fields (such as a custom field), you can check them also by copying and pasting lines four and five of that function and then editing the copies. Just change each occurence of the word "body" with the name of the field you want checked.

  3. Save the file.

  4. Select the entire contents of the file, and copy it.

  5. Create a new javascript in the admin interface, named "searchFormPreSubmit". Paste the script into the form when editing the new script, and save it (click the "Submit Changes" button).

  6. Add the script to your page template, using the JavaScript macro. For debugging purposes, it's probably better if you embed the javascript in the page. Once your confident that it's working correctly, you can allow the browsers to cache the script by using embed="false".

  7. Call the javascript from the search form:

    • If your search form is part of an AQP, add the onSubmit attribute to the queryFormTag macro in the Query Form Template, like this:

      <!--#queryFormTag [other macro attributes] onSubmit="return preSubmitSearchForm( this );"-->

    • If your search form is written manually, such as with the small search fields found on almost every page of most sites, then find and edit the template containing the form tag. Change the form tag to include the onSubmit attribute, as follows:

      <form [other macro attributes] onSubmit="return preSubmitSearchForm( this );">

That's it, you're done. Browser's with JavaScript running (that's most of them) will no longer be able to search for the words you've excluded.

NOTE: this is not a catch-all, thorough, or complete solution to the problem. Think of it as a quick way to prevent virtually all of the "harmless" users from slowing down the server your site runs on. Unfriendly, web-savvy users will have no problem avoiding the restrictions of this JavaScript.

  • Any browser without JavaScript active will still be unaffected by these changes. (Nearly all browsers have JavaScript active, but some do not.)

  • If a link points to a search page, and the link includes the words you want omitted, the search will still run. Also, of course, the search terms could be typed directly into the browser's URL, if the user knows what he's doing.

If you have any problems, please let us know by replying to this message!

View in DG