The Artima Developer Community
Sponsored Link

Java Buzz Forum
Lucene Components for Spring

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Lucene Components for Spring Posted: Apr 11, 2005 7:00 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Lucene Components for Spring
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

Matt and Dion already spilled the beans, so here's the chili: a bunch of stuff to make using Lucene from Spring more convenient:

public void testDemonstration() throws Exception
{
    LuceneTemplate lucene = (LuceneTemplate) beans.getBean("lucene");
    Document one = new Document();
    one.add(Field.Text("name", "Brian McCallister"));

    Document two = new Document();
    two.add(Field.Text("name", "Eric McCallister"));
    lucene.addDocuments(new Document[] {one, two});

    Document[] results = lucene.searchForDocuments(lucene.parseQuery("Eric", "name"));
    assertEquals(1, results.length);
    assertEquals("Eric McCallister", results[0].get("name"));
}

There are other convenience methods, callback handlers for readers, writers, and searchers which managed opening/closing, etc on the LuceneTemplate, and factory beans for direct access to components without going through the template, but that is a nice example. The Spring config used for this test is:

<beans>
    <bean id="directory" class="org.skife.spring.lucene.RAMDirectoryBean"/>

<!-- <bean id="directory" class="org.skife.spring.lucene.FSDirectoryBean"> -->
<!--   <property name="location"><value>/tmp</value></property>            -->
<!-- </bean>                                                               -->

    <bean id="analyzer" class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>

    <bean id="template" class="org.skife.spring.lucene.LuceneTemplate">
        <property name="directory"><ref bean="directory"/></property>
        <property name="analyzer"><ref bean="analyzer"/></property>
    </bean>
</beans>

The fun part is that the components work with Spring transactions (via readers and writers LuceneUtils, which the template uses as well), so that if you index documents inside a transaction, then roll it back, they aren't added. Ditto removing docs, etc. This is awfully handy if you do things like handle document indexing via an interceptor on your DAO ;-)

Haven't figured out where the code will be hosted, yet. There isn't much. I've offered it to the Spring folks, and have had Spring Modules suggested, but haven't thought hard about anything.

So until then, you can grab the jar (only dependencies are Spring and Lucene) and sources from me, and see the API docs. My apologies for not having a source download -- it was developed as part of another project, and the build and sources are all in there (and I'm too lazy to split out a seperate project since I hope to host it somewhere else =). Until it finds a home, I'll keep pushing stuff to the aforementioned links as I make significant changes.

Read: Lucene Components for Spring

Topic: RE: Going to work for Microsoft Previous Topic   Next Topic Topic: Guidelines for creating GUIs, part 1...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use