查询的应用方面没有 return 任何结果

Applied facets on query does not return any result

我正在尝试使用 Hibernate Search 的各个方面对可用数据进行分类。
查询 returns 结果正确,但分面列表的大小始终为 0。这是我的模型 -
我在这里根据 属性 [=14= 对数据进行分类]],它也使用 index.

中可用的两个单独属性获取形式
@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
 }

我在这里使用 groovy,有人可以告诉我这里缺少的东西吗?

我假设您在创建 Elasticsearch 索引后添加了 @Facet 注释。如果是这样的话,你有没有照顾好:

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

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