In Web Application Development with Ontopia – 3. Creating the JSPs I claimed that
The next blog post will explain how to add a search page to our application.
Well, turns out it didn’t. I actually never wrote a post on that topic. Heck, the blog has been more or less dead for much of the last year.
A lot of things have happened in my life during the last year (moving to L.A., starting a new job in the US, etc.), but there sure hasn’t been much blogging going on. I do hope to get better at that, but doubt there will be too much on topic maps as I don’t spend much time tinkering about with this great technology anymore.
Anyway… I’ve recently received a couple of e-mails requesting information on how to query a topic map with Ontopia, and figured I’d better put my answer in a blog post for anyone to read.
tolog search
The easiest way to query a topic map with Ontopia is to use tolog and search for topics names/occurrence values using a simple tolog query. An example query would be:
select $TOPIC, $TYPE, $REL from
value-like($OBJ, "my search query", $REL),
{ topic-name($TOPIC, $OBJ) |
occurrence($TOPIC, $OBJ) },
direct-instance-of($TOPIC, $TYPE)
order by $REL desc, $TOPIC?
The result set from executing this query would contain the topic, it’s type and the relevancy score of the hit, sorted by relevance.
You can incorporate this into JSP files and make use of the taglibs from the tutorial for printing out results, linking to topic/type pages, etc.
Example files that will hopefully help getting you started (ZIP).
If you want to go further on the search (filtering etc.), you probably have to to more of it in Java code — using the APIs that Ontopia provides.