Taylor

Taylor Search

From Taylor

Taylor Search provides a specific application layer on top of Hibernate Search and Lucene for performing polymorphic free text searches. Here is the typical user story.

  1. Your application is made up of many subsystems with various domain entities.
  2. You want to perform free text searches across all of the entities at once.
  3. From the polymorphic search results you want to link to the View of the specific entities.

Here are the components:

  • Lucene handles the indexing and searching
  • Hibernate Search ensures that the indexes are updated as you insert, update, and delete entities
  • Taylor Search provides the search component for executing the search and displaying polymorphic links used to access the specific entities
  • Taylor MDA provides for modeling your entities and their indexes and generating all the code and configurations

Contents

Dependencies

The pom for JPA projects will be generated with the taylor-search dependency included. This will ensure that the dependencies are available for unit testing and included in the Ear.

The taylor-jboss-bundle already contains the hibernate and lucene jars in the server/all/lib directory.

	<dependency>
		<groupId>taylor</groupId>
		<artifactId>taylor-search</artifactId>
		<version>${taylor.version}</version>
	</dependency>

Configuration

By default, all entities from all JPA jars will store their index information in the taylor index. This is necessary so that searches can be performed across all entities/persistence contexts.

  • Each persistence.xml file will be generated with the directory provider.
    • Modify these if you wish to use a different provider.
	<property name="hibernate.search.default.directory_provider"
		value="org.hibernate.search.store.FSDirectoryProvider" /> 
  • For testing the root of the index is configured in the pom.
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-surefire-plugin</artifactId>
		<configuration>
			<systemProperties>
				<property>
					<name>hibernate.search.default.indexBase</name>
					<value>./target</value>
				</property>
			</systemProperties>
		</configuration>
	</plugin>
  • For the application server the root of the index is configured with a system property in the run-all.bat.
call run.bat -c all -Dhibernate.search.default.indexBase=../server/all/data/indexes
  • If you choose to change the name of the index you can add this to the components.xml.
    • NOTE: This value must match the value used in the @Indexed annotation/stereotype
	<search:managed-directory indexName="myindex" />

Reindex

Taylor Search contains an MBean for performing reindexing. Access this through the jmx-console.

  • Object Name = net.taylor.search.jmx:service=SearchReIndex

Theme

The default theme places the search input field in the upper right hand corner like you would expect.

  • themes/default/layout-template.xhtml
	<div id="taylor-search">
		<ui:insert name="search">
			<h:form id="quickSearchForm">
				<h:inputText id="quickSearchText"
					value="#{searchAction.searchPattern}"
					onclick="clickClear(this, 'Quick Search...')"
					onblur="clickRecall(this, 'Quick Search...')"
					styleClass="taylor-quick-search" size="15"
					maxlength="1000">
				</h:inputText>
				<h:commandButton id="findButton" value="Find" action="#{searchAction.doSearch}">
					<s:defaultAction />
				</h:commandButton>
			</h:form>
		</ui:insert>
	</div>
  • Executing a search will open the search results page.
	<rich:dataTable value="#{searchAction.searchResults}" var="result">
		<h:column>
			<div>
				<s:link view="#{result.url}" value="#{result.title}"
					propagation="none">
					<f:param name="id" value="#{result.id}" />
				</s:link>

				<s:formattedText value="#{result.summary}" />
			</div>
		</h:column>
	</rich:dataTable>
  • The url link to the entity will take the form jsf/<EntityName>/View.seam

Modeling

The HibernateSearch profile is included in new models for adding the necessary stereotypes to the entities in your model. For older models you will need to load the profile resource manually.

There is a utility for adding the stereotypes to entities in a model. Utilities > JPA > Add Search Index Stereotypes

The utility uses the following rules:

  • The Indexed stereotype is added to all entities
    • The index is set to "taylor"
  • The DocumentId stereotype is added to all id properties
  • The Field stereotype is added to all properties named: name, code, title, or subject.
    • The field is stored in the index as "title"
  • The Field stereotype is added to all properties named: description or text.
    • The field is stored in the index as "description"
  • The Field stereotype is added to all other string properties
    • These fields are not stored

The stored fields, title and description, are special cases that are used for displaying the results of a search. NOTE: You must have one and only one title and description field per indexed entity.

This utility is just for convenience and handles the bulk of the work. You will most likely need to tweak and add Field stereotypes.

Here is an example from the taylor-tracker model:

@Entity
@Indexed(index = "taylor")
public class Artifact  {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@DocumentId
	public Long getId() {
		return id;
	}

	...

	@Field(name = "title", store = Store.YES, index = Index.TOKENIZED)
	public String getTitle() {
		return title;
	}

	...

	@Field(name = "description", store = Store.YES, index = Index.TOKENIZED)
	public String getText() {
		return text;
	}

	...

	@Field(store = Store.NO, index = Index.TOKENIZED)
	public String getOwner() {
		return owner;
	}

	...
}

Related