Simon Cross avatar Simon Cross committed b92904e

Add tests for solr search.

Comments (0)

Files changed (1)

         self.assertTrue(mk1_lc in metas)
         self.assertTrue(metas[mk1_lc] == meta_data)
         log.msg('done meta_data_simple')
+
+    def test_solr_search_from_bucket(self):
+        self.bucket.new("user", {"username": "roidrage"}).store()
+        results = yield self.bucket.search("username:roidrage")
+        self.assertEquals(1, len(results["response"]["docs"]))
+
+    def test_solr_search_with_params_from_bucket(self):
+        self.bucket.new("user", {"username": "roidrage"}).store()
+        results = yield self.bucket.search("username:roidrage", wt="xml")
+        result = results.find("result")
+        if not hasattr(result, "iter"):
+            setattr(result, "iter", result.getiterator)
+        self.assertEquals(1, len(list(result.iter("doc"))))
+
+    def test_solr_search_with_params(self):
+        self.bucket.new("user", {"username": "roidrage"}).store()
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:roidrage",
+                                                  wt="xml")
+        result = results.find("result")
+        if not hasattr(result, "iter"):
+            setattr(result, "iter", result.getiterator)
+        self.assertEquals(1, len(list(result.iter("doc"))))
+
+    def test_solr_search(self):
+        self.bucket.new("user", {"username": "roidrage"}).store()
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:roidrage")
+        self.assertEquals(1, len(results["response"]["docs"]))
+
+    def test_add_document_to_index(self):
+        yield self.client.solr().add(self.bucket_name,
+                                     {"id": "doc", "username": "tony"})
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:tony")
+        self.assertEquals("tony",
+                          results["response"]["docs"][0]["fields"]["username"])
+
+    def test_add_multiple_documents_to_index(self):
+        yield self.client.solr().add(self.bucket_name,
+                                     {"id": "dizzy", "username": "dizzy"},
+                                     {"id": "russell", "username": "russell"})
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:russell OR"
+                                                  " username:dizzy")
+        self.assertEquals(2, len(results["response"]["docs"]))
+
+    def test_delete_documents_from_search_by_id(self):
+        yield self.client.solr().add(self.bucket_name,
+                                     {"id": "dizzy", "username": "dizzy"},
+                                     {"id": "russell", "username": "russell"})
+        yield self.client.solr().delete(self.bucket_name, docs=["dizzy"])
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:russell OR"
+                                                  " username:dizzy")
+        self.assertEquals(1, len(results["response"]["docs"]))
+
+    def test_delete_documents_from_search_by_query(self):
+        yield self.client.solr().add(self.bucket_name,
+                                     {"id": "dizzy", "username": "dizzy"},
+                                     {"id": "russell", "username": "russell"})
+        yield self.client.solr().delete(self.bucket_name,
+                                        queries=["username:dizzy",
+                                                 "username:russell"])
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:russell OR"
+                                                  " username:dizzy")
+        self.assertEquals(0, len(results["response"]["docs"]))
+
+    def test_delete_documents_from_search_by_query_and_id(self):
+        yield self.client.solr().add(self.bucket_name,
+                                     {"id": "dizzy", "username": "dizzy"},
+                                     {"id": "russell", "username": "russell"})
+        yield self.client.solr().delete(self.bucket_name,
+                                        docs=["dizzy"],
+                                        queries=["username:russell"])
+        results = yield self.client.solr().search(self.bucket_name,
+                                                  "username:russell OR"
+                                                  " username:dizzy")
+        self.assertEquals(0, len(results["response"]["docs"]))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.