Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Commits List »

[hibernate-commits] Hibernate SVN: r15335 - in search/trunk:
 src/java/org/hibernate/search/impl and 9 other directories.

hibernate-commits

2008-10-13


Author LoginPost Reply
Author: hardy.ferentschik
Date: 2008-10-13 05:51:41 -0400 (Mon, 13 Oct 2008)
New Revision: 15335

Added:
 search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java
 search/trunk/src/test-resources/org/
 search/trunk/src/test-resources/org/hibernate/
 search/trunk/src/test-resources/org/hibernate/search/
 search/trunk/src/test-resources/org/hibernate/search/test/
 search/trunk/src/test-resources/org/hibernate/search/test/analyzer/
 search/trunk/src/test-resources/org/hibernate/search/test/analyzer/solr/
 search/trunk/src/test-resources/org/hibernate/search/test/analyzer/solr/stoplist.properties
Removed:
 search/trunk/src/test/org/hibernate/search/test/analyzer/solr/stoplist.properties
Modified:
 search/trunk/ivy.xml
 search/trunk/pom.xml
 search/trunk/src/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java
Log:
HSEARCH-254
* Upgraded to Lucene 2.4.0
* Upgraded to Solr 1.3.0
* Updated analyzer builder
* moved the properties file stoplist.properties into test-resources

Modified: search/trunk/ivy.xml
===================================================================
--- search/trunk/ivy.xml  2008-10-13 09:24:31 UTC (rev 15334)
+++ search/trunk/ivy.xml  2008-10-13 09:51:41 UTC (rev 15335)
@@(protected) @@
     <dependency org="org.slf4j" name="slf4j-api" rev="1.4.2" conf="default->default"/>    
     <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR2" conf="default->default"/>
     <dependency org="javax.transaction" name="jta" rev="1.1" conf="default->default"/>
-     <dependency org="org.apache.lucene" name="lucene-core" rev="2.3.2" conf="default->default"/>
+     <dependency org="org.apache.lucene" name="lucene-core" rev="2.4.0" conf="default->default"/>
     <dependency org="javax.jms" name="jms" rev="1.1" conf="default->default"/> <!-- optional -->
     <dependency org="javax.annotation" name="jsr250-api" rev="1.0" conf="default->default"/> <!-- optional -->
-     <dependency org="org.hibernate.apache.lucene.solr" name="apache-solr-analyzer" rev="1.2.0" conf="default->default"/> <!-- optional -->
+     <dependency org="org.apache.solr" name="solr-core" rev="1.3.0" conf="default->default"/>
+     <dependency org="org.apache.solr" name="solr-common" rev="1.3.0" conf="default->default"/>
+     <!--dependency org="org.hibernate.apache.lucene.solr" name="apache-solr-analyzer" rev="1.3.0" conf="default->default"/-->

     <!-- transitive dependencies -->
     <dependency org="antlr" name="antlr" rev="2.7.6" conf="test->default"/>

Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml  2008-10-13 09:24:31 UTC (rev 15334)
+++ search/trunk/pom.xml  2008-10-13 09:51:41 UTC (rev 15335)
@@(protected) @@
     <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
-        <version>2.3.2</version>
+        <version>2.4</version>
     </dependency>
     <dependency>
        <groupId>org.slf4j</groupId>
@@(protected) @@
        <optional>true</optional>
     </dependency>
     <dependency>
-        <groupId>org.hibernate.apache.lucene.solr</groupId>
-        <artifactId>apache-solr-analyzer</artifactId>
-        <version>1.2.0</version>
+        <groupId>org.apache.solr</groupId>
+        <artifactId>solr-common</artifactId>
+        <version>1.3.0</version>
        <optional>true</optional>
     </dependency>
+     <dependency>
+        <groupId>org.apache.solr</groupId>
+        <artifactId>solr-core</artifactId>
+        <version>1.3.0</version>
+        <optional>true</optional>
+     </dependency>


     <dependency>

Modified: search/trunk/src/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java  2008-10-13 09:24:31 UTC (rev 15334)
+++ search/trunk/src/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java  2008-10-13 09:51:41 UTC (rev 15335)
@@(protected) @@
import org.apache.solr.analysis.TokenizerChain;
import org.apache.solr.analysis.TokenFilterFactory;
import org.apache.solr.analysis.TokenizerFactory;
+import org.apache.solr.util.plugin.ResourceLoaderAware;
+import org.apache.solr.common.ResourceLoader;

import org.hibernate.search.annotations.AnalyzerDef;
import org.hibernate.search.annotations.TokenizerDef;
import org.hibernate.search.annotations.TokenFilterDef;
import org.hibernate.search.annotations.Parameter;
import org.hibernate.search.SearchException;
+import org.hibernate.search.util.HibernateSearchResourceLoader;

/**
- * This class has a direct dependency on Solr classes
+ * Instances of this class are used to build Lucene analyzers which are defined using the solr <code>TokenFilterFactory</code>.
+ * To make the dependency to the solr framework optional only this class has direct dependecies to solr. Solr dependencies
+ * are not supposed to be used anywhere else (except the actual configuration of the analzers in the domain model).
*
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
class SolrAnalyzerBuilder {
 private SolrAnalyzerBuilder() {}

+  /**
+   * Builds a Lucene <code>Analyzer</code> from the specified <code>AnalyzerDef</code> annotation.
+   *
+   * @param analyzerDef The <code>AnalyzerDef</code> annotation as found in the annotated domain class.
+   * @return a Lucene <code>Analyzer</code>
+   */
 public static Analyzer buildAnalyzer(AnalyzerDef analyzerDef) {
   TokenizerDef token = analyzerDef.tokenizer();
   TokenizerFactory tokenFactory = ( TokenizerFactory ) instantiate( token.factory() );
@@(protected) @@

   final int length = analyzerDef.filters().length;
   TokenFilterFactory[] filters = new TokenFilterFactory[length];
+    ResourceLoader resourceLoader = new HibernateSearchResourceLoader();
   for ( int index = 0 ; index < length ; index++ ) {
     TokenFilterDef filterDef = analyzerDef.filters()[index];
     filters[index] = (TokenFilterFactory) instantiate( filterDef.factory() );
     filters[index].init( getMapOfParameters( filterDef.params() ) );
+      if ( filters[index] instanceof ResourceLoaderAware ) {
+        ((ResourceLoaderAware)filters[index]).inform( resourceLoader );
+      }
   }
   return new TokenizerChain(tokenFactory, filters);
 }

Added: search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java                  (rev 0)
+++ search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java  2008-10-13 09:51:41 UTC (rev 15335)
@@(protected) @@
+package org.hibernate.search.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import java.io.Reader;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.apache.solr.common.ResourceLoader;
+import org.apache.solr.util.plugin.ResourceLoaderAware;
+
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.search.SearchException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class HibernateSearchResourceLoader implements ResourceLoader {
+  public InputStream openResource(String resource) throws IOException {
+    return Thread.currentThread().getContextClassLoader().getResourceAsStream( resource );
+  }
+
+  public List<String> getLines(String resource) throws IOException {
+    BufferedReader reader = null;
+    try {
+      reader = new BufferedReader( new InputStreamReader( openResource( resource ) ) );
+      List<String> results = new ArrayList<String>();
+      String line = reader.readLine();
+      while ( line != null ) {
+        //comment or empty line
+        if ( line.length() != 0 && !line.startsWith( "#" ) ) {
+          results.add( line );
+        }
+        line = reader.readLine();
+      }
+      return Collections.unmodifiableList( results );
+    }
+    finally {
+      try {
+        if (reader != null) reader.close();
+      }
+      catch ( Exception e ) {
+        //we don't really care if we can't close
+      }
+    }
+  }
+
+  public Object newInstance(String cname, String... subpackages) {
+    if (subpackages != null && subpackages.length > 0)
+      throw new UnsupportedOperationException( "newInstance(classname, packages) not implemented" );
+
+    final Class<?> clazz;
+    try {
+      clazz = ReflectHelper.classForName( cname );
+    }
+    catch ( ClassNotFoundException e ) {
+      throw new SearchException("Unable to find class " + cname, e);
+    }
+    try {
+      final Object instance = clazz.newInstance();
+      if (instance instanceof ResourceLoaderAware) {
+        ( ( ResourceLoaderAware) instance ).inform( this );
+      }
+      return instance;
+    }
+    catch ( InstantiationException e ) {
+      throw new SearchException("Unable to instanciate class with no-arg constructor: " + cname, e);
+    }
+    catch ( IllegalAccessException e ) {
+      throw new SearchException("Unable to instanciate class with no-arg constructor: " + cname, e);
+    }
+  }
+}

Deleted: search/trunk/src/test/org/hibernate/search/test/analyzer/solr/stoplist.properties
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/analyzer/solr/stoplist.properties  2008-10-13 09:24:31 UTC (rev 15334)
+++ search/trunk/src/test/org/hibernate/search/test/analyzer/solr/stoplist.properties  2008-10-13 09:51:41 UTC (rev 15335)
@@(protected) @@
-a
-an
-and
-are
-as
-at
-be
-but
-by
-for
-if
-in
-into
-is
-it
-no
-not
-of
-on
-or
-such
-that
-the
-their
-then
-there
-these
-they
-this
-to
-was
-will
-with
\ No newline at end of file

Added: search/trunk/src/test-resources/org/hibernate/search/test/analyzer/solr/stoplist.properties
===================================================================
--- search/trunk/src/test-resources/org/hibernate/search/test/analyzer/solr/stoplist.properties                  (rev 0)
+++ search/trunk/src/test-resources/org/hibernate/search/test/analyzer/solr/stoplist.properties  2008-10-13 09:51:41 UTC (rev 15335)
@@(protected) @@
+a
+an
+and
+are
+as
+at
+be
+but
+by
+for
+if
+in
+into
+is
+it
+no
+not
+of
+on
+or
+such
+that
+the
+their
+then
+there
+these
+they
+this
+to
+was
+will
+with
\ No newline at end of file

_______________________________________________
hibernate-commits mailing list
hibernate-commits@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-commits
©2008 gg3721.com - Jax Systems, LLC, U.S.A.