如何使用布尔搜索语法进行Java字符串匹配?
2022-09-04 04:24:51
						我正在寻找一个Java / Scala库,它可以接受用户查询和文本,如果存在匹配项,则返回。
我正在处理一个信息流,即:Twitter Stream,并且无法承受使用批处理过程,我需要实时评估每条推文,而不是通过Lucene RAMDisk对其进行索引并在以后查询。
可以使用ANTLR创建解析器/词法分析器,但这是如此常见的用法,我不敢相信以前没有人创建lib。
TextQuery Ruby 库中的一些示例完全符合我的需求:
    TextQuery.new("'to be' OR NOT 'to_be'").match?("to be")   # => true
    TextQuery.new("-test").match?("some string of text")      # => true
    TextQuery.new("NOT test").match?("some string of text")   # => true
    TextQuery.new("a AND b").match?("b a")                    # => true
    TextQuery.new("a AND b").match?("a c")                    # => false
    q = TextQuery.new("a AND (b AND NOT (c OR d))")
    q.match?("d a b")                                         # => false
    q.match?("b")                                             # => false
    q.match?("a b cdefg")                                     # => true
    TextQuery.new("a~").match?("adf")                         # => true
    TextQuery.new("~a").match?("dfa")                         # => true
    TextQuery.new("~a~").match?("daf")                        # => true
    TextQuery.new("2~a~1").match?("edaf")                     # => true
    TextQuery.new("2~a~2").match?("edaf")                     # => false
    TextQuery.new("a", :ignorecase => true).match?("A b cD")  # => true
一旦它在Ruby中实现,它就不适合我的平台,我也不能仅仅在我们的解决方案中使用JRuby:
我发现了一个类似的问题,但无法从中得到答案:布尔查询/具体语法树的表达式
谢谢!
 
					 
				 
				    		 
				    		 
				    		 
				    		