Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of *** M y C o R e ***
* See https://www.mycore.de/ for details.
*
* MyCoRe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyCoRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

package org.mycore.solr.index.file.tika;

import org.apache.solr.common.SolrInputDocument;

import com.fasterxml.jackson.databind.node.ValueNode;

/**
* A simple implementation of the MCRTikaMapper interface.
* This implementation converts JSON key and value of a Tika metadata field
* into a property-like ('key=value') string and stores it into the Solr field `tika_metadata`;
* If the property "StripNamespace" is set to true, the namespace of the key is removed before mapping.
* If the property "MultiValueField" is set to true, the values are added as multi value fields, otherwise the values
* will be concatenated to a single string with newlines.
*
* @author Robert Stephan
*/
public class MCRCollectingTikaMapper extends MCRSimpleTikaMapper implements MCRTikaMapper {

private static final String SOLR_FIELD_4_TIKA_METADATA = "tika_metadata";

@Override
protected void mapValueNode(SolrInputDocument document, ValueNode vn, String simplifiedKey) {
String value = getValueNodeAsString(vn);
if (value == null || value.isEmpty()) {
return;
}
document.addField(SOLR_FIELD_4_TIKA_METADATA, simplifiedKey + "=" + value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.node.ValueNode;

/**
Expand Down Expand Up @@ -104,11 +105,11 @@ private void mapArrayNode(SolrInputDocument document, ArrayNode an, String simpl
sb.append(getValueNodeAsString(vn));
}
});
document.addField(simplifiedKey, sb.toString());
mapValueNode(document, new TextNode(sb.toString()), simplifiedKey);
}
}

private void mapValueNode(SolrInputDocument document, ValueNode vn, String simplifiedKey) {
protected void mapValueNode(SolrInputDocument document, ValueNode vn, String simplifiedKey) {
String value = getValueNodeAsString(vn);
if (value == null || value.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,12 @@
"type": "boolean"
}
},
{
"add-field": {
"name": "tika_metadata",
"type": "strings"
}
},
{
"add-field": {
"name": "tika_has_error",
Expand Down
Loading