Quick Tip: Cheating your way to cross-output searching

This forum is for all Flare issues not related to any of the other categories.
Post Reply
Eric Lachance
Sr. Propeller Head
Posts: 127
Joined: Thu May 13, 2010 11:51 am
Location: Montreal, Quebec, Canada
Contact:

Quick Tip: Cheating your way to cross-output searching

Post by Eric Lachance »

Didn't know exactly how to describe it in the title, but what I mean is that in my case, I needed to find a way to send a client to a different manual whenever they made specific word searches in one manual. The reason for this is that the different error messages (Codes) for our software were all regrouped in a single "Knowledge Base", and it happened quite often that users would search for these error messages in the user manual - very understandable.

I took advantage of something that happens in Flare's WebHelp output whenever a search result is found: It will automatically "unhide" any hidden blocks in the HTML and highlight the search term. That means if you have a div of which the style is "display:hidden;", that style will be removed by Flare's javascript, the search term result will be wrapped in a span and highlighted in yellow.

Considering I had well over 200 error codes for one software in particular, the following method generated a clean, pretty message for the user.

1. The HTML

The hint here it to build your sentence and, in the middle of it, throw in a bunch of hidden spans with your results in them. Example:

Code: Select all

<p>Search results for <strong><span style="display:hidden;">ERR001</span><span style="display:hidden;">ERR002</span><span style="display:hidden;">ERR003</span></strong> can be found in the Knowledge Base. Click <a href="/en/knowledgebase/" id="kbLink">here</a> to try your search in the KB.
I only put 3 error codes here, but you get the idea. You may think "that's a lot of HTML code that repeats", and you're correct. It is the only downside of this method - a lot of HTML (30Kb in my case).

2. Javascript Magic

I didn't like the idea of telling people "go in the KB and do your search again", so I cheated a little: I used Javascript to grab the highlighted result from the URL query string and re-built a link so that when the client clicked on it, they would be redirected to the search results with that same word directly.

Code: Select all

<script type="text/javascript"><!--
	function getURLParameter(name) {
		return decodeURI(
			(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
		);
	}
	var searchResult = getURLParameter("Highlight");
	$("#kbLink").attr("href", "/EN/knowledgebase/search/"+searchResult);
	-->
</script>
Note that I redirect to a /search/{term} , which is unique to me - I created an HTTP redirection to Default_CSH.html with the search term as well as the "FirstPick" option. It's something I did to enable quick search through a URL, without the need to save a complicated query like it would be normally required by the webhelp. Also, I use jQuery in my documentation so that javascript code is built with jQuery in mind... If you don't use it, your homework is to convert that to "regular" javascript (and most likely realize how jQuery makes your life easier, I guess).

3. Going Further

While I decided to let the users click the link automatically, it would have been very trivial to change the javascript so that it would redirect the user after a couple of seconds or, even further, automatically without even displaying the page (in which case the invisible spans would have been useless and only the second point would have been necessary).

You could also create one page per manual you want to redirect to, have a bunch of keywords on each of those pages and call each page "Search Results in Manual X", if that tickles your fancy.

Enjoy! (Oh, btw, your results may vary, I'm not responsible if anything happens, this is provided as is with no support, etc etc. You know the drill!)
Eric Lachance
Technical Trainer
Objectif Lune Inc.
Eric Lachance
Sr. Propeller Head
Posts: 127
Joined: Thu May 13, 2010 11:51 am
Location: Montreal, Quebec, Canada
Contact:

Re: Quick Tip: Cheating your way to cross-output searching

Post by Eric Lachance »

Oh, I forgot to post an example! Here's a finished product:
http://help.objectiflune.com/en/planetp ... ight=S1014

That page can be reached by opening the navigation (link at top of page), searching for "S1014" and looking at the results.
Eric Lachance
Technical Trainer
Objectif Lune Inc.
Post Reply