-
Notifications
You must be signed in to change notification settings - Fork 242
/
ElasticsearchMatchSearchPredicateIT.java
65 lines (53 loc) · 2.29 KB
/
ElasticsearchMatchSearchPredicateIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.integrationtest.backend.elasticsearch.search;
import org.hibernate.search.engine.backend.document.IndexFieldReference;
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement;
import org.hibernate.search.integrationtest.backend.tck.testsupport.configuration.DefaultAnalysisDefinitions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
public class ElasticsearchMatchSearchPredicateIT {
private static final String TEST_TERM = "ThisWillBeLowercasedByTheNormalizer";
@Rule
public final SearchSetupHelper setupHelper = new SearchSetupHelper();
private final SimpleMappedIndex<IndexBinding> index = SimpleMappedIndex.of( IndexBinding::new );
@Before
public void setup() {
setupHelper.start().withIndex( index ).setup();
initData();
}
@Test
public void match_skipAnalysis_normalizedStringField() {
Assertions.assertThatThrownBy( () -> index.createScope().query()
.where( f -> f.match().field( "normalizedStringField" ).matching( TEST_TERM ).skipAnalysis() )
.toQuery()
)
.isInstanceOf( SearchException.class )
.hasMessageContainingAll( "Cannot skip analysis on field 'normalizedStringField'",
"the Elasticsearch backend will always normalize arguments before attempting matches on normalized fields" );
}
private void initData() {
index.bulkIndexer()
.add( "1", document -> document.addValue( index.binding().normalizedStringField, TEST_TERM ) )
.join();
}
private static class IndexBinding {
final IndexFieldReference<String> normalizedStringField;
IndexBinding(IndexSchemaElement root) {
normalizedStringField = root.field(
"normalizedStringField",
c -> c.asString().normalizer( DefaultAnalysisDefinitions.NORMALIZER_LOWERCASE.name )
)
.toReference();
}
}
}