微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Hibernate Search 6返回结果,但解释值为0.0

如何解决Hibernate Search 6返回结果,但解释值为0.0

我正在尝试休眠搜索6,因为5对我来说很难使用。

但是当匹配的解释为0.0时,结果是否仍返回实体?

为什么0.0有时是这个

2020-09-15 21:57:43.107  INFO 18032 --- [nio-8080-exec-8] n.l.a.s.r.search.HibernateSearchService  : 0.0 = Failure to meet condition(s) of required/prohibited clause(s)
  0.0 = no match on required clause ((MatchNodocsQuery("empty BooleanQuery"))^4.0 description:amonsdu platform:amonsdu platformId:amonsdu)
    0.0 = No matching clauses
  0.0 = match on required clause,product of:
    0.0 = # clause
    1.0 = __HSEARCH_type:main

=>未作为结果返回

有时是这个吗?

2020-09-15 21:57:46.475  INFO 18032 --- [io-8080-exec-10] n.l.a.s.r.search.HibernateSearchService  : 0.0 = sum of:
  0.0 = sum of:
    0.0 = Constantscore(name:us)^0.0
  0.0 = match on required clause,product of:
    0.0 = # clause
    1.0 = __HSEARCH_type:main

=>作为结果返回

这是处理搜索代码

@Transactional
    public Page<Game> fuzzySearch(String searchTerm,Pageable pageable) {
        SearchSession searchSession = Search.session(entityManager);
        LucenesearchQuery<Game> gameSearchQuery = searchSession.search(Game.class)
                .extension(LuceneExtension.get())
                .where(f -> f.bool()
                        .should(
                                f.match()
                                        .field("name")
                                        .matching(searchTerm)
                                        .fuzzy(2,0)
                                        .boost(4)
                        ).should(
                                f.phrase()
                                        .field("description")
                                        .matching(searchTerm)
                                        .slop(3)
                                        .boost(1)
                        )
                        .should(
                                f.match()
                                        .fields("platform","platformId")
                                        .matching(searchTerm)
                        )

                ).toQuery();
        SearchResult<Game> result = gameSearchQuery.fetch((int) pageable.getoffset(),pageable.getPageSize());
        Explanation explanation = gameSearchQuery.explain(21L);
        log.info(explanation.toString());
        log.info(result.hits().toString());
        return new PageImpl<>(result.hits(),pageable,result.total().hitCount());
    }

正在搜索的实体

@Data
@MappedSuperclass
public class GameInfo {

    @FullTextField(analyzer = "gameName")
    @NotBlank
    @Size(min = 2,max = 500)
    private String name;

    @FullTextField(analyzer = "gameDescription")
    @Size(max = 6000)
    private String description;

    @KeywordField
    private String platform;

    @KeywordField
    private String platformId;


}

还有自定义分析器

 public void configure(LuceneAnalysisConfigurationContext context) {
            context.analyzer("gameName").custom()
                    .tokenizer(WhitespacetokenizerFactory.class)
                    .tokenFilter(LowerCaseFilterFactory.class);
            context.analyzer("gameDescription").custom()
                    .tokenizer(StandardTokenizerFactory.class)
                    .tokenFilter(LowerCaseFilterFactory.class)
                    .tokenFilter(snowballPorterFilterFactory.class)
                        .param("language","English");
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。