Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

How to make Lucene match all words in query

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 0.62 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. String defaultField = ...;
  2. Analyzer analyzer = ...;
  3. QueryParser queryParser = new QueryParser(defaultField, analyzer);
  4.  
  5. queryParser.setDefaultOperator(QueryParser.Operator.AND);
  6.  
  7. Query query = queryParser.parse("Searching is fun");
  8.        
  9. if (required && !prohibited)
  10.   clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST));
  11. else if (!required && !prohibited)
  12.   clauses.addElement(new BooleanClause(q, BooleanClause.Occur.SHOULD));
  13. else if (!required && prohibited)
  14.   clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST_NOT));
  15. else
  16.   throw new RuntimeException("Clause cannot be both required and prohibited");