[hibernate-commits] Hibernate SVN: r15387 - in search/trunk/src: test/org/hibernate/search/test/query and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Oct 24 11:04:07 EDT 2008
Author: hardy.ferentschik
Date: 2008-10-24 11:04:07 -0400 (Fri, 24 Oct 2008)
New Revision: 15387
Modified:
search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java
Log:
HSEARCH-162 - added a check to verify that at least one document builder (index class) exists
Modified: search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2008-10-24 14:22:27 UTC (rev 15386)
+++ search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2008-10-24 15:04:07 UTC (rev 15387)
@@ -323,28 +323,28 @@
if ( filterDefinitions == null || filterDefinitions.size() == 0 ) {
return; // there is nothing to do if we don't have any filter definitions
}
-
+
ChainedFilter chainedFilter = new ChainedFilter();
for (FullTextFilterImpl fullTextFilter : filterDefinitions.values()) {
Filter filter = buildLuceneFilter(fullTextFilter);
chainedFilter.addFilter( filter );
}
-
+
if ( filter != null ) chainedFilter.addFilter( filter );
filter = chainedFilter;
}
/**
* Builds a Lucene filter using the given <code>FullTextFilter</code>.
- *
- * @param fullTextFilter the Hibernate specific <code>FullTextFilter</code> used to create the
+ *
+ * @param fullTextFilter the Hibernate specific <code>FullTextFilter</code> used to create the
* Lucene <code>Filter</code>.
* @return the Lucene filter mapped to the filter definition
*/
private Filter buildLuceneFilter(FullTextFilterImpl fullTextFilter) {
-
+
SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
-
+
/*
* FilterKey implementations and Filter(Factory) do not have to be threadsafe wrt their parameter injection
* as FilterCachingStrategy ensure a memory barrier between concurrent thread calls
@@ -357,10 +357,10 @@
Filter filter = cacheInstance( def.getCacheMode() ) ?
searchFactoryImplementor.getFilterCachingStrategy().getCachedFilter( key ) :
null;
-
+
if ( filter == null ) {
- filter = createFilter(def, instance);
-
+ filter = createFilter(def, instance);
+
// add filter to cache if we have to
if ( cacheInstance( def.getCacheMode() ) ) {
searchFactoryImplementor.getFilterCachingStrategy().addCachedFilter( key, filter );
@@ -398,17 +398,17 @@
+ (def.getFactoryMethod() != null ? def.getFactoryMethod().getName() : ""), e );
}
}
-
+
filter = addCachingWrapperFilter(filter, def);
return filter;
}
/**
* Decides whether to wrap the given filter around a <code>CachingWrapperFilter<code>.
- *
+ *
* @param filter the filter which maybe gets wrapped.
* @param def The filter definition used to decide whether wrapping should occur or not.
- * @return The original filter or wrapped filter depending on the information extracted from
+ * @return The original filter or wrapped filter depending on the information extracted from
* <code>def</code>.
*/
private Filter addCachingWrapperFilter(Filter filter, FilterDef def) {
@@ -416,7 +416,7 @@
int cachingWrapperFilterSize = getSearchFactoryImplementor().getFilterCacheBitResultsSize();
filter = new org.hibernate.search.filter.CachingWrapperFilter(filter, cachingWrapperFilterSize);
}
-
+
return filter;
}
@@ -425,7 +425,7 @@
if ( !cacheInstance( def.getCacheMode() ) ) {
return key; // if the filter is not cached there is no key!
}
-
+
if ( def.getKeyMethod() == null ) {
key = new FilterKey() {
public int hashCode() {
@@ -534,7 +534,12 @@
Similarity searcherSimilarity = null;
//TODO check if caching this work for the last n list of classes makes a perf boost
if ( classes == null || classes.length == 0 ) {
- //no class means all classes
+ // empty classes array means search over all indexed enities,
+ // but we have to make sure there is at least one
+ if ( builders.isEmpty() ) {
+ throw new HibernateException( "There are no mapped entities (don't forget to add @Indexed to at least one class)." );
+ }
+
for (DocumentBuilder builder : builders.values()) {
searcherSimilarity = checkSimilarity( searcherSimilarity, builder );
final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
Modified: search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java 2008-10-24 14:22:27 UTC (rev 15386)
+++ search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java 2008-10-24 15:04:07 UTC (rev 15387)
@@ -38,7 +38,7 @@
fail();
}
catch ( HibernateException e ) {
- assertTrue( "Wrong message", e.getMessage().startsWith( "Not a mapped entity" ) );
+ assertTrue( "Wrong message", e.getMessage().startsWith( "There are no mapped entities" ) );
}
tx.rollback();
More information about the hibernate-commits
mailing list