Estás leyendo:
Informática

A little bug in Grails Searchable plugin


I’m going to develop -really, I’m in analysis of requirements phase, but we need a set of web tools for managing the legacy data infrastructure- a management scientific collections project and, after try a lot of web technologies, I select Grails. Grails offer, under my point of view, multiple advantages wich promote their election:

  • A solid and maintainable infrastructure for MVC web based projects
  • A dynamic and easily learn-to language: Groovy
  • A framework IoC based
  • A natural connection and integration with legacy Java systems and Java libraries
  • A integration with ORM persistence (here, hibernate)
  • Finally, a facility for add multiple (GNU) plugins.

This last facility has been which has permitted to integrate easily a search service based of lucene engine. Lucene is a strong search engine for multiple search types: by generic match, or by substrings…over all the data or over a specific column…searching with wildcards and concatenation operators… and all over a only textbox.

The grails plugin is the searchable plugin. Once has been  installed in our grails project, the declaration in a domain groovy class makes the container inyect the Searchable class and then It can be utilized by the controller class for generate a search method.

Searchable has two first methods applied how static domain class methods (ClassSearchable.search() and ClassSearchable.searcEvery()), search and searchEvery, wich deliver a resultSearch object but at two distinct faces:

  • A paginate object
  • A full list hits object

If You wants to show a paginate list, the search first method is the ideal candidate. Else if You was thinking at a persistent memory object -like a file, the second search method is the best.

In my project, It was possible a search without a knowledge of the exact term. There, the use of wildcards  are necessary. Moreover, was intended than If the result of search It was a empty list, another suggested query could be indicated.

But I had seen that anything was not well. No suggests occurred when the find pattern contained a wildcard. The debug process indicates a null resultSearch…I don’t understander.

I tried to eliminate the suggested query indication…argg..else It ran! I googled and then I seen that It’s a plugin bug…and I think is not yet parched😦 .

The solution is not fine: I find a null searchResult for activate the suggest query option. This is the code:

    def search = {
        try {
            def query=params.q?:flash.queryString
            params.q=flash.queryString
            if (!query) {
                flash.message="No hay parámetros. Reconstruya la consulta..."
                redirect(action:"index")
                return [:]
            }
            params.max = Math.min(params.max ? params.int('max') : 17, 100)
            //ojo a suggestQuery (param) y suggestedQuery (property)

            def searchResult = Catalogo.search(query,params)
            flash.queryString = query
            //OJO: Hasta que no se obtenga la búsqueda, no se puede generar la consulta
            //con sugerencia, porque si no peta si q lleva wildCards -es un bug del plugin-
            if(searchResult.total==0){
                params.suggestQuery = true
                searchResult = Catalogo.search(query,params)
                def sugerida = searchResult.suggestedQuery
                flash.message = sugerida
            }
            return [searchResult: searchResult, params:params]
        }
        catch (e) {
            return [searchError: true]
        }
    }

I’d like you to be useful. Regards squids!

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Lo leyeron y comentaron

Top Clicks

  • None

Flickr Photos







More Photos
%d bloggers like this: