Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Lucene Search Engine and Indexing

Lucene Search Engine and Indexing

Search fields and index fields

Object Search Fields Index Fields Locale Comment

product(SF)

keyword

product display name; brand display name; sku code; attribute value which are defined indexable

all locales

If you give multiple keywords, like: keyword1 keyword2. The search result will products whose index fields contain BOTH keyword1 and keyword2.

product(SF)

active only

start date & end date

n/a

product is active if : start date <= now <= end date

category(CM)

keyword

category display name, code

system default locale

category(CM)

active only

start date & end date

n/a

category is active if : start date <= now <= end date

category(CM)

inactive only

start date & end date

n/a

category is inactive if : now <= start date or now >= end date

product(CM)

keyword

product display name, code, sku code

system default locale

product(CM)

active only

start date & end date

n/a

product is active if : start date <= now <= end date

product(CM)

inactive only

start date & end date

n/a

product is active if : now <= start date or now >= end date

product(CM)

brand code

brand code

n/a

product(CM)

category uid

all ancestor categories uids

n/a

customer(CM)

first name

customer first name

n/a

customer(CM)

last name

customer last name

n/a

customer(CM)

customer number

customer number(uidPk)

n/a

customer(CM)

email

customer email

n/a

customer(CM)

phone number

phone number

n/a

For an object search, if multiple search fields are given, it's always an AND relationship among all of them.

Index builder

The index builder constructs the index that Lucene uses to execute searches. The index builder is invoked by a Quartz scheduled job configured in Scheduled Jobs (Search Server). The index builder uses properties from buildIndex.properties, which is described in the following section. There are several index builders that build indices for different entities and their index files are named according to the pattern xBuildIndex.properties where x is the name of the entity being indexed such as a customer or product.

Key classes and files

The following files and Java classes are also related to the Lucene search index support.

buildIndex.properties

  • Contains the following two properties.
    • Rebuild - set to true to create a new index. This provides a way to create a new index when the server is already started. The default value is false and the value is also set to false after a successful index build/update.
    • LastBuildDate - the date when the last build was executed successfully.

IndexBuildService

  • This service class handles the building of the Lucene index as well as updating and deleting documents from the index.
  • provides two key methods.
    • void buildIndex(final boolean rebuild) - If rebuild is true, creates a new index, if rebuild is false, updates the existing index.
    • void buildIndex() - Checks the following conditions to determine whether to create a new index or update an existing index.
      • if the Rebuild property in buildIndex.properties is set to true, calls buildIndex(true)
      • if LastBuildDate property in buildIndex.properties is null or empty, calls buildIndex(true)
      • else calls buildIndex(false)

PropertiesDao

  • This DAO reads and saves properties files.
  • getPropertiesFile(buildIndex) - Retrieves buildIndex.properties.
  • storePropertiesFile(buildIndexProperties, buildIndex) - saves the Rebuild and LastBuildDate properties to buildIndex.properties

ProductService

  • This service class handles product retrieval.
  • list() - Returns list of all products, this is used to create a new index.
  • findByModifiedDate(lastBuildDate) - Returns a list of products whose modified date is after the last build date, this is used to update index.
  • findByDeletedDate(lastBuildDate) - Returns a list of deleted products whose deleted date is after the last build date, this is used to update index.

IndexDao

  • This DAO creates new indices and updates/deletes documents from existing indices.
  • createIndex(documentList, locale) - Create a new index with the passed in list of documents.
  • updateDocumentInIndex(documentList, product uid key, locale) - Update a document in an existing index.
  • deleteDocumentInIndex(termsList, locale) - Delete a document in an existing index.