use of org.hibernate.search.engine.backend.types.Searchable in project hibernate-search by hibernate.
the class DistanceSearchSearchableSortableIT method searchableNotSortable.
@Test
public void searchableNotSortable() {
StubMappingScope scope = index.createScope();
String fieldPath = "searchableNotSortable";
assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:distance' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
use of org.hibernate.search.engine.backend.types.Searchable in project hibernate-search by hibernate.
the class DistanceSearchableSortableIT method searchableNotSortable.
@Test
public void searchableNotSortable() {
assumeFalse("Skipping test for ES GeoPoint as those would become sortable by default in this case.", TckConfiguration.get().getBackendFeatures().fieldsProjectableByDefault());
StubMappingScope scope = index.createScope();
String fieldPath = "searchableNotSortable";
assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:distance' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
use of org.hibernate.search.engine.backend.types.Searchable in project hibernate-search by hibernate.
the class DistanceSearchableSortableIT method searchableDefaultSortable.
@Test
public void searchableDefaultSortable() {
assumeFalse("Skipping test for ES GeoPoint as those would become sortable by default in this case.", TckConfiguration.get().getBackendFeatures().fieldsProjectableByDefault());
StubMappingScope scope = index.createScope();
String fieldPath = "searchableDefaultSortable";
assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:distance' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
use of org.hibernate.search.engine.backend.types.Searchable in project hibernate-search by hibernate.
the class JpaIdAsDocumentIdIT method test.
@Test
public void test() {
backendMock.expectSchema(IndexedEntity.NAME, b -> b.objectField("contained", b2 -> b2.multiValued(true).field("id", Integer.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
SessionFactory sessionFactory = ormSetupHelper.start().setup(IndexedEntity.class, ContainedEntity.class);
backendMock.verifyExpectationsMet();
with(sessionFactory).runInTransaction(session -> {
IndexedEntity entity1 = new IndexedEntity();
entity1.setId(0);
ContainedEntity contained1 = new ContainedEntity();
contained1.setId(1);
entity1.getContained().add(contained1);
contained1.containing = entity1;
ContainedEntity contained2 = new ContainedEntity();
contained2.setId(2);
entity1.getContained().add(contained2);
contained2.containing = entity1;
session.persist(entity1);
session.persist(contained1);
session.persist(contained2);
backendMock.expectWorks(IndexedEntity.NAME).add("0", b -> b.objectField("contained", b2 -> b2.field("id", 1)).objectField("contained", b2 -> b2.field("id", 2)));
});
}
use of org.hibernate.search.engine.backend.types.Searchable in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method includeEmbeddedObjectId_identifierBridge.
@Test
@TestForIssue(jiraKey = "HSEARCH-3071")
public void includeEmbeddedObjectId_identifierBridge() {
class IndexedEmbeddedLevel1 {
@DocumentId(identifierBridge = @IdentifierBridgeRef(type = MyCustomIdentifierBinder.Bridge.class))
Long theId;
@AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "level1")))
Object containing;
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded(includeEmbeddedObjectId = true)
IndexedEmbeddedLevel1 level1;
public IndexedEntity(int id, Long level1Id) {
this.id = id;
this.level1 = new IndexedEmbeddedLevel1();
this.level1.theId = level1Id;
this.level1.containing = this;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("theId", String.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
SearchMapping mapping = setupHelper.start().expectCustomBeans().setup(IndexedEntity.class, IndexedEmbeddedLevel1.class);
backendMock.verifyExpectationsMet();
doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, 4242L), document -> document.objectField("level1", b2 -> b2.field("theId", "4243")));
}
Aggregations