Permalink
Browse files

Added changes from Pull Request 34 feedback:

- Added Solr tests for Terms queries
- Added more comprehensive docstrings
- More comprehensive Elastic Tests
- Fixed Solr Terms queries
  • Loading branch information...
1 parent 8978eaf commit dd61da6ead3f9f480e7b2f60dd73916160d113fa @adamalix adamalix committed May 14, 2012
@@ -421,8 +421,12 @@ object Ast {
def extend(): String = {
escaped match {
// hack to fix wrapping the queries in a List()
- case true => {'"' + escape(query.mkString("")) + '"'}
- case false => '"' + query.toString + '"'
+ case true => {
+ val queries = query.map(q => {'"' + escape(q.toString) + '"'})
+ queries.mkString(" OR ")
+ }
+// case true => {'"' + query.mkString("\" OR \"")
+ case false => '"' + query.mkString(" OR ") + '"'
}
}
/** @inheritdoc */
@@ -439,8 +439,8 @@ trait SolrGeoHash {
}
//Default geohash, does nothing.
object NoopSolrGeoHash extends SolrGeoHash {
- def coverString (geoLat: Double, geoLong: Double, radiusInMeters: Int, maxCells: Int ): Seq[String] = List("pleaseUseaRealGeoHash")
- def rectCoverString(topRight: (Double, Double), bottomLeft: (Double, Double), maxCells: Int = 0, minLevel: Int = 0, maxLevel: Int = 0): Seq[String] = List("pleaseUseaRealGeoHash")
+ def coverString (geoLat: Double, geoLong: Double, radiusInMeters: Int, maxCells: Int ): Seq[String] = List("pleaseUseaRealGeoHash", "thisIsForFunctionalityTests")
+ def rectCoverString(topRight: (Double, Double), bottomLeft: (Double, Double), maxCells: Int = 0, minLevel: Int = 0, maxLevel: Int = 0): Seq[String] = List("pleaseUseaRealGeoHash", "thisIsForFunctionalityTests")
}
trait SlashemSchema[M <: Record[M]] extends Record[M] {
@@ -876,7 +876,10 @@ trait SlashemField[V, M <: Record[M]] extends OwnedField[M] {
//Slashem field types
class SlashemStringField[T <: Record[T]](owner: T) extends StringField[T](owner, 0) with SlashemField[String, T]
/**
- * Field type that can be queried without analyzing whitespace.
+ * Field type that can be queried without analyzing.
+ *
+ * Ex: multi-value field or a whitespace tokenized field where
+ * search terms are always for a specific token.
*
* @see SlashemStringField
*/
@@ -313,20 +313,26 @@ 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 (_.termsfield in List("termhit", "lol")) fetch()
Assert.assertEquals(response1.response.results.length, 2)
Assert.assertEquals(response2.response.results.length, 0)
+ Assert.assertEquals(response3.response.results.length, 1)
}
@Test
def testIntListFieldEmptyIn {
- val response = ESimplePanda where (_.favnums in List()) fetch()
- Assert.assertEquals(response.response.results.length, 0)
+ val response1 = ESimplePanda where (_.favnums in List()) fetch()
+ val response2 = ESimplePanda where (_.termsfield in List()) fetch()
+ Assert.assertEquals(response1.response.results.length, 0)
+ Assert.assertEquals(response2.response.results.length, 0)
}
@Test
def testIntListFieldEmptyNin {
- val response = ESimplePanda where (_.favnums nin List()) fetch()
- Assert.assertEquals(response.response.results.length, 8)
+ val response1 = ESimplePanda where (_.favnums nin List()) fetch()
+ val response2 = ESimplePanda where (_.termsfield nin List()) fetch()
+ Assert.assertEquals(response1.response.results.length, 8)
+ Assert.assertEquals(response2.response.results.length, 8)
}
@Test
@@ -344,6 +350,11 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
val ids2 = response2.response.oids
// All three docs with favnums should be returned, none contain 99
Assert.assertEquals(ids2.intersect(idsWithFavNums).length, 3)
+
+ val response3 = ESimplePanda where (_.termsfield nin List("termhit")) fetch()
+ val ids3 = response3.response.oids
+ // All three docs with favnums should be returned, none contain 99
+ Assert.assertEquals(ids3.intersect(idsWithFavNums).length, 2)
}
@Test
@@ -562,7 +562,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"qf" -> "text",
"qf" -> "ngram_name^0.2",
"qf" -> "tags^0.01",
- "fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\")",
+ "fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\" OR \"thisIsForFunctionalityTests\")",
"tieBreaker" -> "0.2",
"fl" -> "id,name,userid,mayorid,category_id_0,popularity,decayedPopularity1,lat,lng,checkin_info,score,hasSpecial,address,crossstreet,city,state,zip,country,checkinCount,partitionedPopularity",
"bq" -> "name:(holden's hobohut)^10.0",
@@ -609,7 +609,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"qf" -> "text",
"qf" -> "ngram_name^0.2",
"qf" -> "tags^0.01",
- "fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\")",
+ "fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\" OR \"thisIsForFunctionalityTests\")",
"tieBreaker" -> "0.2",
"fl" -> "id,name,userid,mayorid,category_id_0,popularity,decayedPopularity1,lat,lng,checkin_info,score,hasSpecial,address,crossstreet,city,state,zip,country,checkinCount,partitionedPopularity",
"bq" -> "name:(holden's hobohut)^10.0",
@@ -630,7 +630,7 @@ class QueryTest extends SpecsMatchers with ScalaCheckMatchers {
"q" -> "(DJ Hixxy)",
"start" -> "0",
"rows" -> "10",
- "fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\")")
+ "fq" -> "geo_s2_cell_ids:(\"pleaseUseaRealGeoHash\" OR \"thisIsForFunctionalityTests\")")
Assert.assertEquals(Nil, ((qp.toSet &~ expected.toSet)).toList)
Assert.assertEquals(Nil, (expected.toSet &~ qp.toSet).toList)
}

0 comments on commit dd61da6

Please sign in to comment.