Browse files

Merge pull request #33 from holdenk/master

Fix for in/nin queries
  • Loading branch information...
2 parents 20f1fa5 + 40a677c commit c4eb3ada31c78fe250cce61a5d733424a2afbb41 @adamalix adamalix committed May 10, 2012
View
17 README.md
@@ -24,6 +24,11 @@ The other hook is only useful if you are using Solr for geospatail information,
we provide a trait called SolrGeoHash which has two required functions, namely
coverString and rectCoverString. Most people will not need to implement this.
+### Multiple Solr cores & non-stanrd query paths
+
+Support for multiple cores is done by overriding "core" in the model (wich is an Option[String]).
+If you have a non-standard query path you can override queryPath in your model.
+
## Examples
[QueryTest.scala](https://github.com/foursquare/slashem/blob/master/src/test/scala/com/foursquare/slashem/QueryTest.scala) contains sample queries and shows the corresponding query.
@@ -48,11 +53,17 @@ to do this:
## Dependencies
lift, joda-time, junit, finagle, jackson. These dependencies are managed by
-the build system.
+the build system. Note: some of the transitive dependencies may fail to resolve
+from the central maven. If you are using sbt you can fix this by adding
-## Warnings
+ ivyXML := (
+ <dependencies>
+ <exclude module="jmxtools"/>
+ <exclude module="jmxri"/>
+ </dependencies>
+ )
-This is still a very early version. There are likely bugs (sorry!). Let us know
+## Warnings still a very early version. There are likely bugs (sorry!). Let us know
if you find any. While we can't promise timely fixes, it will help :)
## Maintainers
View
9 build.sbt
@@ -1,6 +1,6 @@
name := "slashem"
-version := "0.9.13"
+version := "0.9.15a"
organization := "com.foursquare"
@@ -123,4 +123,11 @@ pomExtra := (
<email>aalix@foursquare.com</email>
</developer>
</developers>
+)
+
+ivyXML := (
+<dependencies>
+ <exclude module="jmxtools"/>
+ <exclude module="jmxri"/>
+</dependencies>
)
View
8 src/main/scala/com/foursquare/slashem/Ast.scala
@@ -242,7 +242,7 @@ object Ast {
}
def elasticBoost(): Pair[List[String],String] = {
weight match {
- case 1.0 => Pair(Nil,"(doc['" + fieldName + "'].value)")
+ case 1.0 => Pair(Nil,"doc['" + fieldName + "'].value")
case _ => Pair(Nil,"(doc['" + fieldName + "'].value *" + weight.toString + ")")
}
}
@@ -359,8 +359,10 @@ object Ast {
def extend(): String = "\"\""
/** @inheritdoc */
def elasticExtend(qf: List[WeightedField], pf: List[PhraseWeightedField], mm: Option[String]): ElasticQueryBuilder = {
- val q = EQueryBuilders.queryString(this.extend())
- qf.map(f => q.field(f.fieldName,f.weight.toFloat))
+ //An empty query matches no documents, so it is the same as the negation of matchAll
+ //Note: this is kind of ugly since this is may likely an OR clause or negated up above
+ //so we should try and avoid generating this
+ val q = EQueryBuilders.boolQuery.mustNot(EQueryBuilders.matchAllQuery())
q
}
}
View
22 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -79,6 +79,14 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
}
@Test
+ def simpleBoostTest {
+ val fullQuery = ESimplePanda.where(_.name contains "lol")
+ .limit(5).boostField(_.followers)
+ val r = fullQuery fetch()
+ }
+
+
+ @Test
def testEmptySearch {
try {
val r = ESimplePanda where (_.name eqs "lolsdonotinsertsomethingwiththisinit") fetch()
@@ -305,10 +313,20 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
def testListFieldIn {
val response1 = ESimplePanda where (_.favnums in List(2, 3, 4, 5)) fetch()
val response2 = ESimplePanda where (_.favnums in List(99)) fetch()
- //val response3 = ESimplePanda where (_.favnums in List()) fetch()
Assert.assertEquals(response1.response.results.length, 2)
Assert.assertEquals(response2.response.results.length, 0)
- //Assert.assertEquals(response3.response.results.length, 0)
+ }
+
+ @Test
+ def testIntListFieldEmptyIn {
+ val response = ESimplePanda where (_.favnums in List()) fetch()
+ Assert.assertEquals(response.response.results.length, 0)
+ }
+
+ @Test
+ def testIntListFieldEmptyNin {
+ val response = ESimplePanda where (_.favnums nin List()) fetch()
+ Assert.assertEquals(response.response.results.length, 8)
}
@Test
View
21 src/test/scala/com/foursquare/slashem/QueryTest.scala
@@ -70,6 +70,27 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
}
@Test
+ def testProduceCorrectListfieldQueryStringWhenEmpty {
+ val q = SVenueTest where (_.commentList in List())
+ val qp = q.meta.queryParams(q).toList
+ Assert.assertEquals(qp.sortWith(_._1 > _._1),
+ List("q" -> "commentList:(\"\")",
+ "start" -> "0",
+ "rows" -> "10").sortWith(_._1 > _._1))
+ }
+ @Test
+ def testProduceCorrectListfieldQueryStringNinWhenEmpty {
+ val q = SVenueTest where (_.commentList nin List())
+ val qp = q.meta.queryParams(q).toList
+ Assert.assertEquals(qp.sortWith(_._1 > _._1),
+ List("q" -> "(*:* -commentList:(\"\"))",
+ "start" -> "0",
+ "rows" -> "10").sortWith(_._1 > _._1))
+ }
+
+
+
+ @Test
def testProduceCorrectSimpleQueryStringContains {
val q = SUserTest where (_.fullname contains "jon")
val qp = q.meta.queryParams(q).toList

0 comments on commit c4eb3ad

Please sign in to comment.