我在我的门户(基于J2EE)中使用Lucene进行索引和搜索服务。
问题是关于Lucene的关键字。当您在搜索查询中使用其中一个时,您将收到错误。
例如:
searchTerms = "ik OR jij"
这工作正常,因为它会搜索“ik”或“jij”
searchTerms = "ik AND jij"
这工作正常,它搜索“ik”和“jij”
但是当你搜索:
searchTerms = "OR"
searchTerms = "AND"
searchTerms = "ik OR"
searchTerms = "OR ik"
等等,它将失败并出现错误:
Component Name: STSE_RESULTS Class: org.apache.lucene.queryParser.ParseException Message: Cannot parse 'OR jij': Encountered "OR" at line 1, column 0.
Was expecting one of:
...
这是有道理的,因为这些词是Lucene的关键词,可能是保留的,并将作为关键字。
在荷兰语中,“OR”这个词很重要,因为它具有“Ondernemings Raad”的含义。它被用于许多文本,需要找到它。例如“或”有效,但不返回符合术语“OR”的文本。如何使其可搜索?
如何避免关键字“或”?或者如何告诉Lucene将“或”作为搜索词不作为关键字。