romseygeek commented on a change in pull request #117:
URL: https://github.com/apache/solr/pull/117#discussion_r628089732



##########
File path: solr/core/src/test/org/apache/solr/hamcrest/QueryMatchers.java
##########
@@ -0,0 +1,184 @@
+package org.apache.solr.hamcrest;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
+import org.apache.lucene.search.DisjunctionMaxQuery;
+import org.apache.lucene.search.PhraseQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.is;
+
+public class QueryMatchers {
+  private QueryMatchers() {}
+
+  public static Matcher<Query> termQuery(String field, String text) {

Review comment:
       Matcher factories are generally written as predicates, so `isTermQuery` 
rather than just `termQuery`.  But I suppose that makes nested definitions read 
a bit weird, so maybe this is fine.

##########
File path: solr/core/src/test/org/apache/solr/hamcrest/QueryMatchers.java
##########
@@ -0,0 +1,184 @@
+package org.apache.solr.hamcrest;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
+import org.apache.lucene.search.DisjunctionMaxQuery;
+import org.apache.lucene.search.PhraseQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.is;
+
+public class QueryMatchers {
+  private QueryMatchers() {}
+
+  public static Matcher<Query> termQuery(String field, String text) {
+    // TODO Use a better matcher for more descriptive results?
+    return is(new TermQuery(new Term(field, text)));
+  }
+
+  public static Matcher<Query> boostQuery(String field, String text, float 
boost) {
+    return boostQuery(termQuery(field, text), boost);
+  }
+
+  public static Matcher<Query> boostQuery(Matcher<? extends Query> query, 
float boost) {
+    return new TypeSafeDiagnosingMatcher<Query>() {
+      @Override
+      protected boolean matchesSafely(Query item, Description 
mismatchDescription) {
+        if (item instanceof BoostQuery) {
+          BoostQuery bq = (BoostQuery) item;
+          boolean match = true;
+          mismatchDescription.appendText("was a BoostQuery ");
+          if (!query.matches(bq.getQuery())) {
+            match = false;
+            mismatchDescription.appendText("with" + bq.getQuery());
+          }
+          if (boost != bq.getBoost()) {
+            match = false;
+            mismatchDescription.appendText("with boost " + bq.getBoost());
+          }
+          return match;
+        } else {
+          classMismatch(mismatchDescription, item);
+          return false;
+        }
+      }
+
+      @Override
+      public void describeTo(Description description) {
+        description.appendText("a BoostQuery 
").appendDescriptionOf(query).appendText("^" + boost);
+      }
+    };
+  }
+
+  public static Matcher<Query> phraseQuery(String field, String... terms) {
+    // TODO Use a better matcher for more descriptive results?
+    return is(new PhraseQuery(field, terms));
+  }
+
+  public static Matcher<BooleanClause> booleanClause(Matcher<? extends Query> 
query) {

Review comment:
       Maybe call this `shouldClause` to make it explicit?

##########
File path: 
solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
##########
@@ -45,6 +45,14 @@
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import static org.apache.solr.hamcrest.QueryMatchers.booleanQuery;
+import static org.apache.solr.hamcrest.QueryMatchers.boostQuery;
+import static org.apache.solr.hamcrest.QueryMatchers.disjunctionQuery;
+import static org.apache.solr.hamcrest.QueryMatchers.phraseQuery;
+import static org.apache.solr.hamcrest.QueryMatchers.termQuery;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.containsString;
+
 @LuceneTestCase.AwaitsFix(bugUrl = 
"https://issues.apache.org/jira/browse/SOLR-15389";)

Review comment:
       Can we remove the awaits fix now?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to