Customizable loader for castor
Create, transform, compute new fields and more ... see castor-load
You can create new fields in each document, by tweaking the ad hoc
JSON configuration file (the one located besides the data directory
you give to castor, or
the one you give in parameters).
customFields
All the settings concerning custom fields are put in customFields
key in that configuration file.
If you want ot create a fields.title
key in your documents, add:
"customFields": {
"title" : {
"path" : "content.json.Ti"
}
}
The path
key points to a location inside the original document,
using the dot notation.
There are many options (keys like path
) you can use, see
Options.
Note: the generated fields are truncated at 250 characters (if they are of string type).
Multivalued fields
Maybe your fields are multivalued, for example, if you load csv
files.
For example, in a Keywords
columns, you have such values:
Dashboard; Nodejs; Github
Web; Dashboard; Statistics
The direct way, is to point to content.json.keywords
, but that will
distinguish the Dashboard
from the first row to the one from the second row.
Moreover, they will be bound to other keywords on the same row.
The solution is to add a custom field in the JSON configuration file:
"customFields" : {
"Keywords" : {
"path" : "content.json.Keywords",
"separator" : ";"
}
},
Options
TODO
path
Dotted notation to a field within the original document.
Required (with the exception of compute
)
Ex:
"customFields" : {
"doi" : {
"path" : "content.json.doi"
}
}
label
Label (in UTF-8, without any constraint): the name of the field
to display in pages of the application. Optional
Ex:
"customFields" : {
"doi" : {
"label" : "Document Object Identifier"
}
}
default
Default value, used when the field has no value (for example
when the path
is not present in the document). Optional
Ex:
"customFields" : {
"title" : {
"default" : "No title given"
}
}
glue
When the already computed field is an array, and that glue
is set,
each value of the array is joined in a string, using glue
between
every value. Optional
transform
Apply any stringjs chain to the field's value.
Optional
Ex:
"customFields" : {
"slug" : {
"path" : "content.json.title"
"transform" : "slugify()"
}
}
textizer
Apply any stringjs chain to the field's value, then add the result to the fulltext index of the document.
Optional
Ex:
"customFields" : {
"slug" : {
"path" : "content.json.title"
"textizer" : "toString()"
}
}
Note: for fulltext search to work, you have to enable it in mongodb.
For that, add to your mongodb.conf
(maybe located in /etc/mongodb.conf
):
setParameter=textSearchEnabled=true
separator
Split the fields' value into an array, depending on the separator.
Optional
Ex:
"customFields" : {
"Keywords" : {
"path" : "content.json.Keywords",
"separator" : ";"
}
},
type
Transtype the custom field value, in order to be used with another
type than string by compute
, or used by a filter... (values: boolean
, string
, text
, number
, date
).
Optional
Ex:
"customFields" : {
"Year" : {
"path" : "content.json.Py",
"type" : "number"
}
},
pattern
TODO
compute
Compute a funex expression, on
the already generated customFields
.
You can access to the customFields.Year
simply using Year
.
Ex:
"customFields" : {
"Authors" : {
"path" : "content.json.Af",
"separator" : ";"
}
"AuthorNb" : {
"compute" : "Authors.length"
}
},
public
Set it to true to indicate that this custom field should appear
whenever the theme needs to display custom fields.
Optional (default value: false)
Ex:
"customFields" : {
"Authors" : {
"path" : "content.json.Af"
"public" : true
}
"authors" : {
"path" : "content.json.Af"
"separator" : ";"
}
},