From 48c52733012907878995a5b9f980b824e47a3a86 Mon Sep 17 00:00:00 2001 From: Vineet Reynolds Date: Mon, 14 Oct 2013 20:46:44 +0530 Subject: [PATCH] JDF-402 Updated Hibernate Search to 4.4.0.Final. Also performed minor tutorial updates. Removed references to Errai annotations. Updated the POM to use project properties to reference the Hibernate Search version. --- demo/pom.xml | 8 +- .../example/ticketmonster/model/Event.java | 1 - .../rest/search/SearchService.java | 2 +- tutorial/DataPersistence.asciidoc | 1 - tutorial/HibernateSearch.asciidoc | 81 +++++++++---------- 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/demo/pom.xml b/demo/pom.xml index ea1a6e104..e34d6e51d 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -36,6 +36,8 @@ 1.7 1.9.9 + + 4.4.0.Final @@ -214,21 +216,21 @@ org.hibernate hibernate-search-orm - 4.3.0.Final + ${hibernate.search.version} provided org.hibernate hibernate-search-engine - 4.3.0.Final + ${hibernate.search.version} provided org.hibernate hibernate-search-analyzers - 4.3.0.Final + ${hibernate.search.version} provided diff --git a/demo/src/main/java/org/jboss/jdf/example/ticketmonster/model/Event.java b/demo/src/main/java/org/jboss/jdf/example/ticketmonster/model/Event.java index ffe9901f7..5fecee4a9 100644 --- a/demo/src/main/java/org/jboss/jdf/example/ticketmonster/model/Event.java +++ b/demo/src/main/java/org/jboss/jdf/example/ticketmonster/model/Event.java @@ -37,7 +37,6 @@ */ @SuppressWarnings("serial") @Entity - public class Event implements Serializable { /* Declaration of fields */ diff --git a/demo/src/main/java/org/jboss/jdf/example/ticketmonster/rest/search/SearchService.java b/demo/src/main/java/org/jboss/jdf/example/ticketmonster/rest/search/SearchService.java index c174d56e5..46dd0553e 100644 --- a/demo/src/main/java/org/jboss/jdf/example/ticketmonster/rest/search/SearchService.java +++ b/demo/src/main/java/org/jboss/jdf/example/ticketmonster/rest/search/SearchService.java @@ -79,7 +79,7 @@ private Query buildLuceneQuery(String searchString, Double latitude, Double long } else { // Find the terms of searchString with terms in event.name (weight of 10), - // event.description (weight of 1) and venue.name (weight of 3) + // event.description (weight of 1) and venue.name (weight of 5) termsQuery = qb.keyword() .onField("event.name").boostedTo(10f) .andField("event.description") diff --git a/tutorial/DataPersistence.asciidoc b/tutorial/DataPersistence.asciidoc index 5b481591b..566532148 100644 --- a/tutorial/DataPersistence.asciidoc +++ b/tutorial/DataPersistence.asciidoc @@ -332,7 +332,6 @@ Users must be able to book tickets for performances. A `Booking` is associated w Finally, both events and venues can have "media items", such as images or videos attached. -[[database-design]] .Entity-Relationship Diagram image::gfx/database-design.png[scaledwidth="70%"] diff --git a/tutorial/HibernateSearch.asciidoc b/tutorial/HibernateSearch.asciidoc index 3972c8664..4563a3b85 100644 --- a/tutorial/HibernateSearch.asciidoc +++ b/tutorial/HibernateSearch.asciidoc @@ -28,7 +28,7 @@ Our first task is to add Hibernate Search as a dependency to our application. Th === Set up the dependencies -Download the https://downloads.sourceforge.net/project/hibernate/hibernate-search/4.3.0.CR1/hibernate-search-modules-4.3.0.CR1-jbossas-72-dist.zip[Hibernate Search module] and copy its content into JBoss EAP or JBoss AS's `modules` directory. +Download the link:http://sourceforge.net/projects/hibernate/files/hibernate-search/4.4.0.Final/hibernate-search-modules-4.4.0.Final-jbossas-72-dist.zip[Hibernate Search module] and copy its content into JBoss EAP or JBoss AS's `modules` directory. Next update `jboss-deployment-structure.xml` to include the ORM module of Hibernate Search. This module is necessary to import the Hibernate Search engine as well as the integration code with Hibernate ORM. @@ -59,27 +59,34 @@ Finally, we need to add Hibernate Search as a `provided` dependency in our `pom. [source,xml] ---- + ... + + ... + + 4.4.0.Final + ... + ... org.hibernate hibernate-search-orm - 4.3.0.Final + ${hibernate.search.version} provided org.hibernate hibernate-search-engine - 4.3.0.Final + ${hibernate.search.version} provided org.hibernate hibernate-search-analyzers - 4.3.0.Final + ${hibernate.search.version} provided @@ -126,14 +133,11 @@ Marking entities and properties as indexed is as simple as adding annotations. B You cannot do joins in a full-text index. Instead, we cheat by denormalizing the information and indexing the associated objects we want to query by in the same entry. For that, we need to be able to navigate to all of the entities we are interested in. -Let's look at our domain model. +Let's look at our domain model once again. -[[database-design]] .Entity-Relationship Diagram image::gfx/database-design.png[scaledwidth="70%"] -CAUTION: TODO: fix diagram around TicketPriceCategory - `Show` happens to be the central entity from which we can reach `Event`, `Venue` as well as price and date information for each `Performance`. That will be the entity we will start indexing from. Let's make `Show` indexed by adding an `@Indexed` annotation. We also want to index the associated `Event` and `Venue` when a given `Show` is indexed. For that, we will mark each association as `@IndexedEmbedded`. @@ -146,7 +150,6 @@ Let's make `Show` indexed by adding an `@Indexed` annotation. We also want to in @SuppressWarnings("serial") @Entity @Table(uniqueConstraints = @UniqueConstraint(columnNames = { "event_id", "venue_id" })) -@Portable @Indexed public class Show implements Serializable { @@ -200,7 +203,6 @@ Next, we need to index the `Event` name and description. To make a property as i @SuppressWarnings("serial") @Entity -@Portable public class Event implements Serializable { ... @@ -260,7 +262,7 @@ public class Bootstrap { } ---- -The Hibernate Search APIs are accessible via `FullTextEntityManager`, a simpler wrapper around the `EntityManager` you are used to deal with. The `MassIndexer` API is a fluent API letting you refine what entities you want to reindex, with how many threads, synchronously or asynchronously etc. But the simple usage is good enough for most cases. +The Hibernate Search APIs are accessible via `FullTextEntityManager`, a simpler wrapper around the `EntityManager` you use to manage the entities. The `MassIndexer` API is a fluent API letting you refine what entities you want to reindex, with how many threads, synchronously or asynchronously etc. But the simple usage is good enough for most cases. We now have indexed entities, it is time to write our query engine. @@ -389,7 +391,7 @@ Here we will focus on keyword queries - queries looking for specific terms - on } else { // Find the terms of searchString with terms in event.name (weight of 10), - // event.description (weight of 1) and venue.name (weight of 3) + // event.description (weight of 1) and venue.name (weight of 5) luceneQuery = qb .keyword() .onField("event.name").boostedTo(10f) @@ -503,8 +505,8 @@ We have seen previously in this tutorial how to write the UI part of a backbone. Let's first define a model for the results we will receive from the search REST endpoint. This model will also be responsible for computing the application URL exposed for bookmarkability. -[source,javascript] .src/main/webapp/resources/js/app/models/results.js +[source,javascript] ---- /** * Module for the query results model @@ -545,8 +547,8 @@ define([ Now that we have a model bound to our backend, we need a view to expose the results to the user. -[source, javascript] .src/main/webapp/resources/js/app/views/results.js +[source, javascript] ---- define([ 'utilities', @@ -581,8 +583,8 @@ define([ }); ---- -[source, html] .src/main/webapp/resources/templates/desktop/results.html +[source, html] ----
@@ -609,8 +611,8 @@ define([ Note that we do retrieve the actual query from the model (`query` parameter) and pass it to the template for display. We will need to fill `query` from the router. Speaking of the devil, let's add the necessary routes to trigger a query. -[source, javascript] .src/main/webapp/resources/js/app/router/desktop/router.js +[source, javascript] ---- ... define("router", [ @@ -654,8 +656,8 @@ define("router", [ We need to do one more thing. Somehow the query URL (e.g. `#search/anywhere/morrison`) needs to be called. Let's add a search box in the top menu and have it call that URL. -[source, html] .src/main/webapp/resources/templates/desktop/main.html +[source, html] ---- ...