Skip to content

Commit

Permalink
HSEARCH-2662 Consistently report errors for any type of query when th…
Browse files Browse the repository at this point in the history
…ere is no indexed type

This is one way of not having any index manager to query on, which
could lead to errors similar to what we are trying to fix in
HSEARCH-2662.
On Lucene this case was correctly detected, but not on Elasticsearch.
  • Loading branch information
yrodiere authored and Sanne committed Apr 13, 2017
1 parent 2e664de commit a091a76
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Expand Up @@ -337,7 +337,11 @@ private IndexSearcher getOrCreateSearcher() {

private Iterable<Class<?>> getQueriedEntityTypes() {
if ( indexedTargetedEntities == null || indexedTargetedEntities.isEmpty() ) {
return extendedIntegrator.getIndexBindings().keySet();
Set<Class<?>> indexBindings = extendedIntegrator.getIndexBindings().keySet();
if ( indexBindings.isEmpty() ) {
throw LOG.queryWithNoIndexedType();
}
return indexBindings;
}
else {
return indexedTargetedEntities;
Expand Down
Expand Up @@ -405,9 +405,7 @@ private LazyQueryState buildSearcher(ExtendedSearchIntegrator extendedIntegrator
// empty indexedTargetedEntities array means search over all indexed entities,
// but we have to make sure there is at least one
if ( indexBindings.isEmpty() ) {
throw new SearchException(
"There are no mapped entities. Don't forget to add @Indexed to at least one class."
);
throw log.queryWithNoIndexedType();
}

for ( EntityIndexBinding entityIndexBinding : indexBindings.values() ) {
Expand Down
Expand Up @@ -1019,4 +1019,7 @@ public interface Log extends BasicLogger {

@Message(id = 332, value = "None of the specified entity types ('%s') or any of their subclasses are configured." )
IllegalArgumentException targetedEntityTypesNotConfigured(String targetedEntities);

@Message(id = 333, value = "Cannot query: there aren't any mapped entity. Don't forget to add @Indexed to at least one class." )
SearchException queryWithNoIndexedType();
}
Expand Up @@ -49,7 +49,7 @@ public void testQueryOnAllEntities() throws Exception {
fail();
}
catch (SearchException e) {
assertTrue( "Wrong message", e.getMessage().startsWith( "There are no mapped entities" ) );
assertTrue( "Wrong message", e.getMessage().contains( "Cannot query: there aren't any mapped entity" ) );
}

tx.rollback();
Expand Down

0 comments on commit a091a76

Please sign in to comment.