[hibernate-commits] Hibernate SVN: r16631 - in search/branches/Branch_3_1/hibernate-search-archetype: src/main/resources/META-INF/maven and 5 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu May 28 18:30:05 EDT 2009
Author: hardy.ferentschik
Date: 2009-05-28 18:30:05 -0400 (Thu, 28 May 2009)
New Revision: 16631
Added:
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Author.java
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Book.java
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/IndexAndSearchTest.java
Removed:
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Author.java
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Book.java
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/java/example/IndexAndSearchTest.java
Modified:
search/branches/Branch_3_1/hibernate-search-archetype/pom.xml
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype.xml
search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/pom.xml
Log:
udated the archetype project
Modified: search/branches/Branch_3_1/hibernate-search-archetype/pom.xml
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/pom.xml 2009-05-28 15:04:28 UTC (rev 16630)
+++ search/branches/Branch_3_1/hibernate-search-archetype/pom.xml 2009-05-28 22:30:05 UTC (rev 16631)
@@ -3,5 +3,5 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-quickstart</artifactId>
<packaging>jar</packaging>
- <version>3.1.0.GA</version>
+ <version>3.1.1.GA</version>
</project>
Modified: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype.xml
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype.xml 2009-05-28 15:04:28 UTC (rev 16630)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype.xml 2009-05-28 22:30:05 UTC (rev 16631)
@@ -1,15 +1,15 @@
<archetype>
<id>hibernate-search-quickstart</id>
<sources>
- <source>src/main/java/example/Book.java</source>
- <source>src/main/java/example/Author.java</source>
+ <source>src/main/java/Book.java</source>
+ <source>src/main/java/Author.java</source>
</sources>
<resources>
<resource>src/main/resources/log4j.properties</resource>
<resource>src/main/resources/META-INF/persistence.xml</resource>
</resources>
<testSources>
- <source>src/test/java/java/example/IndexAndSearchTest.java</source>
+ <source>src/test/java/IndexAndSearchTest.java</source>
</testSources>
<testResources>
<resource>src/test/resources/import.sql</resource>
Modified: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/pom.xml
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/pom.xml 2009-05-28 15:04:28 UTC (rev 16630)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/pom.xml 2009-05-28 22:30:05 UTC (rev 16631)
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
@@ -11,13 +13,13 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
- <version>3.1.0.GA</version>
+ <version>3.1.1.GA</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1_3</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
@@ -38,7 +40,7 @@
<artifactId>solr-core</artifactId>
<version>1.3.0</version>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-snowball</artifactId>
<version>2.4.0</version>
@@ -66,6 +68,18 @@
</dependency>
</dependencies>
<build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-webdav</artifactId>
+ <version>1.0-beta-2</version>
+ </extension>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>2.0-alpha-4</version>
+ </extension>
+ </extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -76,6 +90,11 @@
<target>1.5</target>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>2.0-alpha-4</version>
+ <extensions>true</extensions>
+ </plugin>
</plugins>
</build>
</project>
Copied: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Author.java (from rev 16630, search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Author.java)
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Author.java (rev 0)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Author.java 2009-05-28 22:30:05 UTC (rev 16631)
@@ -0,0 +1,35 @@
+package ${package};
+
+import org.hibernate.search.annotations.*;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/*
+ *
+ */
+ at Entity
+public class Author {
+ @Id
+ @GeneratedValue
+ private Integer id;
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @Field(index = Index.TOKENIZED, store = Store.YES)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Copied: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Book.java (from rev 16630, search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Book.java)
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Book.java (rev 0)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/Book.java 2009-05-28 22:30:05 UTC (rev 16631)
@@ -0,0 +1,86 @@
+package ${package};
+
+import org.hibernate.search.annotations.*;
+import org.apache.solr.analysis.*;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ */
+ at Entity
+ at AnalyzerDef(name = "customanalyzer",
+ tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
+ filters = {
+ @TokenFilterDef(factory = LowerCaseFilterFactory.class),
+ @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
+ @Parameter(name = "language", value = "English")
+ })
+ })
+ at Indexed
+public class Book {
+
+ private Integer id;
+ private String title;
+ private String subtitle;
+ private Set<Author> authors = new HashSet<Author>();
+ private Date publicationDate;
+
+ @IndexedEmbedded
+ @ManyToMany
+ public Set<Author> getAuthors() {
+ return authors;
+ }
+
+ public void setAuthors(Set<Author> authors) {
+ this.authors = authors;
+ }
+
+ public Book() {
+ }
+
+ @Field(index = Index.TOKENIZED, store = Store.YES)
+ @Analyzer(definition = "customanalyzer")
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @Id
+ @DocumentId
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @Field(index = Index.TOKENIZED, store = Store.NO)
+ @Analyzer(definition = "customanalyzer")
+ public String getSubtitle() {
+ return subtitle;
+ }
+
+ public void setSubtitle(String subtitle) {
+ this.subtitle = subtitle;
+ }
+
+ @Field(index = Index.UN_TOKENIZED, store = Store.YES)
+ @DateBridge(resolution = Resolution.DAY)
+ public Date getPublicationDate() {
+ return publicationDate;
+ }
+
+ public void setPublicationDate(Date publicationDate) {
+ this.publicationDate = publicationDate;
+ }
+}
Deleted: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Author.java
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Author.java 2009-05-28 15:04:28 UTC (rev 16630)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Author.java 2009-05-28 22:30:05 UTC (rev 16631)
@@ -1,35 +0,0 @@
-package example;
-
-import org.hibernate.search.annotations.*;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-
-/*
- *
- */
- at Entity
-public class Author {
- @Id
- @GeneratedValue
- private Integer id;
- private String name;
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- @Field(index = Index.TOKENIZED, store = Store.YES)
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Deleted: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Book.java
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Book.java 2009-05-28 15:04:28 UTC (rev 16630)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/main/java/example/Book.java 2009-05-28 22:30:05 UTC (rev 16631)
@@ -1,88 +0,0 @@
-package example;
-
-import org.hibernate.search.annotations.*;
-import org.apache.solr.analysis.*;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToMany;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-import example.Author;
-
-/**
- *
- */
- at Entity
- at AnalyzerDef(name = "customanalyzer",
- tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
- filters = {
- @TokenFilterDef(factory = LowerCaseFilterFactory.class),
- @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
- @Parameter(name = "language", value = "English")
- })
- })
- at Indexed
-public class Book {
-
- private Integer id;
- private String title;
- private String subtitle;
- private Set<Author> authors = new HashSet<Author>();
- private Date publicationDate;
-
- @IndexedEmbedded
- @ManyToMany
- public Set<Author> getAuthors() {
- return authors;
- }
-
- public void setAuthors(Set<Author> authors) {
- this.authors = authors;
- }
-
- public Book() {
- }
-
- @Field(index = Index.TOKENIZED, store = Store.YES)
- @Analyzer(definition = "customanalyzer")
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- @Id
- @DocumentId
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- @Field(index = Index.TOKENIZED, store = Store.NO)
- @Analyzer(definition = "customanalyzer")
- public String getSubtitle() {
- return subtitle;
- }
-
- public void setSubtitle(String subtitle) {
- this.subtitle = subtitle;
- }
-
- @Field(index = Index.UN_TOKENIZED, store = Store.YES)
- @DateBridge(resolution = Resolution.DAY)
- public Date getPublicationDate() {
- return publicationDate;
- }
-
- public void setPublicationDate(Date publicationDate) {
- this.publicationDate = publicationDate;
- }
-}
Copied: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/IndexAndSearchTest.java (from rev 16630, search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/java/example/IndexAndSearchTest.java)
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/IndexAndSearchTest.java (rev 0)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/IndexAndSearchTest.java 2009-05-28 22:30:05 UTC (rev 16631)
@@ -0,0 +1,141 @@
+package ${package};
+
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.hibernate.Session;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.jpa.FullTextEntityManager;
+import org.hibernate.search.jpa.FullTextQuery;
+import org.junit.After;
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class IndexAndSearchTest {
+
+ private EntityManagerFactory emf;
+
+ private EntityManager em;
+
+ private static Logger log = LoggerFactory.getLogger(IndexAndSearchTest.class);
+
+ @Before
+ public void setUp() {
+ initHibernate();
+ }
+
+ @After
+ public void tearDown() {
+ purge();
+ }
+
+ @Test
+ public void testIndexAndSearch() throws Exception {
+ List<Book> books = search("hibernate");
+ assertEquals("Should get empty list since nothing is indexed yet", 0, books.size());
+
+ index();
+
+ // search by title
+ books = search("hibernate");
+ assertEquals("Should find one book", 1, books.size());
+ assertEquals("Wrong title", "Java Persistence with Hibernate", books.get(0).getTitle());
+
+ // search author
+ books = search("\"Gavin King\"");
+ assertEquals("Should find one book", 1, books.size());
+ assertEquals("Wrong title", "Java Persistence with Hibernate", books.get(0).getTitle());
+ }
+
+ @Test
+ public void testStemming() throws Exception {
+
+ index();
+
+ List<Book> books = search("refactor");
+ assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
+
+ books = search("refactors");
+ assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
+
+ books = search("refactored");
+ assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
+
+ books = search("refactoring");
+ assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
+ }
+
+
+ private void initHibernate() {
+ Ejb3Configuration config = new Ejb3Configuration();
+ config.configure("hibernate-search-example", new HashMap());
+ emf = config.buildEntityManagerFactory();
+ em = emf.createEntityManager();
+ }
+
+ private void index() {
+ em.getTransaction().begin();
+ FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession((Session) em.getDelegate());
+ List<Book> results = ftSession.createCriteria(Book.class).list();
+ for (Object obj : results) {
+ ftSession.index(obj);
+ }
+ em.getTransaction().commit();
+ }
+
+ private void purge() {
+ em.getTransaction().begin();
+ FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession((Session) em.getDelegate());
+ ftSession.purgeAll(Book.class);
+ em.getTransaction().commit();
+ }
+
+ private List<Book> search(String searchQuery) throws ParseException {
+ Query query = searchQuery(searchQuery);
+
+ List<Book> books = query.getResultList();
+
+ for (Book b : books) {
+ log.info("Title: " + b.getTitle());
+ }
+ return books;
+ }
+
+ private Query searchQuery(String searchQuery) throws ParseException {
+
+ String[] bookFields = {"title", "subtitle", "authors.name", "publicationDate"};
+
+ //lucene part
+ Map<String, Float> boostPerField = new HashMap<String, Float>(4);
+ boostPerField.put(bookFields[0], (float) 4);
+ boostPerField.put(bookFields[1], (float) 3);
+ boostPerField.put(bookFields[2], (float) 4);
+ boostPerField.put(bookFields[3], (float) .5);
+
+ FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager((EntityManager) em);
+
+ QueryParser parser = new MultiFieldQueryParser(bookFields, ftEm.getSearchFactory().getAnalyzer("customanalyzer"),
+ boostPerField);
+
+ org.apache.lucene.search.Query luceneQuery;
+ luceneQuery = parser.parse(searchQuery);
+
+ final FullTextQuery query = ftEm.createFullTextQuery(luceneQuery, Book.class);
+
+ return query;
+ }
+
+}
+
Deleted: search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/java/example/IndexAndSearchTest.java
===================================================================
--- search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/java/example/IndexAndSearchTest.java 2009-05-28 15:04:28 UTC (rev 16630)
+++ search/branches/Branch_3_1/hibernate-search-archetype/src/main/resources/archetype-resources/src/test/java/java/example/IndexAndSearchTest.java 2009-05-28 22:30:05 UTC (rev 16631)
@@ -1,138 +0,0 @@
-package example;
-
-import org.apache.lucene.queryParser.MultiFieldQueryParser;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.hibernate.Session;
-import org.hibernate.ejb.Ejb3Configuration;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.jpa.FullTextEntityManager;
-import org.hibernate.search.jpa.FullTextQuery;
-import org.junit.After;
-import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Query;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- *
- */
-public class IndexAndSearchTest {
-
- private EntityManagerFactory emf;
-
- private EntityManager em;
-
- private static Logger log = LoggerFactory.getLogger(IndexAndSearchTest.class);
-
- @Before
- public void setUp() {
- initHibernate();
- }
-
- @After
- public void tearDown() {
- purge();
- }
-
- @Test
- public void testIndexAndSearch() throws Exception {
- List<Book> books = search("hibernate");
- assertEquals("Should get empty list since nothing is indexed yet", 0, books.size());
-
- index();
-
- // search by title
- books = search("hibernate");
- assertEquals("Should find one book", 1, books.size());
- assertEquals("Wrong title", "Java Persistence with Hibernate", books.get(0).getTitle());
-
- // search author
- books = search("\"Gavin King\"");
- assertEquals("Should find one book", 1, books.size());
- assertEquals("Wrong title", "Java Persistence with Hibernate", books.get(0).getTitle());
- }
-
- @Test
- public void testStemming() throws Exception {
-
- index();
-
- List<Book> books = search("refactor");
- assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
-
- books = search("refactors");
- assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
-
- books = search("refactored");
- assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
-
- books = search("refactoring");
- assertEquals("Wrong title", "Refactoring: Improving the Design of Existing Code", books.get(0).getTitle());
- }
-
-
- private void initHibernate() {
- Ejb3Configuration config = new Ejb3Configuration();
- config.configure("hibernate-search-example", new HashMap());
- emf = config.buildEntityManagerFactory();
- em = emf.createEntityManager();
- }
-
- private void index() {
- FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession((Session) em.getDelegate());
- List results = ftSession.createCriteria(Book.class).list();
- for (Object obj : results) {
- ftSession.index(obj);
- }
- }
-
- private void purge() {
- FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession((Session) em.getDelegate());
- ftSession.purgeAll(Book.class);
- }
-
- private List<Book> search(String searchQuery) throws ParseException {
- Query query = searchQuery(searchQuery);
-
- List<Book> books = query.getResultList();
-
- for (Book b : books) {
- log.info("Title: " + b.getTitle());
- }
- return books;
- }
-
- private Query searchQuery(String searchQuery) throws ParseException {
-
- String[] bookFields = {"title", "subtitle", "authors.name", "publicationDate"};
-
- //lucene part
- Map<String, Float> boostPerField = new HashMap<String, Float>(4);
- boostPerField.put(bookFields[0], (float) 4);
- boostPerField.put(bookFields[1], (float) 3);
- boostPerField.put(bookFields[2], (float) 4);
- boostPerField.put(bookFields[3], (float) .5);
-
- FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager((EntityManager) em);
-
- QueryParser parser = new MultiFieldQueryParser(bookFields, ftEm.getSearchFactory().getAnalyzer("customanalyzer"),
- boostPerField);
-
- org.apache.lucene.search.Query luceneQuery;
- luceneQuery = parser.parse(searchQuery);
-
- final FullTextQuery query = ftEm.createFullTextQuery(luceneQuery, Book.class);
-
- return query;
- }
-
-}
More information about the hibernate-commits
mailing list