Permalink
Browse files

Make Queries.phraseFor null resilient

  • Loading branch information...
1 parent 1deda7d commit 124128a6fe8b4f0eb74a1aeb105afd34ec283586 @kevinclark kevinclark committed Jun 20, 2012
@@ -61,6 +61,9 @@ public static BooleanQuery or(final Query... subQueries) {
*/
public static PhraseQuery phraseFor(
final Analyzer analyzer, final String field, final String query) {
+ if (query == null) {
+ return null;
+ }
TokenStream tokens = analyzer.tokenStream("", new StringReader(query));
PhraseQuery phrase = new PhraseQuery();
try {
@@ -0,0 +1,16 @@
+package com.greplin.lucene.query;/*
+ * Copyright 2010 Greplin, Inc. All Rights Reserved.
+ */
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.util.Version;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class QueriesTest {
+ @Test
+ public void testPhraseForWithNullStringReturnsNull() throws Exception {
+ Assert.assertNull(Queries.phraseFor(new StandardAnalyzer(Version.LUCENE_34), "field", null));
+ }
+}

0 comments on commit 124128a

Please sign in to comment.