getDescription() {
return getStringList(CollectionSchema.description_txt);
}
public static URIMetadataNode importEntry(final String propStr) {
if (propStr == null || propStr.isEmpty() || propStr.charAt(0) != '{' || !propStr.endsWith("}")) {
ConcurrentLog.severe("URIMetadataNode", "importEntry: propStr is not proper: " + propStr);
return null;
}
try {
return new URIMetadataNode(MapTools.s2p(propStr.substring(1, propStr.length() - 1)));
} catch (final kelondroException e) {
// wrong format
ConcurrentLog.severe("URIMetadataNode", e.getMessage());
return null;
}
}
protected StringBuilder corePropList() {
// generate a parseable string; this is a simple property-list
final StringBuilder s = new StringBuilder(300);
// create new formatters to make concurrency possible
final GenericFormatter formatter = new GenericFormatter(GenericFormatter.FORMAT_SHORT_DAY, GenericFormatter.time_minute);
try {
s.append("hash=").append(ASCII.String(this.hash()));
s.append(",url=").append(crypt.simpleEncode(this.url().toNormalform(true)));
s.append(",descr=").append(crypt.simpleEncode(this.dc_title()));
s.append(",author=").append(crypt.simpleEncode(this.dc_creator()));
s.append(",tags=").append(crypt.simpleEncode(Tagging.cleanTagFromAutotagging(this.dc_subject())));
s.append(",publisher=").append(crypt.simpleEncode(this.dc_publisher()));
s.append(",lat=").append(this.lat());
s.append(",lon=").append(this.lon());
s.append(",mod=").append(formatter.format(this.moddate()));
s.append(",load=").append(formatter.format(this.loaddate()));
s.append(",fresh=").append(formatter.format(this.freshdate()));
s.append(",referrer=").append(this.referrerHash() == null ? "" : ASCII.String(this.referrerHash()));
s.append(",md5=").append(this.md5());
s.append(",size=").append(this.filesize());
s.append(",wc=").append(this.wordCount());
s.append(",dt=").append(this.doctype());
s.append(",flags=").append(this.flags().exportB64());
s.append(",lang=").append(this.language());
s.append(",llocal=").append(this.llocal());
s.append(",lother=").append(this.lother());
s.append(",limage=").append(this.limage());
s.append(",laudio=").append(this.laudio());
s.append(",lvideo=").append(this.lvideo());
s.append(",lapp=").append(this.lapp());
s.append(",score=").append(Float.toString(this.score()));
if (this.word() != null) {
// append also word properties
final String wprop = this.word().toPropertyForm();
s.append(",wi=").append(Base64Order.enhancedCoder.encodeString(wprop));
}
return s;
} catch (final Throwable e) {
ConcurrentLog.logException(e);
return null;
}
}
/**
* the toString format must be completely identical to URIMetadataRow because that is used
* to transport the data over p2p connections.
*/
public String toString(String snippet) {
// add information needed for remote transport
final StringBuilder core = corePropList();
if (core == null)
return null;
core.ensureCapacity(core.length() + snippet.length() * 2);
core.insert(0, '{');
core.append(",snippet=").append(crypt.simpleEncode(snippet));
core.append('}');
return core.toString();
//return "{" + core + ",snippet=" + crypt.simpleEncode(snippet) + "}";
}
/**
* @return the object as String.
* This e.g. looks like this:
* {hash=jmqfMk7Y3NKw,referrer=------------,mod=20050610,load=20051003,size=51666,wc=1392,cc=0,local=true,q=AEn,dt=h,lang=uk,url=b|aHR0cDovL3d3dy50cmFuc3BhcmVuY3kub3JnL3N1cnZleXMv,descr=b|S25vd2xlZGdlIENlbnRyZTogQ29ycnVwdGlvbiBTdXJ2ZXlzIGFuZCBJbmRpY2Vz}
*/
@Override
public String toString() {
final StringBuilder core = corePropList();
if (core == null) return null;
core.insert(0, '{');
core.append('}');
return core.toString();
}
private int getInt(CollectionSchema field) {
assert !field.isMultiValued();
assert field.getType() == SolrType.num_integer;
Object x = this.getFieldValue(field.getSolrFieldName());
if (x == null) return 0;
if (x instanceof Integer) return ((Integer) x).intValue();
if (x instanceof Long) return ((Long) x).intValue();
return 0;
}
private Date getDate(CollectionSchema field) {
assert !field.isMultiValued();
assert field.getType() == SolrType.date;
Date x = (Date) this.getFieldValue(field.getSolrFieldName());
if (x == null) return new Date(0);
Date now = new Date();
return x.after(now) ? now : x;
}
private Date[] getDates(CollectionSchema field) {
assert field.isMultiValued();
assert field.getType() == SolrType.date;
@SuppressWarnings("unchecked")
List x = (List) this.getFieldValue(field.getSolrFieldName());
if (x == null) return new Date[0];
return x.toArray(new Date[x.size()]);
}
private String getString(CollectionSchema field) {
assert !field.isMultiValued();
assert field.getType() == SolrType.string || field.getType() == SolrType.text_general || field.getType() == SolrType.text_en_splitting_tight;
Object x = this.getFieldValue(field.getSolrFieldName());
if (x == null) return "";
if (x instanceof ArrayList) {
@SuppressWarnings("unchecked")
ArrayList xa = (ArrayList) x;
return xa.size() == 0 ? "" : xa.get(0);
}
return (String) x;
}
@SuppressWarnings("unchecked")
private ArrayList getStringList(CollectionSchema field) {
assert field.isMultiValued();
assert field.getType() == SolrType.string || field.getType() == SolrType.text_general;
Object r = this.getFieldValue(field.getSolrFieldName());
if (r == null) return new ArrayList(0);
if (r instanceof ArrayList) {
return (ArrayList) r;
}
ArrayList a = new ArrayList(1);
a.add((String) r);
return a;
}
@SuppressWarnings("unchecked")
private ArrayList getIntList(CollectionSchema field) {
assert field.isMultiValued();
assert field.getType() == SolrType.num_integer;
Object r = this.getFieldValue(field.getSolrFieldName());
if (r == null) return new ArrayList(0);
if (r instanceof ArrayList) {
return (ArrayList) r;
}
ArrayList a = new ArrayList(1);
a.add((Integer) r);
return a;
}
}