示例#1
0
    def _execute_query(self):
        self.session.increment_requests_count()
        conventions = self.session.conventions
        end_time = time.time() + conventions.timeout
        while True:
            index_query = IndexQuery(
                self.query_builder,
                default_operator=self.using_default_operator,
                sort_hints=self._sort_hints,
                sort_fields=self._sort_fields,
                fetch=self.fetch,
                wait_for_non_stale_results=self.wait_for_non_stale_results,
                start=self._start)
            if self._page_size is not None:
                index_query.page_size = self._page_size
            response = self.session.database_commands.query(
                self.index_name, index_query, includes=self.includes)
            if response["IsStale"] and self.wait_for_non_stale_results:
                if time.time() > end_time:
                    raise ErrorResponseException(
                        "The index is still stale after reached the timeout")
                    time.sleep(0.1)
                continue
            break

        results = []
        response_results = response.pop("Results")
        response_includes = response.pop("Includes")

        for result in response_results:
            entity, metadata, original_metadata = Utils.convert_to_entity(
                result,
                self.object_type,
                conventions,
                self.nested_object_types,
                fetch=False if not self.fetch else True)
            if not self.fetch:
                self.session.save_entity(key=original_metadata.get(
                    "@id", None),
                                         entity=entity,
                                         original_metadata=original_metadata,
                                         metadata=metadata,
                                         document=result)
            results.append(entity)
        self.session.save_includes(response_includes)
        if self._with_statistics:
            return results, response
        return results
 def test_delete_by_index_success(self):
     result = self.db.delete_by_index("indexOperation",
                                      IndexQuery("Name:test"))
     status = self.operation.wait_for_operation_complete(
         result["OperationId"])
     self.assertTrue(status["Completed"] == True
                     and status["Faulted"] == False)
 def test_only_query_change_page_size_and_add_start(self):
     self.db.put_index("Testing", self.index, True)
     start = time.time()
     while True and time.time() - start < 30:
         response = self.db.query("Testing",
                                  IndexQuery("Tag:Products", page_size=1, start=1))
         if not response["IsStale"]:
             break
     self.assertEqual(response["Results"][0]["Name"], "test2")
示例#4
0
    def set_based_scripted(original="USA", newVal="United States of America"):
        index_query = IndexQuery(query="Address_Country:{0}".format(original))
        scripted_patch = ScriptedPatchRequest(
            script="this.Address.Country = newVal;", values={"newVal": newVal})

        DocumentStoreHolder.get_store().database_commands.update_by_index(
            index_name="CompaniesAndCountry",
            query=index_query,
            scripted_patch=scripted_patch)

        with DocumentStoreHolder.get_store().open_session() as session:
            results = list(
                session.query(object_type=Company,
                              wait_for_non_stale_results=True).where(
                                  Address_Country=newVal))

            return results
 def test_fail_none_response(self):
     with self.assertRaises(exceptions.ErrorResponseException):
         self.db.query("IndexIsNotExists", IndexQuery("Tag:Products"))
 def test_fail(self):
     with self.assertRaises(ValueError):
         self.db.query(None, IndexQuery("Tag:Products"))
 def test_get_only_index_entries(self):
     self.db.put_index("Testing", self.index, True)
     response = self.db.query("Testing", IndexQuery("Tag:Products"), index_entries_only=True)
     self.assertFalse("@metadata" in response["Results"][0])
 def test_get_only_metadata(self):
     self.db.put_index("Testing", self.index, True)
     response = self.db.query("Testing", IndexQuery("Tag:Products"), metadata_only=True)
     self.assertFalse("Name" in response["Results"][0])
 def test_only_query(self):
     self.db.put_index("Testing", self.index, True)
     response = self.db.query("Testing", IndexQuery("Tag:Products"))
     self.assertEqual(response["Results"][0]["Name"], "test")
 def test_delete_by_index_success(self):
     self.assertIsNotNone(
         self.db.delete_by_index("Testing", IndexQuery("Name:test")))
 def test_delete_by_index_fail(self):
     with self.assertRaises(exceptions.ErrorResponseException):
         self.db.delete_by_index("region2", IndexQuery("Name:Western"))
 def test_update_by_index_fail(self):
     with self.assertRaises(Exception):
         self.db.update_by_index("", IndexQuery("Name:test"), self.patch)
 def test_update_by_index_success(self):
     self.assertIsNotNone(
         self.db.update_by_index("Raven/DocumentsByEntityName",
                                 IndexQuery("Name:test"), self.patch))
示例#14
0
 def test_only_query_change_page_size_and_add_start(self):
     self.db.put_index("Testing", self.index, True)
     response = self.db.query("Testing", IndexQuery("Tag:Products", page_size=1, start=1))
     self.assertEqual(response["Results"][0]["Name"], "test2")
 def get_index_query(self):
     return IndexQuery(self.query_builder, default_operator=self.using_default_operator,
                       sort_hints=self._sort_hints, sort_fields=self._sort_fields,
                       fetch=self.fetch,
                       wait_for_non_stale_results=self.wait_for_non_stale_results,
                       start=self._start)
 def test_update_by_index_fail(self):
     with self.assertRaises(exceptions.InvalidOperationException):
         result = self.db.update_by_index("c", IndexQuery("Name:test"),
                                          self.patch)
         self.operation.wait_for_operation_complete(result["OperationId"])