Table of Contents

Working with queries

How to work with queries in DW10

A query is a request for data from an index. They are used extensively in DynamicWeb, both in frontend and backend, to query the system for product data, content, users, and so on and so forth.

  • For a basic understanding of how to create a query read the Queries article in the Manual
  • For a more in-depth technical look at queries and indexes consult the How Lucene.NET works article

In this article you will find a number of hands-on example of how to create specific queries. It is the hope that these examples will help you learn more about how to work with queries when implementing a solution.

Customer assortments

Customer assortments are subsets of products associated with specific users or user groups, so that logged-in users will only have access to products in the assortments they as members of.

To make sure a customer only sees the products they have access to you can:

  • Compare the product index field Assortment IDs with the value retrieved by the AssortmentIDs macro
  • Include all products not in an assortment

This can be done by creating these two expressions inside an OR-group:

AssortmentsExpressions

Matching null values

Lucene.NET, the software library used to build repositories, does not index Null values or empty strings at all. This means that you cannot easily isolate index entries without a value in them. A workaround is to add an expression group matching all records with a value, and then negate it.

Finding products without a DataModel

Products can be assigned to channel shops without being assigned to a DataModel. To identify products that are missing a data structure, the standard product index includes the generated field:

Datamodel Structure IDs

This field contains the IDs of all DataModel (shop as data structure) assignments for a product.

To find products that are not assigned to any DataModel, create a query with the following expressions:

  • Field: Datamodel structure IDs
  • Operator: IsEmpty

This query returns all products that do not belong to any DataModel, even if they are assigned to one or more channel shops.

To top