Login | About | Page IndexHome | Manual | Publications | Download | Support

Search

WebDSL supports simple search capabilities through Lucene. Entity properties can be marked as "searchable" to subsequently be indexed:

    entity Message {
      subject :: String (searchable)
      text    :: Text   (searchable)
    }

The searchable can be applied to the following built-in WebDSL types: String, Text, WikiText, Int, Long, Float and date types.

If one or more properties of an entity are marked as searchable, a set of searchEntity functions are generated, in this case:

    function searchMessage(query : String) : List<Message>
    function searchMessage(query : String, limit : Int)
                                 : List<Message>
    function searchMessage(query : String, limit : Int,
                           offset : Int) : List<Message>

Which can be used from anywhere. For instance on a search page:

    define page search(query : String) {
      var newQuery : String := query;
      action doSearch() {
        return search(newQuery);
      }

      title { "Search" }
      form {
        input(newQuery)
        submit("Search", doSearch())
      }
      for(m : Message in searchMessage(query, 50)) {
        output(m)
      }
    }

The query syntax adheres to Lucene's query syntax as does the scoring.

Index location

WebDSL stores its search index in the /var/indexes/APPNAME directory. This is currently not configurable. Make sure this directory is readable and writeable for the user that runs tomcat.

Indexing

When the searchable annotations are added to a property after data is already in the database, the search index has to be recreated. When your application has been deployed, go to the directory in which it was extracted, for instance /var/tomcat/webapps/yourapp. In this directory you will find a webdsl-reindex script. Run this script as root:

    # sh webdsl-reindex

A demo of the search functionality can be seen on TweetView


powered by WebDSL