在集成我們現有的應用程式之前,我正在試驗 Hibernatesearch 6.2.0.Alpha1 的投影功能。
我用 JHIPSTER示例專案創建了一個 spring-boot 專案。并在 POM.XML 和 application*.yml 中添加了 Hibernate-search 依賴項和配置。使用 JHipster 是因為它可以幫助我處理樣板代碼和假資料。
-parameters已經用和配置了jandexpom.xml 應用程式成功運行并將資料加載到資料庫中。而且我可以使用我們根據檔案撰寫的實用程式來批量索引。
但是,當嘗試使用預測搜索資料時,我們會收到錯誤訊息Exception in searchWithProjection() with cause = 'NULL' and exception = 'HSEARCH700112: Invalid object class for projection: com.sample.shop.service.projections.dto.Address. Make sure that this class is mapped correctly, either through annotations (@ProjectionConstructor) or programmatic mapping. If it is, make sure the class is included in a Jandex index made available to Hibernate Search.'。如果我們在沒有投影的情況下進行搜索,相同的查詢/邏輯可以正常作業。
前任。如果您查看AddressResource.java & AddressService.java上述鏈接存盤庫中的檔案;您可以分別找到投影和無投影的 2 個實作。雖然沒有投影的那個作業得很好,但有專案的那個卻拋出了錯誤。
我覺得這可能是一些配置問題,但無法弄清楚自己。感謝您對配置/代碼方法的幫助。
請注意,我已經通過了以下票證:
- Hibernate Search 6結合投影不起作用
- Hibernate Search 中的單一回傳型別
uj5u.com熱心網友回復:
感謝您的轉載。這是一個錯誤:https ://hibernate.atlassian.net/browse/HSEARCH-4724
我在這里建議了一個解決方法:https ://github.com/anothergoodguy/spring-data-hibernate-search/pull/1
簡而言之:
- 將此類添加到您的應用程式中:
package com.sample.shop.config;
import java.net.URISyntaxException;
import java.nio.file.Path;
import org.hibernate.search.mapper.orm.mapping.HibernateOrmMappingConfigurationContext;
import org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer;
import org.hibernate.search.util.common.jar.impl.JandexUtils;
import org.springframework.stereotype.Component;
@Component("searchMappingConfigurer")
public class HibernateSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {
@Override
public void configure(HibernateOrmMappingConfigurationContext context) {
// Workaround for https://hibernate.atlassian.net/browse/HSEARCH-4724
// => Hibernate Search doesn't seem to find the Jandex index in the fat JAR.
try {
var classesUri = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
var ssp = classesUri.getSchemeSpecificPart();
var jarpath = Path.of(ssp.substring(ssp.indexOf(":") 1, ssp.indexOf("!")));
context.annotationMapping().add(JandexUtils.readIndex(jarpath).get());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
- 在您的配置中參考它:
jpa:
properties:
hibernate.search.mapping.configurer: bean:searchMappingConfigurer
瞧。
請注意,這只是一種解決方法,并且依賴于可能隨時中斷的內部代碼。但是,好吧,至少它可以作業,所以在錯誤得到修復之前沒問題。
uj5u.com熱心網友回復:
以下是運行應用程式的說明:
所有需要的生態系統,如 Elasticsearch、kibana 和 MySql 都添加到eco.yml檔案中src/main/docker/eco.yml
請使用以下命令啟動生態系統docker-compose -f src/main/docker/eco.yml up -d && docker-compose -f src/main/docker/eco.yml logs -f
在不同的終端選項卡/視窗上,使用以下命令構建應用程式 ./mvnw clean package -Pprod,api-docs -Dskip.Tests -Dmaven.test.skip=true
以運行應用程式運行以下命令java -jar target/shop-app-0.0.1-SNAPSHOT.jar
一旦應用程式啟動,它會顯示它正在[http://localhost:8080]上進行串列。請在瀏覽器上打開相同的 url 并使用默認管理員 User:admin和 Password:登錄admin。然后請從管理員選單和API選單項導航到招搖。
我們需要對已經從同一個 swagger 視窗的 swagger 加載的假資料進行大規模索引:通過在資源Elastic Search Mass Indexing API上執行/api/mass/index上的帖子
然后請轉到地址資源:
/api/_search/addresses使用查詢字串請求沒有 Projections 訪問aa- 這將導致成功/_search/addresses/projection具有相同查詢字串的 Projections 訪問請求aa- 這將導致失敗
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/521164.html
