www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  WebPublisher PRO    search within search
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Posted
I made a working search-within-search for Webpublisher a few months back, with the help of the wonderful mootools javascript framework, which makes object-oriented javascript easy. I just never have time to *write* about these things. It was kind of complicated to create, and I'm trying to think of ways to simplify the implementation, but it does work really well.

An overview
The user's initial search is serialized to a cookie. (If the user came to the results via canned query instead of a search form, and thus no cookie, the query string is parsed.) The results page has a 'search within results' textbox. The new search text is combined with the old to create a brand new query string, which is then saved to cookie to become the new original query.

The script in action
The method which serializes a search form looks like this. Four lines: isn't that nice and neat?

function SaveQuery()
{
    var oForm = document.forms[0];
    var formQuery = decodeURIComponent($(oForm).toQueryString()); 
    var oQuery = new WebPublisherQuery(formQuery);
    oQuery.saveToCookie(oQuery.cookieName(), {path: "/"});
}


The method that handles the 'search within results' on the results page goes like this. It's a little longer to handle cookie/no-cookie, but still very easy to follow.

function SearchWithinResults(searchText)
{
	var oQuery = new WebPublisherQuery();
	
	// attempt to load original query from cookie
	var isCookie = oQuery.loadFromCookie(GetQueryParamByKey('TN', 'Catalog') + "QueryTracker");
	if (isCookie == false)
	{
		// no cookie, so load from query string
		if (window.location.search == "")
		{
			return false;	
		}
		var windowQuery = decodeURIComponent(window.location.search.substr(1));
		oQuery.loadFromQuery(windowQuery);
	}
	
	var subquery = new WebPublisherQueryGroup(searchText, {fields: oQuery.getFields()});
	oQuery.addSubquery(subquery);
	oQuery.saveToCookie(oQuery.cookieName(), {path: "/"});
	
	var query = oQuery.toQueryString();
	window.location.href = "/dbtw-wpd/exec/dbtwpub.dll?" + query;
}


Of course the real power is in the WebpublisherQuery object, which is a javascript class that does all the heavy lifting. I won't paste it in here because it's 250 lines of code.

If anyone wants the search within search, they can have it free. I am releasing all my Webpublisher scripts under an open-source MIT/X11 license. The only caveat, folks, is that I do not have time to write documentation. I wish I did. You could of course *hire me* to implement it for you. Which is pretty ironic, I know.

UPDATE: Available for download from my blog post: read the post, get the beta.

This message has been edited. Last edited by: Peter Tyrrell,


Peter Tyrrell, MLIS
Senior Consultant
Andornot Consulting Inc.
http://www.andornot.com/about/developerblog
 
Posts: 179 | Location: Vancouver, BC, Canada | Registered: Thu September 20 2001Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  WebPublisher PRO    search within search