Quantcast

Searchable Plugin - Filtering by Category with subclasses

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Searchable Plugin - Filtering by Category with subclasses

micahcraig
Hi,

I'm trying to use the Searchable plugin to provide a search/filter/sort
interface on part of my domain, but I'm having some difficulty with my
approach.

I have a base domain class, Activity, with a few subclasses,
NumberActivity, ChoiceActivity and ResponseActivity.  The Activity
superclass defines a 'category' member of the type 'ActivityCategory'.  
Here are the relevant class definitions, somewhat simplified for
readability and relevance:

Activity.groovy:
package activity;
class Activity {
   String name
   ActivityCategory category

   static searchable = true
}
ActivityCategory.groovy:
package activity;

class ActivityCategory {
   String name

   static constraints = {
     name(nullable: false, blank: false)
   }

   static searchable = {
     name boost: 4.0
   }
}

My goal is to be able to search across all types of Activity (Number,
Response & Choice), but limit the results to Activity(s) of one of the
user selected ActivityCategory(s).  The problem is that the only
resource property I can find to search on is subclass specific, and
won't work across all classes of type Activity.

eg: '$/NumberActivity/category/id' or '$/ResponseActivity/category/id'
are available, but only match Activity(s) of their respective subclass
types.  What I would like would be something like
'$/Activity/category/id', but this doesn't work.


I feel as though there is probably a more straightforward means of
accomplishing what I'm trying to do, but I haven't been able to find
it.  I'm not certain that this sort of filtering is an ideal use of the
Lucene index, but full text search across multiple fields is a
requirement for this particular workflow, so it seemed like a good
match.  However, since at least for the filtering I'm really trying to
match on identity, the match against '..../category/id' seems awkward.

So, my questions are, first, Is this an appropriate use of
Searchable/Compass/Lucene, or should I be trying to use GORM/Hibernate
despite my text search requirements?  and second, How can I match
ActivityCategory(s) across all types of Activity?  Is there some trick
of mapping that will give me a consistent field name/resource property
across subclasses?

Thanks.  Any help or advice is very much appreciated.

     -micah

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Searchable Plugin - Filtering by Category with subclasses

John Stoneham
On Tue, Jun 1, 2010 at 3:44 PM, micah craig <[hidden email]> wrote:
> My goal is to be able to search across all types of Activity (Number,
> Response & Choice), but limit the results to Activity(s) of one of the user
> selected ActivityCategory(s).  The problem is that the only resource
> property I can find to search on is subclass specific, and won't work across
> all classes of type Activity.

You could map 'category' as a searchable component
(http://www.grails.org/Searchable+Plugin+-+Mapping+-+Searchable+Component)
and then search against it. Or, define a searchable transient property
(add getCategoryId(), add 'categoryId' to def transients), and have
Compass index that, then search against categoryId.

I've never used the $-prefix properties to search against, since my
application is also concerned with making the Compass query string
available to the user, but these would both be options you could use.

--
John Stoneham
[hidden email]

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...