2
votes

I would like to search over a string in java using search engine like syntax.

For example:

String: foo baz bar

Search query: "foo bar" OR baz

Result would be TRUE or found because the string 'baz' exist even though it couldn't find exact match of "foo bar"

Other query examples:

(foo OR baz) AND bar

foo -bar

-"foo bar" AND baz

Is there a library in JAVA that already does that and supports 'AND', 'OR', '-' and parentheses syntax?

1

1 Answers

3
votes

There is no direct search api, instead we can use regular expression to search or matching a string.

java.util.regex

The below simple example will you to start with regular expression.

http://www.kodejava.org/examples/276.html http://www.vogella.de/articles/JavaRegularExpressions/article.html http://java.sun.com/developer/technicalArticles/releases/1.4regex/