【问题标题】:Lucene's Highlighter.getBestFragments method return empty string when a query contains forward slash当查询包含正斜杠时,Lucene 的 Highlighter.getBestFragments 方法返回空字符串
【发布时间】:2017-06-14 06:28:41
【问题描述】:

我有一个应用程序,当输入“fulltext:rajath AND filepath:rajath”之类的查询时,Highlighter.getBestFragments 会正确返回。但是,如果输入相同的查询在文件路径中包含“/”,这意味着如果查询类似于“fulltext:rajath AND filepath:rajath/rajath1”,则 Highlighter.getBestFragments 方法将返回一个空字符串。请让我知道如何解决这个问题。我严重怀疑这个问题是因为查询中的正斜杠。有什么办法可以逃脱吗?

目前我在我的应用程序中使用 lucene 2.9.3,其中突出显示不正确。但是查询“fulltext:rajath AND filepath:rajath/rajath1”用于在 lucene 2.2.0 中正确突出显示关键字 rajath。在 2.2.0 和 2.9.3 中,当输入 "fulltext:rajath AND filepath:rajath/rajath1" 时,内部查询变为 [+fulltext:rajath +filepath:"rajath rajath1"]

【问题讨论】:

    标签: java lucene special-characters lucene-highlighter


    【解决方案1】:

    在 Lucene 4.x 中,正斜杠 (/) 现在是一个特殊字符,用于表示正则表达式搜索。你需要escape your slashes,比如:

    String query = "filepath:rajath\\/rajath1";
    

    或者你可以给你lucene do the escaping,比如:

    String searchfor = "rajath/rajath1";
    String escapedsearch = QueryParserBase.escape(searchfor);
    String query = "filepath:" + escapedsearch;
    

    【讨论】:

    • 目前我在我的应用程序中使用 lucene 2.9.3,其中突出显示不正确。但是查询“fulltext:rajath AND filepath:rajath/rajath1”用于在 lucene 2.2.0 中正确突出显示关键字 rajath。在 2.2.0 和 2.9.3 中,当输入“fulltext:rajath AND filepath:rajath/rajath1”时,内部查询变为 [+fulltext:rajath +filepath:"rajath rajath1"]。
    猜你喜欢
    • 2011-10-10
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多