Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for in/nin queries #33

Merged
merged 5 commits into from

2 participants

Holden Karau Adam Alix
Holden Karau

No description provided.

Adam Alix

This should be seldom used, I think it's OK for it to be non-optimal.

Adam Alix adamalix merged commit c4eb3ad into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 7, 2012
  1. Holden Karau
  2. Holden Karau
Commits on May 8, 2012
  1. Holden Karau
Commits on May 10, 2012
  1. Holden Karau

    Fix query gen for ES Empty[T] queries.

    holdenk authored
    TODO: We should optimize our tree before generating queries
  2. Holden Karau

    Bump version for bugfix

    holdenk authored
This page is out of date. Refresh to see the latest.
17 README.md
View
@@ -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
9 build.sbt
View
@@ -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>
)
8 src/main/scala/com/foursquare/slashem/Ast.scala
View
@@ -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
}
}
22 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
View
@@ -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
21 src/test/scala/com/foursquare/slashem/QueryTest.scala
View
@@ -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
Something went wrong with that request. Please try again.