Resurrecting jsFind Part 2
Given that I had an index ready to go last night all I had to do was get the javascript to work, how hard could that be? Javascript is not a language I consider myself proficient. I usually swear a lot when js is involved.
So I started by ignoring the js. Grabbed a page and hollowed it out to a template and declared it the search results page.
Then I spent a lot of time staring at js. The example seemed to do its best to hide what a developer actually had to do. I eventually found the call I needed to make. You call the method and pass the search terms and a callback method that gets the results objects and outputs them.
The callback method had some issues and so I wrote my own. Then comes the part where I waste a lot of time because it doesn’t look like search results should look. I finally get something that looks about right. Modern search results have a description/context section which jsFind is missing. This is obvious because I removed the position data when I created jsFind’s xml file. But we have results with a title, url and frequency. Good enough for now.
Reworked the search forms on the page to point to the results page. Seems the piece that process args doesn’t properly process more than one argument, so I worked around that problem by not giving the submit button a name. I’ll fix it properly later. And now I had one working page that worked like a charm.
Then I started testing.
So the page has a stylesheet imported by the @include mechanism. Which means it was still pointing to the original site. This got me wondering how I could build some js to include search.js for any location in the site hierarchy… I had the same thought about the css file. For the time being used a known key the url to find the root, it works but it isn’t very portable to another project. I’m going to have to think about a long term solution, but with a root in place I used DHTML to dynamically add the js and css files.
The search page was not portable to other directories. Of course paths returned by jsFind still point to hard coded locations. I’m going to have to use the root information to translate the locations to wherever they happen to be if the root moves (i.e. copied to a cdrom).
Then I got tired of that.
I still have to fix the portability issue, and write a script to do the search and replaces on all the html files in the corpus.
I’d like to keep the positional information and re-write mkIndex (in python) to store that information. Once I rewrote search.js to retrieve that information I could make a callback function that retrieved some context at least out of the html files to show results.
Once (if) that is done I’ll probably post that code up somewhere so others can use it if they have a need. Which is why I’m making this post to remind myself what I did when I document it.
Hi,
Can you post the code (if you still have it). I would like to explore it.
Thanks