Specific Indexing

2008 March 20
tags:
by Shay Banon

Compass supports the ability to completely index external content (for example, a database mapped using an ORM) using very simple API:

1
2
ComapssGps gps = // ...
gps.index();

This indexing process is a parallel indexing process (by default) based on the number of sub indexes, and will go and fetch all the data mapped using the ORM tool and index it using Compass. The old content of the index (for all types) will be replaced by the new content.

Some Compass users have suggested a (very) valid feature request of being able to just index specific types. So now, this feature is available in trunk (todays nightly will have it). Here is what it looks like:

1
2
ComapssGps gps = // ...
gps.index(Person.class, Account.class);

This will only index the Person class and Account class data (in parallel if possible) and replace only their respective sub indexes. The rest of the index will remain the same.

Now, the only thing left is for the Grails Searchable Plugin to enable it so people will be able to this: Person.index() in groovy.

Finally I can go to bed ;)

7 Responses leave one →
  1. 2008 March 21

    Shay, what is the reason for such function? If I am not mistaken the Compass indexes all classes having specific annotation (while these classes also have to be added into classMappings list). Does it mean that I can use this new function to force complete re-indexing data for specific class only (and this class has to have annotation and is included in the mappings list - of course)? In other words this function allows me to rebuild portion (aka subindex) of whole index from the scratch, correct? Is there any other use case?

  2. 2008 March 21

    Yes, that is basically what it does.

  3. 2008 March 21

    This is awesome work!

  4. 2008 March 22
    Maurice Nicholson permalink

    Actually the Grails Searchable Plugin already has quite rich index management capabilities ;-)

    It is possible to do stuff like:

    Person.indexAll() // indexes all Person instances
    Person.unindexAll() removes all Person instances from the index

    person.index() // indexes a specific Person instance

    Person.index(john, mary, kate) // indexes specific instances
    Person.index(1l, 2l, 3l) // indexes specific instances by id

    searchableService.reindexAll() // do a complete index (using compassGps.index())

    searchableService.index([class: Post], 1l, 2l, 3l) // index specific instances of Post by id using the service interface

    And more…

    See http://grails.org/Searchable+Plugin+-+Managing+the+index

  5. 2008 March 22

    Interesting… . How do you implement Person.indexAll()? Is it similar to what suggested in this blog post?

  6. 2008 March 22
    Maurice Nicholson permalink

    Actually I just checked the code and Person.indexAll() isn’t supported for performance reasons! My bad.

    So I definitely need this feature in the plugin :-)

  7. 2008 April 2
    Ben Dotte permalink

    Awesome.. I’ve had requests for this feature from co-workers many times. Thanks Shay!

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS