Documentation Home

Order, Fulfillment Order, and Customer Sort and Filter:

The OMS module uses SOLR to index Orders, Fulfillment Orders, and Customer. Filter and Sort functionality uses the SOLR capabilities to search (filter) and sort these entities. This means that the any fields that needs to be used for filtering or sorting must be in the associated SOLR index.

Adding fields to SOLR documents

With the introduction of the Enterprise Search module, fields can easily be added to SOLR documents by setting up select "field" tables in the database. Some of these tables can be managed in the admin but for this documentation we will cover the tables and the data that is needed.

BLC_FIELD table

The base table that must be setup is the BLC_FIELD table. This table defines the name and source of the fields for each entity type. Out of the box the system supports CUSTOMER, FULFILLMENT_ORDER, ORDER, and PRODUCT. Each entry in this table will define:

abbreviation - defines the property name that will be used in the SOLR document
entity_type - one of CUSTOMER, FULFILLMENT_ORDER, ORDER, and PRODUCT
friendly_name - name that will be displayed in the admin
property_name - relative to the entity_type, the Java property desired to be added to the document
translatable - whether this field will have variations based on language/locale

Here is an example of adding FulfillmentOrder#dateCreated to the table (note that the field_id need to be unique)

INSERT INTO `blc_field` (`FIELD_ID`, `ABBREVIATION`, `ENTITY_TYPE`, `FRIENDLY_NAME`, `PROPERTY_NAME`, `TRANSLATABLE`)
VALUES
    (-4803, 'fodtcreated', 'FULFILLMENT_ORDER', 'Fulfillment Order Date Created', 'auditable.dateCreated', NULL);

Note that the abbreviation "fodtcreated" will be the property name in the SOLR document. The value of abbreviation is not important but it needs to be unique by entity_type.

BLC_INDEX_FIELD:

The next table to update is the BLC_INDEX_FIELD. This table has a reference to the BLC_FIELD table and defines whether the field will be searchable. When searchable, the field will be utilized from the front-end and customer do a search. This is probably most applicable for Product/Catalog searches.

The FulfillmentOrder#dateCreated will not be searchable.

INSERT INTO `blc_index_field` (`INDEX_FIELD_ID`, `SEARCHABLE`, `FIELD_ID`)
VALUES
    (-1631, 0, -1631);

Again, the index_field_id needs to be unique. If you are inserting this row manually, you should use a negative ID to prevent collisions with the Hibernate sequence manager.

BLC_INDEX_FIELD_TYPE:

This is the last table and describes for SOLR the type of field that will be added to the document. SOLR have a predefined list of field types that can be used. New field types can be added but that is an advanced SOLR concept we will not cover here.

SOLR document property names is a combination of the abbreviation and the fieldType:

abbreviation_fieldType

These are the more common field types:
i - Integer
s - String
l - Long
t - Text
b - Boolean
d - Double
dt - Date

Types can also support multi-values (i.e. arrays):
is - Integer with multiple values
ss - String with multiple values
dts - Date with multiple values
etc...

It's important that you use the SOLR short/abbreviation for the field type when you populate the BLC_INDEX_FIELD_TYPE table.

Here would be the entry for the FulfillmentOrder#dateCreated field type:

INSERT INTO `blc_index_field_type` (`INDEX_FIELD_TYPE_ID`, `FIELD_TYPE`, `INDEX_FIELD_ID`)
VALUES
    (-1638, 'dt', -1632);

A couple notes on the insert statement:

  • The index_field_type_id column must be unique. If you are inserting this row manually, you should use a negative ID to prevent collisions with the Hibernate sequence manager.
  • The index+field_id relates to the BLC_INDEX_FIELD table.

### SOLR Reindex
Once those three tables are populated, you can do a full reindex of the appropriate collection. Once the reindex is complete the new field should exist on the SOLR document

### Sort and Filter
Once the field exists in the SOLR document, sorting and filtering can be used. As mentioned, all sorting and filtering happen in SOLR. The SOLR query will return a list of ID's for the entity and those ID's are used to look up all the details against the database.

Say that we are getting Orders. The basic steps are:

1) Query the Orders collection (with sorting or filtering as needed). The results will return a list of Order ID's.
2) A query will be done aginst the BLC_ORDER table where ID in ({list of ID's}).

Note that the associated logic for converting a FilterAndSortCriteria object to a SOLR query is handled in the associated CustomPersistenceHandler. For example, the Order Custom Persistence Handler:

com.broadleafcommerce.oms.admin.order.service.handler.OMSOrderCustomPersistenceHandler