使用特殊字符

时间:2014-07-10 10:58:21

标签: lucene cq5

我想用CQs QueryBuilder进行全文搜索:

type=cq:Page
path=/content/page
fulltext=#Employees

尝试此操作会为我提供与“员工”字样匹配的匹配,即使我将哈希作为查询的一部分,也可以使用' #Employees'。

看不到QueryBuilder修改了查询,但Lucene是否可能删除哈希?

1 个答案:

答案 0 :(得分:2)

我不确定cq5,但如果使用StandardAnalyzer,Lucene确实会在标记和查询时删除散列密钥,按照Word boundary rules from Unicode standard annex UAX#29

此代码

public static void main(String[] args) throws IOException {
    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_46);
    String s = "test if #hash has been removed";
    TokenStream stream = analyzer.tokenStream("field", new StringReader(s));
    stream.reset();
    CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
    while (stream.incrementToken()) {
        System.out.println(termAtt.toString());
    }
    stream.end();
    stream.close();
}

打印

  

测试
  哈希
  有
  被
  除去