查询中的适用方面未返回任何结果

问题描述 投票:0回答:1

我正在尝试使用Hibernate Search方面对可用数据进行分类。查询可正确返回结果,但构面列表的大小始终为0。这是我的模型-我正在根据属性cityStateCombination对此处的数据进行分类,该属性也使用索引中可用的两个独立属性来获取表格。

@Entity
@Indexed
class Location {

    @Id
    @GeneratedValue
    @Column(name = "id", updatable = false, nullable = false)
    Long id

    @Field
    @NotNull
    String city

    @Field
    @NotNull
    String state

    @Field
    @NotNull
    String stateCode

    @Field
    @NotNull
    String zip

    @Field
    @NotNull
    String country

    @Field
    @NotNull
    String countryCode

    @Field
    String metro

    @Field
    Float latitude

    @Field
    Float longitude

    transient String cityStateCombination

    @Transient
    @Field(index= org.hibernate.search.annotations.Index.YES, analyze= Analyze.NO, store= Store.YES, name="cityStateCombination")
    @Facet(name="cityStateCombinationFacet", forField = "cityStateCombination")
    String getCityStateCombination()
    {
        return (this.city + "," + this.state).toLowerCase()
    }


    Location() {
    }

    Location(String city, String state, String stateCode, String zip, String country, String countryCode, String metro,
             Float latitude, Float longitude) {
        this.city = city
        this.state = state
        this.stateCode = stateCode
        this.zip = zip
        this.country = country
        this.countryCode = countryCode
        this.metro = metro
        this.latitude = latitude
        this.longitude = longitude
    }

}

下面的代码被写成可用于多个方面-

QueryBuilder locationQB = locationSearchService.getQueryBuilderForClass(Location)

Query luceneQuery = locationQB.phrase().onField("city").andField("state").andField("stateCode").
andField("zip").sentence(locationToSearch).createQuery()

//here I am receiving results correctly
List < Location > results = locationSearchService.fuzzySearchQb(luceneQuery, 10)

FullTextQuery fullTextQuery = locationSearchService.fullTextEntityManager.createFullTextQuery(luceneQuery, Location.class)
FacetingRequest cityStateCombinationFacetingRequest = locationQB.facet()
 .name("cityStateFacetRequest")
 .onField("cityStateCombinationFacet")
 .discrete()
 .orderedBy(FacetSortOrder.COUNT_DESC)
 .includeZeroCounts(false)
 .maxFacetCount(3)
 .createFacetingRequest()

FacetManager facetManager = fullTextQuery.getFacetManager()
facetManager.enableFaceting(cityStateCombinationFacetingRequest)
List < org.hibernate.search.query.facet.Facet > facetsPulled = facetManager.getFacets("cityStateFacetRequest")

//Here, facets size returned is always 0
log.info 'facets pulled are :' + facetsPulled.size()

索引文件的例子是这样的-

{
    "_index" : "location",
    "_type" : "Location",
    "_id" : "56977",
    "_score" : 1.0,
    "_source" : {
      "id" : "56977",
      "cityStateCombination" : "millwood,virginia",
      "city" : "Millwood",
      "state" : "Virginia",
      "stateCode" : "VA",
      "zip" : "22646",
      "country" : "United States",
      "countryCode" : "US",
      "metro" : "metro_name",
      "latitude" : 39.0697,
      "longitude" : -78.0375
 }

我在这里使用常规,有人可以让我知道这里缺少东西吗?

hibernate-search
1个回答
0
投票

我假设您已经在创建Elasticsearch索引之后添加了@Facet批注。如果是这样,您是否照顾过:

  • 删除索引并重新启动Hibernate Search以更新架构?
  • 使用mass indexer重新索引数据?

不执行上述操作可能会导致搜索失败或搜索结果不完整。

© www.soinside.com 2019 - 2024. All rights reserved.