有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring Boot Solr HighlightPage不返回突出显示的信息

我似乎无法让高亮显示与Spring Boot和Spring Data Solr包正常工作

我使用的是Spring Boot 1.4.1

我有

public interface BooksRepository extends SolrCrudRepository<Books, String> {

    @Highlight(prefix = "<highlight>", postfix = "</highlight>")
    HighlightPage<SolrBooks> findByTitle(@Param("title") String title, Pageable pageable);

}

我在日志中看到了这一点

webapp=/solr path=/select params={q=title:Matrix&hl=true&hl.simple.post=&start=0&hl.fl=*&rows=20&wt=javabin&version=2&hl.simple.pre=}

如果我直接对Solr运行上面的查询(不带wt=javabin),我会得到高亮显示的对象

然而,我的Spring Boot REST响应不包括突出显示

 {
  "_embedded" : {
    "Books" : [ {
      "Title" : "Matrix",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/Books/329"
        },
        "Books" : {
          "href" : "http://localhost:8080/Books/329"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/Books/search/findByTitle?title=Matrix"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 1,
    "totalPages" : 1,
    "number" : 0
  }
}

我觉得我在做一些愚蠢的事情,但这很简单,但当Solr将信息传递回Spring时,它似乎忽略了突出显示。我做错了什么


共 (1) 个答案

  1. # 1 楼答案

    使用

    @Highlight(prefix = "<highlight>", postfix = "</highlight>", fields = {"title"})