lucene转义

0

org.apache.lucene.queryparser.classic.ParseException: Cannot parse '?': '*' or '?' not allowed as first character in WildcardQuery
	at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:125)
	at org.apache.lucene.queryparser.classic.MultiFieldQueryParser.parse(MultiFieldQueryParser.java:307)
	at com.acgist.module.search.utils.IndexReaderUtils.searchIndex(IndexReaderUtils.java:66)
	at com.acgist.module.search.utils.SearchUtils.search(SearchUtils.java:16)
	at com.acgist.controller.SearchController.index(SearchController.java:41)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)

上面就是在搜索带有?的关键字时会出现这些错误,怎么解决呢?方法很简单,就是把你的关键词转义一下:

keyword = QueryParser.escape(keyword);