1
|
package edu.ucsb.nceas.metacat.index;
|
2
|
|
3
|
import java.io.Reader;
|
4
|
|
5
|
import edu.ucsb.nceas.metacat.index.D1IndexField.DataFormat;
|
6
|
import edu.ucsb.nceas.metacat.index.D1IndexField.Conversion;
|
7
|
|
8
|
/*
|
9
|
* Simple xpath-based indexing. Accepts DOM-parseable data, extracts text data from all
|
10
|
* nodes selected by an XPath expression concatenated into a single Lucene/SOLR field
|
11
|
* body. Equivalent to the DataONE indexer's MergeSolrField bean.
|
12
|
*
|
13
|
* Currently just wraps DataONE SolrField code.
|
14
|
*/
|
15
|
|
16
|
public class XpathIndexField extends FieldSpec {
|
17
|
private static final String textSelector = "text()";
|
18
|
public final String xpath;
|
19
|
|
20
|
public XpathIndexField(String name, String xp) {
|
21
|
super(name);
|
22
|
this.xpath = xp;
|
23
|
}
|
24
|
|
25
|
@Override
|
26
|
public String[] extract(Reader in) {
|
27
|
String s = this.xpath;
|
28
|
if (!this.xpath.endsWith(textSelector)) {
|
29
|
if (this.xpath.charAt(this.xpath.length()-1) != '/') {
|
30
|
s = s + "/";
|
31
|
}
|
32
|
s = s + textSelector;
|
33
|
}
|
34
|
|
35
|
D1IndexField field = new D1IndexField(this.name, s, DataFormat.SINGLE, Conversion.NONE);
|
36
|
return field.extract(in);
|
37
|
}
|
38
|
}
|