私はApache LuceneでHibernate Searchを設定して、与えられた座標でより簡単にenititesを検索しました。今、検索エンティティにどのように基準を追加することができますか?私はSpring DataプロジェクトとQuery DSLも使用しています。私はPredicate
QueryDSLのクラスを使用して、私のアプリケーションの一貫性を維持しようとしています。これを行う可能性はありますか?QueryDSLとHibernate SearchとLuceneを組み合わせる
マイPlace.class
@Getter
@Setter
@Entity
@Indexed
@Spatial
public class Place implements Serializable {
private static final long serialVersionUID = -8379536848917838560L;
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "place_id")
private Long id;
//...
@Longitude
private Double lng;
@Latitude
private Double lat;
//...
}
マイリポジトリクラス
@PersistenceContext(type = PersistenceContextType.EXTENDED)
EntityManager em;
@Override
@Transactional
public List findAll(Coordinates coordinates, Predicate predicate, Pageable pageable, int maxDistance) {
FullTextEntityManager fullTextSession = Search.getFullTextEntityManager(em);
QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Place.class).get();
org.apache.lucene.search.Query luceneQuery = builder
.spatial()
.within(maxDistance, Unit.KM)
.ofCoordinates(coordinates)
.createQuery();
FullTextQuery jpaQuery = fullTextSession.createFullTextQuery(luceneQuery, Place.class);
return jpaQuery.getResultList();
}
私はluceneではなくsqlの方がより自信を持っているので、自分のSQLクエリ/基準とluceneクエリを組み合わせる方法を探していましたが、ありがとうございました。私は欲しいものをやったことがあり、それは素晴らしい作品です。 –