tags:

views:

420

answers:

2

Is it possible to search for a phrase of the kind Searching is fun, in Lucene?

When I try to search with this, Lucene ends up looking for the word fun alone.

+3  A: 

Try to put in in quotes: "Searching is fun" or add '+' to required words +Searching +fun

See "Lucene - Query Parser Syntax" for available options

aku
+3  A: 

If you are using a QueryParser object to parse your query, you can configure it to automatically assume the '+' operator that Aku spoke of in his answer (sorry Aku for not simply commenting, but comments apparently don't support code formatting). For example:

String defaultField = ...;
Analyzer analyzer = ...;
QueryParser queryParser = new QueryParser(defaultField, analyzer);

queryParser.setDefaultOperator(QueryParser.Operator.AND);

Query query = queryParser.parse("Searching is fun");
Adam Paynter