Author: sannegrinovero
Date: 2011-01-07 12:14:55 -0500 (Fri, 07 Jan 2011)
New Revision: 13977
Added:
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/IndexerAction.java
Modified:
branches/community/Seam_2_2/examples/build.xml
branches/community/Seam_2_2/examples/dvdstore/
branches/community/Seam_2_2/examples/dvdstore/build-jboss42.xml
branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml
branches/community/Seam_2_2/examples/dvdstore/build.xml
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java
branches/community/Seam_2_2/examples/dvdstore/readme.txt
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Actor.java
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Category.java
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/FullTextSearchAction.java
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/IndexerAction.java
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Product.java
Log:
JBSEAM-4759 - update DVD-Store example to show new Hibernate Search features - and fix old
issues
Modified: branches/community/Seam_2_2/examples/build.xml
===================================================================
--- branches/community/Seam_2_2/examples/build.xml 2011-01-07 16:34:24 UTC (rev 13976)
+++ branches/community/Seam_2_2/examples/build.xml 2011-01-07 17:14:55 UTC (rev 13977)
@@ -357,13 +357,32 @@
<include name="jgroups.jar" if="cache.lib" />
</fileset>
+ <!-- Hibernate Search requires different dependencies since version 3.3
+ (minimal suggested version for JBossAS 6 ) -->
+ <condition property="search.lib.jb6">
+ <and>
+ <isset property="jboss6"/>
+ <isset property="search.lib"/>
+ </and>
+ </condition>
+ <condition property="search.lib.jb5">
+ <and>
+ <not>
+ <isset property="jboss6"/>
+ </not>
+ <isset property="search.lib"/>
+ </and>
+ </condition>
+
<!-- Dependencies for using Seam with Hibernate Search -->
<fileset id="search.jar" dir="${lib.search.dir}">
<include name="lucene-core.jar" if="search.lib" />
- <include name="lucene-analyzers.jar" if="search.lib"/>
+ <include name="lucene-analyzers.jar" if="search.lib" />
<include name="hibernate-search.jar" if="search.lib" />
- <include name="hibernate-search-analyzers.jar"
if="search.lib"/>
- <include name="hibernate-commons-annotations.jar"
if="search.lib" />
+ <include name="solr-core.jar" if="search.lib" />
+ <include name="solr-lucene-analyzers.jar" if="search.lib.jb5"
/>
+ <include name="hibernate-search-analyzers.jar"
if="search.lib.jb6"/>
+ <include name="hibernate-commons-annotations.jar"
if="search.lib.jb5" />
<!-- <include name="hibernate-core.jar" if="search.lib" />
remove or add condition for jboss42 only -->
</fileset>
@@ -647,17 +666,37 @@
<mkdir dir="${dist.dir}" />
</target>
- <target name="copyextradependencies" depends="gettrinidad,
getmetawidget, getelri, gethsearch3.3"/>
+ <target name="copyextradependencies" depends="gettrinidad,
getmetawidget, getelri, gethsearch3.3, gethsearch3.1" />
<target name="getmetawidget"
depends="getmetawidget-war,getmetawidget-ear"/>
- <target name="gethsearch3.3" if="jboss6">
+ <target name="gethsearch3.3" if="jboss6">
<copyInlineDependencies id="org.hibernate.search"
scope="runtime" todir="${example.lib.dir}">
<dependency groupId="org.hibernate"
artifactId="hibernate-search" version="3.3.0.Final">
<exclusion groupId="org.hibernate"
artifactId="hibernate-core"/>
</dependency>
+ <dependency groupId="org.hibernate"
artifactId="hibernate-search-analyzers" version="3.3.0.Final" />
</copyInlineDependencies>
- </target>
+ </target>
+
+ <target name="gethsearch3.1" unless="jboss6">
+ <copyInlineDependencies id="org.hibernate.search"
scope="runtime" todir="${example.lib.dir}">
+ <dependency groupId="org.apache.solr" artifactId="solr-core"
version="1.3.0">
+ <exclusion groupId="commons-httpclient"
artifactId="commons-httpclient" />
+ <exclusion groupId="org.apache.solr" artifactId="solr-solrj"
/>
+ <exclusion groupId="org.apache.solr"
artifactId="solr-lucene-queries" />
+ <exclusion groupId="org.apache.solr"
artifactId="solr-lucene-core" />
+ <exclusion groupId="org.apache.solr"
artifactId="solr-lucene-highlighter" />
+ <exclusion groupId="org.apache.solr"
artifactId="solr-lucene-spellchecker" />
+ <exclusion groupId="org.apache.solr"
artifactId="solr-lucene-snowball" />
+ <exclusion groupId="org.apache.solr"
artifactId="solr-commons-csv" />
+ <exclusion groupId="woodstox" artifactId="wstx-asl" />
+ <exclusion groupId="net.java.dev.stax-utils"
artifactId="stax-utils" />
+ <exclusion groupId="commons-logging"
artifactId="commons-logging" />
+ <exclusion groupId="org.apache.geronimo.specs"
artifactId="geronimo-stax-api_1.0_spec" />
+ </dependency>
+ </copyInlineDependencies>
+ </target>
<target name="getmetawidget-war" if="metawidget-war.lib">
<copyInlineDependencies id="metawidget" scope="runtime"
todir="${lib.dir}">
@@ -1102,7 +1141,7 @@
<fileset refid="wicket-extensions.jar" />
<fileset refid="wicket-datetime.jar" />
<fileset refid="seam.wicket.jar" />
- <fileset refid="seam.resteasy.jar" />
+ <fileset refid="seam.resteasy.jar" />
<fileset refid="trinidad-api.jar" />
<fileset refid="metawidget.jar" />
<fileset refid="el-ri.jar"/>
Property changes on: branches/community/Seam_2_2/examples/dvdstore
___________________________________________________________________
Name: svn:ignore
- build
test-build
dist
exploded-archives
dvdindexes
+ build
test-build
dist
exploded-archives
dvdindexes
staging-jbossas6
exploded-archives-jbossas6
dist-jbossas6
Modified: branches/community/Seam_2_2/examples/dvdstore/build-jboss42.xml
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/build-jboss42.xml 2011-01-07 16:34:24
UTC (rev 13976)
+++ branches/community/Seam_2_2/examples/dvdstore/build-jboss42.xml 2011-01-07 17:14:55
UTC (rev 13977)
@@ -1,9 +1,35 @@
<?xml version="1.0"?>
<project name="DVDStore" default="deploy"
basedir=".">
+
+ <!-- Naming -->
+ <property name="Name" value="Seam Dvd Store
Example"/>
+ <property name="example.name"
value="jboss-seam-dvdstore"/>
+ <!-- Libraries -->
+ <property name="seam.ui.lib" value="yes" />
+ <property name="seam.debug.lib" value="yes" />
+ <property name="facelets.lib" value="yes" />
+ <property name="jbpm.lib" value="yes" />
+ <property name="search.lib" value="yes" />
+ <property name="urlrewrite.lib" value="yes"/>
<property name="han.lib" value="yes"/>
+ <target name="init" depends="gethsearch3.1">
+ <fileset id="ear.lib.extras" dir="${example.lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <antcall target="SeamExample.init"/>
+ <path id="build.classpath.extras">
+ <fileset dir="${lib.search.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="${example.lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+ </target>
+
<import file="../build.xml"/>
</project>
Modified: branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml 2011-01-07 16:34:24 UTC
(rev 13976)
+++ branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml 2011-01-07 17:14:55 UTC
(rev 13977)
@@ -3,7 +3,7 @@
<!-- Naming -->
<property name="Name" value="Seam Dvd Store
Example"/>
- <property name="example.name"
value="jboss-seam-dvdstore"/>
+ <property name="example.name"
value="jboss-seam-dvdstore"/>
<property name="jboss6" value="yes"/>
<!-- Libraries -->
<property name="seam.ui.lib" value="yes" />
@@ -29,9 +29,12 @@
<fileset includes="**" dir="jboss6/src" />
</copy>
<copy todir="${src.java.dir}">
- <fileset includes="**"
excludes="src/com/jboss/dvd/seam/FullTextSearchAction.java"
dir="src"/>
- </copy>
-
+ <fileset dir="src">
+ <include name="**" />
+ <exclude name="src/com/jboss/dvd/seam/FullTextSearchAction.java" />
+ <exclude name="src/com/jboss/dvd/seam/IndexerAction.java" />
+ </fileset>
+ </copy>
</target>
<import file="../build.xml"/>
Modified: branches/community/Seam_2_2/examples/dvdstore/build.xml
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/build.xml 2011-01-07 16:34:24 UTC (rev
13976)
+++ branches/community/Seam_2_2/examples/dvdstore/build.xml 2011-01-07 17:14:55 UTC (rev
13977)
@@ -12,13 +12,27 @@
<property name="facelets.lib" value="yes" />
<property name="jbpm.lib" value="yes" />
<property name="search.lib" value="yes" />
- <property name="urlrewrite.lib" value="yes"/>
+ <property name="urlrewrite.lib" value="yes"/>
+ <property name="example.lib.dir" value="lib"/>
<!-- Datasource -->
- <property name="example.ds" value="jboss-seam-dvdstore-ds.xml"
/>
-
- <import file="../build.xml" />
-
+ <property name="example.ds" value="jboss-seam-dvdstore-ds.xml"
/>
+
+ <target name="init" depends="gethsearch3.1">
+ <fileset id="ear.lib.extras" dir="${example.lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <antcall target="SeamExample.init"/>
+ <path id="build.classpath.extras">
+ <fileset dir="${lib.search.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="${example.lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+ </target>
+
<!-- Exclude the DS from validated files, as the mbean causes it not to validate
-->
<fileset id="validate.resources"
dir="${validate.resources.dir}">
<include name="META-INF/application.xml" />
@@ -45,4 +59,6 @@
<ant antfile="build-jboss6.xml"/>
</target>
+ <import file="../build.xml" />
+
</project>
Modified:
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -9,28 +9,32 @@
import javax.ejb.Remove;
import javax.ejb.Stateful;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.queryParser.MultiFieldQueryParser;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.util.Version;
+import org.apache.lucene.search.Query;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.FullTextQuery;
+import org.hibernate.search.query.dsl.QueryBuilder;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.datamodel.DataModel;
+import org.jboss.seam.log.Log;
/**
- * Hibernate Search version of the store querying mechanism
+ * Hibernate Search version of the store querying mechanism.
+ * This version is updated to show the new Query capabilities
+ * of Hibernate Search 3.3, which requires Hibernate 3.6 and
+ * as such is the recommended (minimal) version to use for JBoss6.
+ * This code resides in a separate src directory as it wouldn't
+ * compile with older Hibernate Search versions.
+ *
* @author Emmanuel Bernard
+ * @author Sanne Grinovero
*/
@Stateful
@Name("search")
@@ -43,8 +47,16 @@
@In(create=true)
ShoppingCart cart;
- @PersistenceContext
- EntityManager em;
+ /**
+ * Note that when using Seam's injection the entityManager
+ * can be assigned directly to a FullTextEntityManager.
+ * Same trick applies to FullTextSession.
+ */
+ @In
+ FullTextEntityManager entityManager;
+
+ @Logger
+ Log log;
//@RequestParameter
Long id;
@@ -107,7 +119,7 @@
@Begin(join = true)
public void selectFromRequest() {
if (id != null) {
- dvd = em.find(Product.class, id);
+ dvd = entityManager.find(Product.class, id);
} else if (selectedProduct != null) {
dvd = selectedProduct;
}
@@ -123,12 +135,7 @@
@SuppressWarnings("unchecked")
private void updateResults() {
- FullTextQuery query;
- try {
- query = searchQuery(searchQuery);
- } catch (ParseException pe) {
- return;
- }
+ FullTextQuery query = searchQuery(searchQuery);
List<Product> items = query
.setMaxResults(pageSize + 1)
.setFirstResult(pageSize * currentPage)
@@ -146,22 +153,38 @@
searchSelections = new HashMap<Product, Boolean>();
}
- private FullTextQuery searchQuery(String searchQuery) throws ParseException
- {
- Map<String,Float> boostPerField = new HashMap<String,Float>();
- boostPerField.put("title", 4f);
- boostPerField.put("description", 2f);
- boostPerField.put("actors.name", 2f);
- boostPerField.put("categories.name", 0.5f);
-
- String[] productFields = {"title", "description",
"actors.name", "categories.name"};
+ private FullTextQuery searchQuery(String textQuery) {
+ QueryBuilder queryBuilder = entityManager.getSearchFactory()
+ .buildQueryBuilder().forEntity(Product.class).get();
- Analyzer defaultAnalyzer = ((FullTextEntityManager)
em).getSearchFactory().getAnalyzer(Product.class);
- QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_30, productFields,
defaultAnalyzer, boostPerField);
-
- parser.setAllowLeadingWildcard(true);
- org.apache.lucene.search.Query luceneQuery = parser.parse(searchQuery);
- return ( (FullTextEntityManager) em ).createFullTextQuery(luceneQuery,
Product.class);
+ //Hibernate Search fulltext query example:
+
+ //query to match exact terms occurrence, using custom boosts:
+ Query queryToFindExactTerms = queryBuilder.keyword()
+ .onFields("title").boostedTo(4f)
+ .andField("description").boostedTo(2f)
+ .andField("actors.name").boostedTo(2f)
+ .andField("categories.name").boostedTo(0.5f)
+ .matching(textQuery)
+ .createQuery();
+
+ //Similar query, but using NGram matching instead of exact terms:
+ Query queryToFindMathingNGrams = queryBuilder.keyword()
+ .onFields("title:ngrams").boostedTo(2f)
+ .andField("description:ngrams")
+ .andField("actors.name:ngrams")
+ .andField("categories.name:ngrams").boostedTo(0.2f)
+ .matching(textQuery)
+ .createQuery();
+
+ //Combine them for best results, note exact uses an higher boost:
+ Query fullTextQuery = queryBuilder.bool()
+ .should(queryToFindMathingNGrams)
+ .should(queryToFindExactTerms)
+ .createQuery();
+
+ log.info("Executing fulltext query {0}", fullTextQuery);
+ return entityManager.createFullTextQuery(fullTextQuery, Product.class);
}
/**
Added:
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/IndexerAction.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/IndexerAction.java
(rev 0)
+++
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/IndexerAction.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -0,0 +1,56 @@
+package com.jboss.dvd.seam;
+
+import java.util.Date;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+
+import org.hibernate.search.jpa.FullTextEntityManager;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+
+/**
+ * At startup we need to reindex all entities from the database.
+ * This is an optional step in a real application, we need it in
+ * the demo as the database is volatile and was just filled
+ * with a SQL dump (see import.sql).
+ *
+ * @author Sanne Grinovero
+ */
+@Name("indexer")
+@Stateful
+(a)Scope(ScopeType.APPLICATION)
+@Startup
+public class IndexerAction implements Indexer
+{
+
+ private Date lastIndexingTime;
+
+ @In
+ private FullTextEntityManager entityManager;
+
+ public Date getLastIndexingTime()
+ {
+ return lastIndexingTime;
+ }
+
+ @Create
+ public void index()
+ {
+ // Re-build the index for the whole database:
+ entityManager
+ .createIndexer()
+ .start();
+ lastIndexingTime = new Date();
+ }
+
+ @Remove
+ @Destroy
+ public void stop() {}
+
+}
Modified: branches/community/Seam_2_2/examples/dvdstore/readme.txt
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/readme.txt 2011-01-07 16:34:24 UTC (rev
13976)
+++ branches/community/Seam_2_2/examples/dvdstore/readme.txt 2011-01-07 17:14:55 UTC (rev
13977)
@@ -7,9 +7,10 @@
process management. It runs on JBoss AS as an EAR and Tomcat with Embedded
JBoss as a WAR.
-JBoss AS 4.2 needs additional hibernate libraries, use ant target jboss42 for deploying
to it.
+JBoss AS 4.2 needs additional Hibernate libraries, use ant target jboss42 for deploying
to it.
-JBoss AS 6 needs new hibernate search and hibernate-commons-annotations, and more source
code enhancement due Hibernate Search and Lucene-Core
-API changes. Therefore use ant target jboss6 for deploying to JBoss AS 6 M5 and later.
For instance:
+JBoss AS 6 needs new hibernate-search and hibernate-commons-annotations, and more source
code
+enhancement due to Hibernate Search and Apache Lucene API changes.
+Therefore use ant target jboss6 for deploying to JBoss AS 6 M5 and later. For instance:
ant -f build-jboss6.xml
Modified:
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml 2011-01-07
17:14:55 UTC (rev 13977)
@@ -19,11 +19,7 @@
value="org.hibernate.search.store.FSDirectoryProvider"/>
<!-- directory where the indexes will be stored -->
<property name="hibernate.search.default.indexBase"
value="./dvdindexes"/>
- <!-- Not needed with HA 3.3
- <property name="hibernate.ejb.event.post-insert"
value="org.hibernate.search.event.FullTextIndexEventListener"/>
- <property name="hibernate.ejb.event.post-update"
value="org.hibernate.search.event.FullTextIndexEventListener"/>
- <property name="hibernate.ejb.event.post-delete"
value="org.hibernate.search.event.FullTextIndexEventListener"/>
- -->
+
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/dvdstoreEntityManagerFactory" />
</properties>
Modified: branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Actor.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Actor.java 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Actor.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -14,8 +14,10 @@
import javax.persistence.Id;
import javax.persistence.Table;
+import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Fields;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
@@ -41,7 +43,9 @@
}
@Column(name="NAME", length=50)
- @Field(index = Index.TOKENIZED)
+ @Fields({
+ @Field(index=Index.TOKENIZED),
+ @Field(index=Index.TOKENIZED, name="name:ngrams",
analyzer=@Analyzer(definition="ngrams"))})
public String getName() {
return name;
}
Modified:
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Category.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Category.java 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Category.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -16,8 +16,10 @@
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Fields;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
@@ -43,7 +45,9 @@
}
@Column(name="NAME",nullable=false,unique=true,length=50)
- @Field(index = Index.TOKENIZED)
+ @Fields({
+ @Field(index=Index.TOKENIZED),
+ @Field(index=Index.TOKENIZED, name="name:ngrams",
analyzer=@Analyzer(definition="ngrams"))})
public String getName() {
return name;
}
Modified:
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/FullTextSearchAction.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/FullTextSearchAction.java 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/FullTextSearchAction.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -27,9 +27,13 @@
import org.hibernate.search.jpa.FullTextEntityManager;
/**
- * Hibernate Search version of the store querying mechanism
+ * Hibernate Search version of the store querying mechanism.
+ * (Old version: see FullTextSearchAction implementation in the
+ * jboss6 additional source folder to see usage of new Search API)
+ *
* @author Emmanuel Bernard
*/
+@Deprecated
@Stateful
@Name("search")
public class FullTextSearchAction
Modified:
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/IndexerAction.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/IndexerAction.java 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/IndexerAction.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -19,7 +19,9 @@
import org.jboss.seam.annotations.Startup;
/**
- * Re index the needed entities
+ * Re index the needed entities.
+ * (Old version: see IndexerAction implementation in the
+ * jboss6 additional source folder to see usage of new Search API)
*
* @author Emmanuel Bernard
*/
@@ -27,6 +29,7 @@
@Stateful
@Scope(ScopeType.APPLICATION)
@Startup
+@Deprecated
public class IndexerAction implements Indexer
{
private Date lastIndexingTime;
Modified:
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Product.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Product.java 2011-01-07
16:34:24 UTC (rev 13976)
+++
branches/community/Seam_2_2/examples/dvdstore/src/com/jboss/dvd/seam/Product.java 2011-01-07
17:14:55 UTC (rev 13977)
@@ -22,18 +22,31 @@
import javax.persistence.OneToOne;
import javax.persistence.Table;
+import org.apache.solr.analysis.LowerCaseFilterFactory;
+import org.apache.solr.analysis.NGramFilterFactory;
+import org.apache.solr.analysis.StandardTokenizerFactory;
+import org.hibernate.search.annotations.AnalyzerDef;
import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Fields;
+import org.hibernate.search.annotations.Parameter;
import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.search.annotations.TokenFilterDef;
+import org.hibernate.search.annotations.TokenizerDef;
-
@Entity
@Table(name="PRODUCTS")
@Indexed
-public class Product
- implements Serializable
+@AnalyzerDef(name="ngrams",
tokenizer=(a)TokenizerDef(factory=StandardTokenizerFactory.class),
+ filters={
+ @TokenFilterDef(factory = LowerCaseFilterFactory.class),
+ @TokenFilterDef(factory = NGramFilterFactory.class,
+ params = { @Parameter(name = "minGramSize", value =
"3"), @Parameter(name = "maxGramSize", value = "3") })
+ })
+public class Product implements Serializable
{
private static final long serialVersionUID = -5378546367347755065L;
@@ -93,6 +106,7 @@
@JoinTable(name="PRODUCT_CATEGORY",
joinColumns=@JoinColumn(name="PROD_ID"),
inverseJoinColumns=@JoinColumn(name="CATEGORY"))
+ @IndexedEmbedded
public Set<Category> getCategories() {
return categories;
}
@@ -101,7 +115,9 @@
}
@Column(name="TITLE",nullable=false,length=100)
- @Field(index=Index.TOKENIZED)
+ @Fields({
+ @Field(index=Index.TOKENIZED),
+ @Field(index=Index.TOKENIZED, name="title:ngrams",
analyzer=@Analyzer(definition="ngrams"))})
public String getTitle() {
return title;
}
@@ -110,6 +126,9 @@
}
@Column(name="DESCRIPTION",length=1024)
+ @Fields({
+ @Field(index=Index.TOKENIZED),
+ @Field(index=Index.TOKENIZED, name="description:ngrams",
analyzer=@Analyzer(definition="ngrams"))})
public String getDescription() {
return description;
}