Last update: 2015-08-24 11:20
Faceting

Faceting is based on indexed SOLR fields. To facet on a field, the following is required:

  1. Specify the 'solr_column_name' field in template field definition
  2. Make sure the column is available in SOLR: for custom columns, you need to extend the default SOLR schema
  3. Reindex SOLR core: it will populate the solr field (reindex only objects with the custom solr_column)
  4. Specify where and how the facet should appear: a) facets can be specified per node, in the 'config' mysql table, or based on 'onGetNodeFacets' event

TODO onGetNodeFacets to be discussed/implemented.

1. Custom solr_column_name in field configuration

The screenshot shows several fields with custom solr_column_names:

2. Adding a custom field in SOLR schema

See SOLR schema for details.

3. Reindexing SOLR core to populate the custom columns

The script /bin/solr_reindex_core.php allows you to reindex a core:

> php solr_reindex_core.php -c demo -a -l

The command above will fully reindex the demo core.

By default, when called without all parameter, CB will reindex only updated records. The updated flag is found in mysql tree table.

> php solr_reindex_core.php -c demo

After adding a new solr column to a core, and you don't want to fully reindex the database, you may perform a mysql query to mark as updated only the objects you need to be reindexed, and run the above command.

At this moment you should have a custom SOLR schema, and a reindexed core, with populated custom solr fields. To use these columns in faceting:

  • Define facet configuration in mysql config table in facet_configs
  • Specify which facets should be enabled per node (i.e. for all children of a node)

4. Facet configuration

4.1. Default CB facets

CB comes with a set of default facets declared in casebox.config mysql table in default_facet_configs row:

{
  "template_type": {
    "title": "[Type]"
    ,"type": "objectTypes"
  }
  ,"template": {
    "title": "[Template]"
    ,"field": "template_id"
    ,"type": "objects"
  }
  ,"creator": {
    "title": "[Creator]"
    ,"field": "cid"
    ,"type": "users"
  }
  ,"owner": {
    "title": "[Owner]"
    ,"field": "oid"
    ,"type": "users"
  }
  ,"updater": {
    "title": "Updater"
    ,"field": "uid"
    ,"type": "users"
  }
  ,"date": {
    "title": "[Date]"
    ,"facet": "query"
    ,"type": "dates"
    ,"manualPeriod": true
    ,"queries": [
      "today"
      ,"yesterday"
      ,"week"
      ,"month"
    ]
    ,"boolMode": true
  }
  ,"date_end": {
    "title": "End date"
    ,"facet": "query"
    ,"type": "dates"
    ,"queries": [
      "today"
      ,"week"
      ,"next7days"
      ,"next31days"
      ,"month"
    ]
    ,"boolMode": true
  }
  ,"status": {
    "title": "[Status]"
    ,"type": "objects"
 }
  ,"task_status": {
    "title": "[Status]"
    ,"type": "taskStatuses"
 }
  ,"category": {
    "field": "category_id"
    ,"title": "[Category]"
    ,"type": "objects"
    ,"boolMode": true
  }
  ,"importance": {
    "title": "[Importance]"
    ,"type": "importance"
  }
  ,"assigned": {
    "title": "[TaskAssigned]"
    ,"field": "user_ids"
    ,"type": "users"
    ,"boolMode": true
  }
}

By default, CB will enable these facets for the root node of the tree (children objects inherit facet config from the parent. Configuring what facets and for which objects is done in node_facets mysql config table:

{
"1" : [
  "template_type"
  ,"creator"
  ,"template"
  ,"date"
  ,"status"
  ,"category"
  ,"importance"
  ,"assigned"
]
}

4.2. Custom facets

Similar to the default facets, to enable a custom facet you need to define it first, and then specify for which objects it should be enabled.

Custom facets are definded in facet_configs row of config table. Example:

{
    "case_lawyers": {
        "field": "case_lawyers",        // SOLR field
        "title": "Lawyers",             // Facet title in CB filtering panel
        "type": "objects"               // type of facet: 'objects' most of the time
    }
}

The above example will define the color facet. Now we need to specify for which objects (and all children) it should be enabled, it's done in node_facets of the config table:

{
"1" : [
  "creator"
  ,"template"
  ,"date"
  ,"status"
  ,"category"
  ,"importance"
  ,"assigned"
]
  ,"10953": [
    "case_status"
    ,"case_priority"
    ,"case_inspektor"
    ,"case_lawyers"
    ,"case_region"
    ,"case_echr"
  ]
}

The above example will show most of the default facets for all objects (because the root object has id=1), but starting from the object with id=10953 and below, another list of facets will appear (the folder contains legal cases).

In general, the format of node_facets is as follows:

{
    "$objectId": ["facetName1", "facetName2", ...],
    "$objectId": ["facetName3", "facetName4", ...]
}

4.3. Facet types

  • objects: IDs of tree objects are stored in SOLR column, and Casebox will show their titles as facet item captions
  • users: IDs of Casebox users are stored in SOLR
  • dates: to be described

'objects' is the default facet type. Such a facet will treat the value of SOLR column as IDs of tree objects.

CLARIFY: define a list of facets per NodeId, can use a name or a json cfg.

INFO: general casebox.default_facets are JOINed with core.facet_configs, but the later has precedence

Copyright (C) KETSE, HURIDOCS