blogTag search

mtn's picture

You might have noticed the new link Tag search which directs you to a new page where you are asked to enter a query.

Julian and I have implemented a simple tag query language to be able to perform more complex searches over the tags:   This query will return all content which has the tag "tcp" but is not tagged with "udp" yielding in content only related to the TCP.

Here is another query simply to show you some other syntax:  

The features so far are:

  • Simple but powerful syntax
  • Auto completion
  • Highlighted error messages

Implementation

After little success with backends for lemon and JLex (the generated code did not work) we used the generators ([1], [2]) from the PEAR library.

The next hurdle was the code generation for MySQL. First we translate the strings into integer IDs to get faster query execution. This was the easy part.

The table layout was predefined by the taxonomy module. The first attempt was using SQL UNION and INTERSECT set operations to implement the boolean and, or and xor. It turned out, that MySQL up to version 5 does not support INTERSECT.

So only UNION could be used for the or. I decided to implement the and by doing a join and then using the WHERE clause "t1='term1' and t2='term2'". After that it took a long while to figure out the proper SQL-Slang for MySQL.

At some places it was necessary to do something like   in order to have no unnamed sub-queries. The error message was really bad but Google (once again) knew the answer :-)

After that we decided to add some sugar. This includes highlighting the parts of an erroneous query and, even more important, a powerful auto-completion using AJAX functionality built into Drupal. Julian said its implementation worked like a charm.

I hope you enjoy it!

Syndicate content