...
Code Block |
---|
from voyager import PipelineStep class SampleStep(PipelineStep): def __init__(self): super(SampleStep, self).__init__() def info(self): """ Provides information about the pipeline step including name, title, description and parameters. Parameters are optional. :return: A JSON object/dictionary """ return { "name": "sample", "title": "Sample Step", "description": "Sample pipeline step", "params": [{ "type": "string", "name": "add", "title": "Add", "description": "Field to add" }, { "type": "string", "name": "remove", "title": "Remove", "description": "Field to remove" }] } def run(self, entry, config): """ Runs the pipeline step. This method works by modifying the :param entry: parameter, mutating fields, etc... :param entry: The entry being indexed. :param config: The pipeline step configuration. """ print("INFO adding") add = config.get("add") if add: entry["fields"][add] = "foo" print("INFO removing") remove = config.get("remove") if remove: entry["fields"].pop(remove) if __name__ == "__main__": PipelineStep.main(SampleStep()) view rawsample_pipeline.py hosted with ❤ by GitHub |
Code Block | ||
---|---|---|
| ||
from voyager import PipelineStep
class SampleStep(PipelineStep):
def __init__(self):
super(SampleStep, self).__init__()
def info(self):
"""
Provides information about the pipeline step including name, title, description and parameters. Parameters are optional.
:return: A JSON object/dictionary
"""
return {
"name": "sample",
"title": "Sample Step",
"description": "Sample pipeline step",
"params": [{
"type": "string",
"name": "add",
"title": "Add",
"description": "Field to add"
}, {
"type": "string",
"name": "remove",
"title": "Remove",
"description": "Field to remove"
}]
}
def run(self, entry, config):
"""
Runs the pipeline step.
This method works by modifying the :param entry: parameter, mutating fields, etc...
:param entry: The entry being indexed.
:param config: The pipeline step configuration.
"""
print("INFO adding")
add = config["add"]
if add:
entry["fields"][add] = "foo"
print("INFO removing")
remove = config.get("remove")
if remove:
entry["fields"].pop(remove)
if __name__ == "__main__":
PipelineStep.main(SampleStep())
|
Creating the Pipeline
To create the pipeline:
...