### Start EvitaDB Server (Java) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/create-first-database.md Example of starting the EvitaDB server. Ensure this is running before proceeding with API interactions. ```java package io.evitadb.example; import io.evitadb.api.EvitaContract; import io.evitadb.api.EvitaDB; import io.evitadb.api.EvitaDBClient; import io.evitadb.api.EvitaDBConfiguration; import io.evitadb.api.EvitaDBException; import java.io.IOException; public class CompleteStartup { public static void main(String[] args) { try { // Create EvitaDB configuration EvitaDBConfiguration configuration = EvitaDBConfiguration.builder() .build(); // Start EvitaDB instance EvitaDB evitaDB = EvitaDB.start(configuration); // Create EvitaDB client EvitaDBClient client = evitaDB.getClient(); // Use the client for further operations... System.out.println("EvitaDB started successfully."); // Keep the instance running for a while or until interrupted Thread.currentThread().join(); } catch (IOException | InterruptedException e) { e.printStackTrace(); System.err.println("Failed to start EvitaDB: " + e.getMessage()); } } } ``` -------------------------------- ### Start evitaDB Web API Server Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/run-evitadb.md Example of how to instantiate and start the ExternalApiServer in Java. When manually wiring, use `new Evita(config, false)` to defer catalog loading until the server starts. ```java import io.evitadb.core.Evita; import io.evitadb.core.EvitaConfig; import io.evitadb.externalApi.http.ExternalApiServer; public class ApiStartup { public static void main(String[] args) throws Exception { // Load configuration EvitaConfig config = EvitaConfig.load("path/to/evitadb.conf"); // Instantiate Evita engine, deferring catalog loading Evita evita = new Evita(config, false); // Instantiate and start the web API server ExternalApiServer server = new ExternalApiServer(evita); server.start().get(); // Use .get() to block until started // Application logic here... // Ensure server is closed on application exit // Runtime.getRuntime().addShutdownHook(new Thread(server::close)); } } ``` -------------------------------- ### evitaDB Server Startup Output Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/operate/run.md Example console output displayed when the evitaDB server successfully starts within the Docker container. ```plain _ _ ____ ____ _____ _(_) |_ __ _| _ \| __ ) / _ \ \ / / | __/ _` | | | | _ \ | __/\ V /| | || (_| | |_| | |_) | \___| \_/ |_|\__\__,_|____/|____/ You'll see some version here Visit us at: https://evitadb.io Root CA Certificate fingerprint: You'll see some fingerprint here API `graphQL` listening on https://your-server:5555/gql/ API `rest` listening on https://your-server:5555/rest/ API `gRPC` listening on https://your-server:5555/ API `system` listening on http://your-server:5555/system/ ``` -------------------------------- ### Example Query for Telemetry Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/telemetry.md This example demonstrates how to compute query telemetry for a complex filtering and ordering operation. It requires the evitaql-init.java setup. ```evitaql [Example query to compute query telemetry for complex filtering and ordering](/documentation/user/en/query/requirements/examples/telemetry/queryTelemetry.evitaql) ``` -------------------------------- ### Lazy Fetching Example in Java Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md Demonstrates how to perform lazy fetching to enrich an existing entity with additional data. This example assumes a setup defined in evitaql-init.java. ```java import io.evitadb.api.EvitaSessionContract; import io.evitadb.api.EvitaSessionContract.Entity; import io.evitadb.api.EvitaSessionContract.EntityRequirements; import io.evitadb.api.EvitaSessionContract.EntityRequirements.AttributeRequirement; import io.evitadb.api.EvitaSessionContract.EntityRequirements.ReferenceRequirement; import io.evitadb.api.EvitaSessionContract.EntityRequirements.PriceRequirement; import io.evitadb.api.EvitaSessionContract.EntityRequirements.AssociatedDataRequirement; import java.util.Set; public class LazyFetchExample { public static void main(String[] args) { // Assume 'session' is an initialized EvitaSessionContract EvitaSessionContract session = null; // Replace with actual session initialization // 1. Fetch an initial entity with limited requirements Entity initialEntity = session.fetchEntity(EntityRequirements.newBuilder() .addAttributes(AttributeRequirement.newBuilder().setName("name")) .addReferences(ReferenceRequirement.newBuilder().setName("category")) .build()); // 2. Enrich the entity with additional data Entity enrichedEntity = session.enrichEntity(initialEntity, EntityRequirements.newBuilder() .addAttributes(AttributeRequirement.newBuilder().setName("description")) .addAssociatedData(AssociatedDataRequirement.newBuilder().setName("images")) .addPrices(PriceRequirement.newBuilder().setName("default")) .build()); // Now 'enrichedEntity' contains the initial data plus the newly fetched data. // Note: 'enrichedEntity' is a new instance due to immutability. System.out.println("Initial Entity ID: " + initialEntity.getId()); System.out.println("Enriched Entity ID: " + enrichedEntity.getId()); // You can now access 'description', 'images', and 'default' price from enrichedEntity } } ``` -------------------------------- ### Install EvitaDB.Client using Package Manager Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/connectors/c-sharp.md Use the Package Manager console in Visual Studio to install the EvitaDB.Client package. This command installs the latest compatible version. ```Package Manager Install-Package EvitaDB.Client ``` -------------------------------- ### Example Spacing Query Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/paging.md This example demonstrates how to use spacing constraints to display an ad on every even page up to the 10th page and a blog post on the 1st and 4th page. ```evitaql SELECT * FROM "products" WHERE "name" LIKE "%%" spacing( requireConstraint:gap( pageNumber % 2 == 0 && pageNumber <= 10 ) requireConstraint:gap( pageNumber == 1 || pageNumber == 4 ) ) ``` -------------------------------- ### Start evitaDB Server (Java) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/run-evitadb.md Instantiate the Evita class to start the evitaDB server. Keep the reference to call it when needed. The Evita instance loads all indexes into memory on startup. ```java import io.evitadb.core.Evita; // ... Evita evitaDB = new Evita(); // ... use evitaDB ... // Don't forget to close the instance when done // evitaDB.close(); ``` -------------------------------- ### Get product with parameters ordered by their priority Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/ordering/reference.md This example demonstrates how to fetch a product and order its associated parameter values based on their priority. It utilizes the entityProperty constraint to sort references by an attribute of the referenced entity. ```evitaql GET Product WHERE id = "product-1" FETCH references( ParameterValue ) AS parameters ( entityProperty(constraint: orderingConstraint(priority ASC)) ) ``` -------------------------------- ### EvitaQL Syntax Highlighting Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/blog/en/07-advanced-features-on-developers-portal.md This is an example of basic EvitaQL syntax highlighting. Prism is used for syntax highlighting. ```evitaql query( collection('Product'), filterBy( entityPrimaryKeyInSet(110066, 106742), attributeEquals('code', 'lenovo-thinkpad-t495-2') ) ) ``` -------------------------------- ### Example: List E-readers with Price Between €150 and €170.5 Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/filtering/price.md This example demonstrates filtering products in the 'E-readers' category to show only those priced between €150 and €170.5. ```evitaql [Listing E-readers with price between `€150` and `€170.5`](/documentation/user/en/query/filtering/examples/price/price-between.evitaql) ``` -------------------------------- ### Example Price Histogram Query Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/histogram.md Demonstrates how to request a price histogram in EvitaQL. This example shows a basic query for a price histogram. ```evitaql query { products(filter: { ... }) { priceHistogram(argument: 10) } } ``` -------------------------------- ### Install EvitaDB.Client using .NET CLI Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/connectors/c-sharp.md Use the dotnet CLI to add the EvitaDB.Client package to your project. This command installs the latest compatible version. ```.NET CLI dotnet add package EvitaDB.Client ``` -------------------------------- ### evitaDB Readiness Probe Example Response Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/operate/observe.md This is an example JSON response from the readiness probe, indicating the status of various internal APIs. ```json { "status": "READY", "apis": { "rest": "ready", "system": "ready", "graphQL": "ready", "lab": "ready", "observability": "ready", "gRPC": "ready" } } ``` -------------------------------- ### Fetching Entity with References and Attributes Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/fetching.md Example EvitaQL query demonstrating how to fetch an entity along with its references and their specific attributes. This is useful for understanding product-variant combinations. ```evitaql entity(id:1) .referenceContentWithAttributes( argument:"product-variant", requireConstraint:attributeContent( argument:"name", argument:"price" ) ) ``` -------------------------------- ### Example EvitaQL Query for Products with Battery Life >= 40 Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/filtering/comparable.md This example demonstrates how to query for products where the 'battery-life' attribute is greater than or equal to 40 hours. ```evitaql Products with `battery-life` attribute greater than or equal to 40 hours ``` -------------------------------- ### Query Parsing Examples Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/developer/query/query_language_parser.md Examples demonstrating how to use the `QueryParser` to parse queries using both safe and unsafe methods with different argument types. ```APIDOC ## Query Parsing Examples ### Safe Query Parsing ```java import io.evitadb.api.query.QueryParser; import io.evitadb.api.query.parser.DefaultQueryParser; import io.evitadb.api.query.Query; import java.util.Map; QueryParser parser = DefaultQueryParser.getInstance(); // Parsing with positional arguments Query myQuery1 = parser.parseQuery("query(collection(?), filterBy(attributeEqualsTrue(?)))", "a", "b"); // Parsing with named arguments Query myQuery2 = parser.parseQuery("query(collection(@col), filterBy(attributeEqualsTrue(@attr)))", Map.of("col", "a", "attr", "b")); ``` ### Unsafe Query Parsing ```java import io.evitadb.api.query.QueryParser; import io.evitadb.api.query.parser.DefaultQueryParser; import io.evitadb.api.query.Query; QueryParser parser = DefaultQueryParser.getInstance(); // Parsing with direct string literals (unsafe) Query myQuery3 = parser.parseQueryUnsafe("query(collection('a'), filterBy(attributeEqualsTrue('b')))"); ``` ``` -------------------------------- ### Example: Products with battery-capacity <= 125 mWH Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/filtering/comparable.md This example demonstrates how to retrieve products where the 'battery-capacity' attribute is less than or equal to 125 mWH. It utilizes the `attributeLessThanEquals` function for filtering. ```evitaql Products with `battery-life` attribute less than or equal to 125 mWH ``` -------------------------------- ### Create New Entity Example (Java) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/write-data.md Example demonstrating how to create a new entity in EvitaDB. This code is a condensed version and may be split into several parts. ```java var entity = session.upsertEntity(new EntityBuilder(catalog.getEntity("product")) .set("name", "My Product") .set("description", "A great product") .set("price", 100.0) .buildChangeSet()); ``` -------------------------------- ### Example Query with hierarchyWithin and fromRoot Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/hierarchy.md Demonstrates how to use `hierarchyWithin` and `fromRoot` together in a single query to list products and compute a hierarchical menu with statistics. ```java Example of using `hierarchyWithin` and `fromRoot` in a single query ``` -------------------------------- ### GraphQL Get Query Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md Use this query to fetch a specific entity by its unique identifier. It supports a simplified filter syntax and returns a rich entity object. ```graphql query { getProduct(id: "some-product-id") { id name description price } } ``` -------------------------------- ### Example of Segmented Ordering in Practice Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/ordering/segment.md This example demonstrates a practical application of segmented ordering, showing new products first, followed by top-selling items within specific price ranges, and then in-stock items. ```evitaql segments( requireConstraint: segment( filterConstraint:newlyAdded requireConstraint:limit(2) ), segment( filterConstraint:topSelling requireConstraint:limit(1) orderConstraint:price(desc) ), segment( filterConstraint:topSelling requireConstraint:limit(1) orderConstraint:price(desc) filterConstraint:price(500) ), segment( filterConstraint:inStock ), segment() ) ``` -------------------------------- ### Get Entity with Filtered Prices Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/fetching.md Example query to fetch an entity along with its prices that match the filter's price list constraints. This is equivalent to using the priceContentRespectingFilter alias. ```evitaql query { products(filter: { priceInPriceLists: ["employee-basic-price", "basic"] }) { edges { node { id name priceContent { prices { priceListId price } } } } } } ``` -------------------------------- ### Minimal Catalog Change Capture (GraphQL) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/capture-changes.md Sets up a basic subscription to capture changes in the catalogue data API. This example demonstrates the initial setup for monitoring catalogue modifications. ```graphql subscription { catalogChanges { version entity { id type } attribute { name value } } } ``` -------------------------------- ### List products breadth first by order in category Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/ordering/reference.md This example shows how to list products in the 'Accessories' category, ordering them by the category's `order` attribute using a breadth-first traversal of the hierarchy. ```evitaql SELECT p FROM Product p WHERE p.category.name = 'Accessories' ORDER BY traverseByEntityProperty(argument = BREADTH_FIRST, constraint = referenceProperty(property = 'order')) ``` -------------------------------- ### Start evitaDB Server (Linux/macOS) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/query-our-dataset.md Run the evitaDB Docker container, mounting the local 'data' directory and exposing host networking. ```shell docker run --name evitadb -i --net=host \ -v "./data:/evita/data" \ index.docker.io/evitadb/evitadb:latest ``` -------------------------------- ### Basic JUnit 5 test with evitaDB Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/write-tests.md A standard JUnit 5 test class demonstrating how to interact with evitaDB. This example requires manual setup and teardown of the evitaDB instance. ```java import io.evitadb.api.EvitaSessionContract; import io.evitadb.api.query.Query; import io.evitadb.api.query.QueryBuilder; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(DbInstanceParameterResolver.class) public class TestWithEmptyDatasetExample { @Test public void exampleTestCaseWithAssertions(EvitaSessionContract session) { // given final Query query = QueryBuilder.forCollection("Brand").build(); // when final var result = session.query(query); // then assertEquals(0, result.getTotalCount()); } } ``` -------------------------------- ### REST GET Query Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md Use the /get endpoint to fetch a specific entity by its unique key. This endpoint supports a simplified filter and requirements using URL query parameters. ```REST GET /rest/evita/product/get?filter=id=123 ``` -------------------------------- ### EvitaQL Order By Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/research/en/assignment/querying/query_language.md Shows how to define multiple ordering criteria for query results. Supports ascending and descending orders. ```evitaql orderBy( ascending('code'), ascending('create'), priceDescending() ) ``` -------------------------------- ### Setting up Engine Change Capture in Java Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/capture-changes.md Example of setting up the engine change capture in Java using Flow Publisher and Subscriber. ```java final EvitaContract evita = EvitaContract.open( "http://localhost:8080", "tenant", "api-key" ); final Flow.Publisher publisher = evita.system().changeCaptures().openStream(); final Flow.Subscriber subscriber = new Flow.Subscriber() { @Override public void onSubscribe(Flow.Subscription subscription) { subscription.request(1); } @Override public void onNext(ChangeSystemCapture item) { System.out.println("Received change: " + item); // Request next item // subscription.request(1); } @Override public void onError(Throwable throwable) { throwable.printStackTrace(); } @Override public void onComplete() { // This method is never called for infinite streams. } }; publisher.subscribe(subscriber); ``` -------------------------------- ### GraphQL Get Entity Query Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md This query is used when you have a globally unique identifier but don't know the specific entity collection. It returns a generic entity object with common data. ```graphql query { getEntity(id: "some-global-id") { id type version } } ``` -------------------------------- ### REST GET Entity Query Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md Use the special /entity/get endpoint when you have a global unique identifier but do not know the target entity collection. It resolves the entity type and returns the corresponding object. ```REST GET /rest/entity/get?id=a1b2c3d4-e5f6-7890-1234-567890abcdef ``` -------------------------------- ### Query EvitaDB Demo Server (C#) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/query-our-dataset.md Example of querying the EvitaDB demo server after establishing a connection with the C# client. This code snippet requires a separate file for full implementation. ```csharp // Query the demo server // See: /documentation/user/en/get-started/example/query-demo-server.cs ``` -------------------------------- ### GraphQL Get Entity with Target Entity Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md Fetch a specific entity using its global ID and then access its collection-specific data using inline fragments. You must specify the target entity and its fields. ```graphql query { getEntity(id: "some-global-id") { id type version targetEntity { ... on Product { name price } ... on Category { name description } } } } ``` -------------------------------- ### Connect to EvitaDB Demo Server (C#) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/query-our-dataset.md Example of connecting to the EvitaDB demo server using the C# client. This code snippet requires a separate file for full implementation. ```csharp // Connect the demo server // See: /documentation/user/en/get-started/example/connect-demo-server.cs ``` -------------------------------- ### Get product with parameters ordered by group name and name Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/ordering/reference.md Example EvitaQL query to retrieve a product with its parameters, ordered first by the name of the group entity (e.g., Parameter) and then by the name of the referenced entity (e.g., ParameterValue). ```evitaql GET Product WHERE referenceContent( reference: parameters, constraint: entityGroupProperty(constraint: name) ) ORDER BY entityGroupProperty(constraint: name), name ``` -------------------------------- ### List products in 'Accessories' category ordered by predecessor chain Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/ordering/reference.md This example demonstrates ordering products within the 'Accessories' category by the `orderInCategory` attribute of the category reference, traversing the hierarchy in a depth-first manner. ```evitaql SELECT p FROM Product p WHERE p.category.name = 'Accessories' ORDER BY traverseByEntityProperty(constraint = referenceProperty(property = 'orderInCategory')) ``` -------------------------------- ### Get product with parameter values ordered by their name Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/ordering/reference.md This example shows how to retrieve a product and sort its associated parameter values alphabetically by their name. It uses the entityProperty constraint to specify that the ordering should be based on the 'name' attribute of the ParameterValue entities. ```evitaql GET Product WHERE id = "product-1" FETCH references( ParameterValue ) AS parameters ( entityProperty(constraint: orderingConstraint(name ASC)) ) ``` -------------------------------- ### Example: Filter Products by Code Prefix Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/filtering/string.md This example demonstrates how to find products where the 'code' attribute begins with the string 'garmin'. This is useful for searching items with a common prefix in their codes. ```evitaql SELECT * FROM Products WHERE attributeStartsWith(code, "garmin") ``` -------------------------------- ### Fetching Example with Require Constraints Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md Shows how to fetch full entity bodies by using require constraints like 'entity fetch'. This data is fetched greedily. ```java final var entities = evitaClient.query( EvitaQL.builder() .select("*") .from("Product") .where("categoryId = ?", categoryId) .require("entity fetch") .build() ); // entities are of type SealedEntity for (final var entity : entities.getEntities()) { final var id = entity.getId(); final var body = entity.getBody(); // ... } ``` -------------------------------- ### Filter Reference Summary Options and Groups Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/reference.md Use `filterBy` to filter individual options within a reference summary and `filterGroupBy` to filter entire groups. This example demonstrates filtering options whose 'code' attribute contains 'ar' and groups whose 'code' starts with 'o'. ```evitaql referenceSummary( filterBy = "code" ~ "ar", filterGroupBy = "code" ~ "^o" ) ``` -------------------------------- ### Catalog Copy Constructor (Path 2) Source: https://github.com/fgforrest/evitadb/blob/dev/specifications/faceted-partially-indexing/wbs/WBS-11-initial-catalog-load.md This code demonstrates the creation of a new Catalog instance using a copy constructor, with schemas being initialized. This is used during the go-live transition. ```java final Catalog newCatalog = new Catalog( 1L, CatalogState.ALIVE, catalogIndex, archiveCatalogIndex, newCollections, this.persistenceService, this, true // line 1115: initSchemas=true ); ``` -------------------------------- ### Non-uniform Strip of Results Retrieval Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/paging.md Example of how to retrieve a non-uniform strip of results, useful when entity listing is interleaved with content that requires skipping records. This specific example requests records from the 76th through the 95th. ```evitaql query($limit: Int, $offset: Int) { product(filter: {}, recordStrip: {limit: $limit, offset: $offset}) { primaryKey } } ``` -------------------------------- ### Connect to EvitaDB Demo Server (Java) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/get-started/query-our-dataset.md Example of connecting to the EvitaDB demo server using the Java client. This code snippet requires a separate file for full implementation. ```java // Connect the demo server // See: /documentation/user/en/get-started/example/connect-demo-server.java ``` -------------------------------- ### EvitaQL Greater Than Constraint Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/research/en/assignment/querying/query_language.md Example of using the 'greaterThan' constraint to compare an attribute's value with a number. ```evitaql greaterThan('age', 20) ``` -------------------------------- ### EvitaQL Paging Example (Page 2) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/paging.md This EvitaQL snippet demonstrates data retrieval for the second page, considering inserted spacing logic. ```evitaql SELECT * FROM products WHERE id = 1 LIMIT 9 OFFSET 9 ``` -------------------------------- ### EvitaQL Equals Constraint Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/research/en/assignment/querying/query_language.md Basic example of the 'equals' constraint for comparing an attribute's value with a string. ```evitaql equals('code', 'abc') ``` -------------------------------- ### EvitaQL Filter Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/research/en/assignment/querying/query_language.md Example of using filterBy with multiple constraint functions like primaryKey, isTrue, and validInTime. ```evitaql filterBy( and( primaryKey(6), isTrue('visible'), validInTime('validity', 2020-07-30T07:28:13+00:00) ) ) ``` -------------------------------- ### EvitaQL Query Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/use/api/query-data.md This example demonstrates a complex evitaQL query for fetching products with specific criteria, including category, price, currency, and parameters. It also shows how to calculate a price histogram and perform facet impact analysis. ```java Query.builder() .collection("product") .filterBy(Filter.collection("category", "local food", Filter.Operator.IN_COLLECTION, Filter.Operator.WITH_SUBCATEGORIES)) .filterBy(Filter.collection("price", "VIP", "loyal customer", "regular prices", Filter.Operator.IN_COLLECTION)) .filterBy(Filter.collection("currency", "CZK", Filter.Operator.EQUALS)) .filterBy(Filter.range("price", 600.0, 1600.0, Filter.Operator.BETWEEN, Filter.Operator.WITH_VAT)) .filterBy(Filter.collection("parameter", "gluten-free", "original recipe", Filter.Operator.IN_COLLECTION)) .require(Require.histogram("price", 30)) .require(Require.facetImpactAnalysis()) .build() ``` -------------------------------- ### Factorial Function Processor Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/developer/query/expression_language_extension.md An example of a custom FunctionProcessor implementation in Java that computes the factorial of a non-negative integer. ```APIDOC ## Implementing a custom function processor The following example shows a custom function processor that computes the factorial of a non-negative argument: ```java package com.example.evita.expression; import io.evitadb.api.query.expression.function.processor.FunctionProcessor; import io.evitadb.dataType.EvitaDataTypes; import io.evitadb.exception.ExpressionEvaluationException; import javax.annotation.Nonnull; import java.io.Serializable; import java.math.BigDecimal; import java.util.List; import java.util.Objects; public class FactorialFunctionProcessor implements FunctionProcessor { @Nonnull @Override public String getName() { return "factorial"; } @Nonnull @Override public Serializable process(@Nonnull List arguments) throws ExpressionEvaluationException { if (arguments.size() != 1) { throw new ExpressionEvaluationException( "Function `factorial` requires exactly 1 argument, but got " + arguments.size() + "." ); } final Serializable arg = arguments.get(0); if (!(arg instanceof Number)) { throw new ExpressionEvaluationException( "Function `factorial` requires a numeric argument." ); } final long n = Objects.requireNonNull( EvitaDataTypes.toTargetType(arg, Long.class) ); if (n < 0) { throw new ExpressionEvaluationException( "Function `factorial` requires a non-negative argument." ); } long result = 1; for (long i = 2; i <= n; i++) { result *= i; } return BigDecimal.valueOf(result); } } ``` *Note: if the function produces numeric results and you want the engine to use output range narrowing for histogram optimization, implement `NumericFunctionProcessor` instead and provide a `determinePossibleRange()` implementation. Use `PossibleRange.transform()` for single-argument functions and `PossibleRange.combine()` for two-argument functions.* ``` -------------------------------- ### Example Query for Accompanying Prices Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/fetching.md Demonstrates calculating a default accompanying price and a custom-named accompanying price using specified price lists. ```evitaql [Example query to calculate different accompanying prices](/documentation/user/en/query/requirements/examples/fetching/accompanying-price-content.evitaql) ``` -------------------------------- ### GraphQL Paging Example (Page 4) Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/requirements/paging.md This GraphQL example fetches data for the fourth page, respecting inserted spacing. ```graphql query { products(limit: 8, offset: 27) { id name } } ``` -------------------------------- ### Example: Product found by code attribute in given set Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/filtering/comparable.md This example demonstrates how to find products where the 'code' attribute matches one of the provided values. Note that not all provided values may exist in the database. ```evitaql product.filter(attributeInSet(argument="code", argument=["A100", "B200", "C300"])) .limit(3) ``` -------------------------------- ### EvitaDB Attribute Constraint Example Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/blog/en/02-designing-evita-query-language-for-graphql-api.md A simple JSON example demonstrating how to specify a constraint on an entity's attribute value. ```json { "attributeCodeEquals": "iphone7s" } ``` -------------------------------- ### Example: List of products filtered by entity primary key Source: https://github.com/fgforrest/evitadb/blob/dev/documentation/user/en/query/filtering/constant.md This example demonstrates how to retrieve products whose primary keys are declared in the `entityPrimaryKeyInSet` constraint. The order of primary keys in the constraint does not affect the output order, which is ascending by default. ```evitaql GET Product WHERE entityPrimaryKeyInSet(1, 3, 5) ```