public class JSONFileCommitter extends Object implements ICommitter, com.norconex.commons.lang.config.IXMLConfigurable
Commits documents to JSON files. There are two kinds of generated files: additions and deletions.
The generated JSON file names are made of a timestamp and a sequence number.
The timestamp matches the first time the
add(String, InputStream, Properties)
or
remove(String, Properties)
methods is called.
Since 2.1.2, you have to option to give a prefix or suffix to files that will be created (default does not add any).
If you request to split additions and deletions into separate files, the generated files will start with "add-" (for additions) and "del-" (for deletions).
[ {"doc-add": { "reference": "document reference, e.g., URL", "metadata": { "name": ["value"], "anothername": [ "multivalue1", "multivalue2" ], "anyname": ["name-value is repeated as necessary"] }, "content": "Document Content Goes here" }}, {"doc-add": { // doc-add is repeated as necessary }}, {"doc-del": {"reference": "document reference, e.g., URL"}}, {"doc-del": {"reference": "repeated as necessary"}} ]
<committer class="com.norconex.committer.core.impl.JSONFileCommitter"> <directory>(path where to save JSON files)</directory> <pretty>[false|true]</pretty> <docsPerFile>(max number of docs per JSON file)</docsPerFile> <compress>[false|true]</compress> <splitAddDelete>[false|true]</splitAddDelete> <fileNamePrefix>(optional prefix to created file names)</fileNamePrefix> <fileNameSuffix>(optional suffix to created file names)</fileNameSuffix> </committer>
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DIRECTORY
Default committer directory
|
Constructor and Description |
---|
JSONFileCommitter()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(String reference,
InputStream content,
com.norconex.commons.lang.map.Properties metadata)
Adds a new or modified document to the target destination.
|
void |
commit()
Commits documents.
|
boolean |
equals(Object obj) |
String |
getDirectory()
Gets the directory where files are committed.
|
int |
getDocsPerFile() |
String |
getFileNamePrefix()
Gets the file name prefix (default is
null ). |
String |
getFileNameSuffix()
Gets the file name suffix (default is
null ). |
int |
hashCode() |
boolean |
isCompress() |
boolean |
isPretty() |
boolean |
isSplitAddDelete() |
void |
loadFromXML(Reader in) |
void |
remove(String reference,
com.norconex.commons.lang.map.Properties metadata)
Removes a document from the target destination.
|
void |
saveToXML(Writer out) |
void |
setCompress(boolean compress) |
void |
setDirectory(String directory)
Sets the directory where files are committed.
|
void |
setDocsPerFile(int docsPerFile) |
void |
setFileNamePrefix(String fileNamePrefix)
Sets an optional file name prefix.
|
void |
setFileNameSuffix(String fileNameSuffix)
Sets an optional file name suffix.
|
void |
setPretty(boolean indent) |
void |
setSplitAddDelete(boolean separateAddDelete) |
String |
toString() |
public static final String DEFAULT_DIRECTORY
public String getDirectory()
public void setDirectory(String directory)
directory
- the directorypublic boolean isPretty()
public void setPretty(boolean indent)
public int getDocsPerFile()
public void setDocsPerFile(int docsPerFile)
public boolean isCompress()
public void setCompress(boolean compress)
public boolean isSplitAddDelete()
public void setSplitAddDelete(boolean separateAddDelete)
public String getFileNamePrefix()
null
).public void setFileNamePrefix(String fileNamePrefix)
fileNamePrefix
- file name prefixpublic String getFileNameSuffix()
null
).public void setFileNameSuffix(String fileNameSuffix)
fileNameSuffix
- file name suffixpublic void add(String reference, InputStream content, com.norconex.commons.lang.map.Properties metadata)
ICommitter
add
in interface ICommitter
reference
- document reference (e.g. URL)content
- document contentmetadata
- document metadatapublic void remove(String reference, com.norconex.commons.lang.map.Properties metadata)
ICommitter
remove
in interface ICommitter
reference
- document reference (e.g. URL)metadata
- document metadatapublic void commit()
ICommitter
commit
in interface ICommitter
public void loadFromXML(Reader in)
loadFromXML
in interface com.norconex.commons.lang.config.IXMLConfigurable
public void saveToXML(Writer out) throws IOException
saveToXML
in interface com.norconex.commons.lang.config.IXMLConfigurable
IOException
Copyright © 2009–2020 Norconex Inc.. All rights reserved.