我需要使用一个特定的格式化程序(前缀和后缀)对同一字段中的多个单词进行突出显示。
假设我有一个export class SecondComponent implements OnInit {
running;
constructor(private myService: MyService) { }
ngOnInit(){
this.myService.running.subscribe((isRunning) => {
this.running = isRunning;
console.log('running', this.running);
});
}
}
字段,对于一个文档,它的值为:description
。如何使用一对特定的前缀和后缀突出显示Einstein always excelled at math and physics from a young age
以及如何使用不同的前缀后缀对突出显示math
?因此,最后我想获得:
physics
原因是,在前端,我有不同的CSS类,例如Einstein always excelled at <em class="hl-red">math</em> and <em class="hl-green">physics</em> from a young age
的{{1}}和background-color: red;
的{{1}}。
但是,我设法在同一个字段中突出显示多个单词,但是到处都有相同的前缀-后缀对,这并不是我真正想要的。另外,我尝试在solrconfig.xml中添加多个HtmlFormatter条目:
hl-red
但我得到了background-color: green
。另外,我没有找到在Solr Admin UI或spring-data-solr中指定前缀数组的方法,只是一个简单的查询,如下所示:
hl-green
我认为这是Solr本身的局限性。
我当时正在考虑编写一个自定义的fragmentsBuilder,但我不知道是否确实如此,也不知道该怎么做。对于另一个变通办法,我想为每个单词执行一个突出显示查询,然后存储结果,然后为第二个单词执行另一个突出显示查询,存储结果,依此类推。但是我认为这不是一个好的优雅的解决方案,因为如果第二个单词是:“ em”或“ class”或“ red” /“ green”(执行不必要的突出显示,则会在执行第二个查询时遇到问题) )。
我正在将Spring-data-solr用于Spring Boot应用程序,并将Solr 6.6.5用作(http)服务。
有人知道如何解决吗?请给我一个建议!任何想法将不胜感激!