Exemplo n.º 1
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
Exemplo n.º 2
0
    def query2(externalId="ALFKI"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(session.query(object_type=Company,
                                              with_statistics=True).
                                where(ExternalId=externalId))

            return query[0] if query else None
Exemplo n.º 3
0
    def query1(country="UK"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(session.query(object_type=Company,
                                              with_statistics=True).
                                where(**{"Address.Country": country}))

            return query[0] if query else None
Exemplo n.º 4
0
    def query1(country="UK"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(
                session.query(object_type=Company, with_statistics=True).where(
                    **{"Address.Country": country}))

            return query[0] if query else None
Exemplo n.º 5
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
Exemplo n.º 6
0
    def delete(company_id=2):
        with DocumentStoreHolder.get_store().open_session() as session:
            company_id = "{0}/{1}".format(DocumentConvention.default_transform_type_tag_name(Company.__name__),
                                          company_id)

            session.delete(company_id)
            session.save_changes()
            return "CompanyId {0} Deleted  Successfully.".format(company_id)
Exemplo n.º 7
0
    def query2(externalId="ALFKI"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(
                session.query(
                    object_type=Company,
                    with_statistics=True).where(ExternalId=externalId))

            return query[0] if query else None
Exemplo n.º 8
0
    def query3(city="Berlin"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(session.query(object_type=Company, with_statistics=True,
                                              nested_object_types={"Address": AddressC,
                                                                   "Contact": ContactC}).
                                where_equals("Address.City", city))

            return query[0] if query else None
Exemplo n.º 9
0
    def map_reduce_using_document_query():
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(
                session.query(object_type=ProductSales.Result,
                              index_name=ProductSales.__name__,
                              with_statistics=True))

            return query
Exemplo n.º 10
0
    def static_query(high_price=500, delay_days=35):
        with DocumentStoreHolder.get_store().open_session() as session:
            query = list(
                session.query(index_name="CostlyOrders").where_greater_than(
                    "Price", high_price).and_also().where_greater_than(
                        "Delay",
                        Utils.timedelta_tick(timedelta(days=delay_days))))

            return query[0] if query else None
Exemplo n.º 11
0
    def static_query(high_price=500, delay_days=35):
        with DocumentStoreHolder.get_store().open_session() as session:
            query = list(
                session.query(index_name="CostlyOrders").
                where_greater_than("Price", high_price).
                and_also().
                where_greater_than("Delay", Utils.timedelta_tick(timedelta(days=delay_days))))

            return query[0] if query else None
Exemplo n.º 12
0
 def deploy_indexes():
     store = DocumentStoreHolder.get_store()
     ProductSales().execute(store)
     LastFmAnalyzed().execute(store)
     CompaniesAndCountry().execute(store)
     CostlyOrders().execute(store)
     NameAndCountry().execute(store)
     OrderByCompanyAndCountryWithBoost().execute(store)
     OrderByCompanyAndCountry().execute(store)
Exemplo n.º 13
0
    def full_text_search(searchTerm="Jazz"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(session.query(object_type=LastFm, with_statistics=True,
                                              index_name=LastFmAnalyzed.__name__).
                                search("Query", search_terms=searchTerm))

            server_time = timedelta(milliseconds=stats["DurationMilliseconds"])

            return query
Exemplo n.º 14
0
 def boosting_disabled(city="London", country="Denmark"):
     with DocumentStoreHolder.get_store().open_session() as session:
         orders = list(session.query(object_type=Order, index_name="OrderByCompanyAndCountry",
                                     wait_for_non_stale_results=True,
                                     nested_object_types={"OrderedAt": datetime, "RequireAt": datetime,
                                                          "ShippedAt": datetime, "ShipTo": AddressC,
                                                          "Lines": OrderLine}).
                       where(ShipTo_City=city, ShipTo_Country=country))
         
         return orders
Exemplo n.º 15
0
    def boosting_enabled(city="London", country="Denmark"):
        with DocumentStoreHolder.get_store().open_session() as session:
            orders = list(session.query(object_type=Order, index_name="OrderByCompanyAndCountryWithBoost",
                                        wait_for_non_stale_results=True,
                                        nested_object_types={"OrderedAt": datetime, "RequireAt": datetime,
                                                             "ShippedAt": datetime, "ShipTo": AddressC,
                                                             "Lines": OrderLine}).
                          where(ShipTo_City=city, ShipTo_Country=country))
						  
            return orders
Exemplo n.º 16
0
    def store():
        with DocumentStoreHolder.get_store().open_session() as session:
            company = Company(Name="Hibernating Rhinos",
                              ExternalId="HR",
                              Phone="+972 4 622 7811",
                              Fax="+972 153 4 622 7811")

            session.store(company)
            session.save_changes()

            return "New Company Created Successfully"
Exemplo n.º 17
0
    def edit(company_id=1):
        with DocumentStoreHolder.get_store().open_session() as session:
            company_id = "{0}/{1}".format(DocumentConvention.default_transform_type_tag_name(Company.__name__),
                                          company_id)

            company = session.load(company_id, object_type=Company)

            company.Address.Line2 = "Zip 12345"
            session.save_changes()

            return "CompanyId {0} Edited Successfully.".format(company_id)
Exemplo n.º 18
0
    def full_text_search(searchTerm="Jazz"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(
                session.query(object_type=LastFm,
                              with_statistics=True,
                              index_name=LastFmAnalyzed.__name__).search(
                                  "Query", search_terms=searchTerm))

            server_time = timedelta(milliseconds=stats["DurationMilliseconds"])

            return query
Exemplo n.º 19
0
    def query3(city="Berlin"):
        with DocumentStoreHolder.get_store().open_session() as session:
            query, stats = list(
                session.query(object_type=Company,
                              with_statistics=True,
                              nested_object_types={
                                  "Address": AddressC,
                                  "Contact": ContactC
                              }).where_equals("Address.City", city))

            return query[0] if query else None
Exemplo n.º 20
0
    def edit(company_id=1):
        with DocumentStoreHolder.get_store().open_session() as session:
            company_id = "{0}/{1}".format(
                DocumentConvention.default_transform_type_tag_name(
                    Company.__name__), company_id)

            company = session.load(company_id, object_type=Company)

            company.Address.Line2 = "Zip 12345"
            session.save_changes()

            return "CompanyId {0} Edited Successfully.".format(company_id)
Exemplo n.º 21
0
 def multi_map_indexing_query(country="USA"):
     with DocumentStoreHolder.get_store().open_session() as session:
         return list(
             session.query(index_name="NameAndCountry",
                           wait_for_non_stale_results=True).search(
                               "Country", country).select("Name", "Id"))
Exemplo n.º 22
0
 def multi_map_indexing_query(country="USA"):
     with DocumentStoreHolder.get_store().open_session() as session:
         return list(session.query(index_name="NameAndCountry",
                                   wait_for_non_stale_results=True).
                     search("Country", country).select("Name", "Id"))