enhanced solr writers

pull/1/head
Michael Peter Christen 12 years ago
parent 9644c186a4
commit e84ffdb4f3

@ -83,6 +83,7 @@ public class EnhancedXMLResponseWriter implements QueryResponseWriter {
}
private static void writeProps(final Writer writer, final String name, final NamedList<?> val) throws IOException {
if (val == null) return;
int sz = val.size();
if (sz <= 0) startTagClose(writer, "lst", name); else startTagOpen(writer, "lst", name);
Object v;
@ -153,7 +154,8 @@ public class EnhancedXMLResponseWriter implements QueryResponseWriter {
if (fidx1 + 1 == fidx2) {
if (sf.multiValued()) {
startTagOpen(writer, "arr", fieldName);
writeField(writer, type, null, value.stringValue()); //sf.write(this, null, f1);
String sv = value.stringValue();
writeField(writer, type, null, sv); //sf.write(this, null, f1);
writer.write("</arr>");
} else {
writeField(writer, type, value.name(), value.stringValue()); //sf.write(this, f1.name(), f1);
@ -161,7 +163,8 @@ public class EnhancedXMLResponseWriter implements QueryResponseWriter {
} else {
startTagOpen(writer, "arr", fieldName);
for (int i = fidx1; i < fidx2; i++) {
writeField(writer, type, null, fields.get(i).stringValue()); //sf.write(this, null, (Fieldable)this.tlst.get(i));
String sv = fields.get(i).stringValue();
writeField(writer, type, null, sv); //sf.write(this, null, (Fieldable)this.tlst.get(i));
}
writer.write("</arr>");
writer.write(lb);

@ -109,17 +109,17 @@ public class JsonResponseWriter implements QueryResponseWriter {
List<Fieldable> fields = doc.getFields();
int fieldc = fields.size();
List<String> texts = new ArrayList<String>();
String description = "";
String description = "", title = "";
StringBuilder path = new StringBuilder(80);
for (int j = 0; j < fieldc; j++) {
Fieldable value = fields.get(j);
String fieldName = value.name();
if (YaCySchema.title.name().equals(fieldName)) {
solitaireTag(writer, "title", value.stringValue());
texts.add(value.stringValue());
title = value.stringValue();
texts.add(title);
continue;
}
if (YaCySchema.sku.name().equals(fieldName)) {
urlhash = value.stringValue();
solitaireTag(writer, "link", value.stringValue());
continue;
}
@ -133,14 +133,20 @@ public class JsonResponseWriter implements QueryResponseWriter {
solitaireTag(writer, "guid", urlhash);
continue;
}
if (YaCySchema.host_s.name().equals(fieldName)) {
solitaireTag(writer, "host", value.stringValue());
continue;
}
if (YaCySchema.url_paths_sxt.name().equals(fieldName)) {
path.append('/').append(value.stringValue());
continue;
}
if (YaCySchema.last_modified.name().equals(fieldName)) {
Date d = new Date(Long.parseLong(value.stringValue()));
solitaireTag(writer, "pubDate", HeaderFramework.formatRFC1123(d));
texts.add(value.stringValue());
continue;
}
if (YaCySchema.size_i.equals(fieldName)) {
urlhash = value.stringValue();
int size = value.stringValue() != null && value.stringValue().length() > 0 ? Integer.parseInt(value.stringValue()) : -1;
int sizekb = size / 1024;
int sizemb = sizekb / 1024;
@ -161,6 +167,9 @@ public class JsonResponseWriter implements QueryResponseWriter {
}
}
// compute snippet from texts
solitaireTag(writer, "path", path.toString());
solitaireTag(writer, "title", title.length() == 0 ? (texts.size() == 0 ? path.toString() : texts.get(0)) : title);
List<String> snippet = urlhash == null ? null : snippets.get(urlhash);
writer.write("\"description\":\""); writer.write(serverObjects.toJSON(snippet == null || snippet.size() == 0 ? description : snippet.get(0))); writer.write("\"\n}\n");
if (i < responseCount - 1) {

@ -151,7 +151,7 @@ public class OpensearchResponseWriter implements QueryResponseWriter {
List<Fieldable> fields = doc.getFields();
int fieldc = fields.size();
List<String> texts = new ArrayList<String>();
String description = "";
String description = "", title = "";
for (int j = 0; j < fieldc; j++) {
Fieldable value = fields.get(j);
String fieldName = value.name();
@ -170,14 +170,13 @@ public class OpensearchResponseWriter implements QueryResponseWriter {
continue;
}
if (YaCySchema.title.name().equals(fieldName)) {
solitaireTag(writer, RSSMessage.Token.title.name(), value.stringValue());
texts.add(value.stringValue());
title = value.stringValue();
texts.add(title);
continue;
}
if (YaCySchema.last_modified.name().equals(fieldName)) {
Date d = new Date(Long.parseLong(value.stringValue()));
solitaireTag(writer, RSSMessage.Token.pubDate.name(), HeaderFramework.formatRFC1123(d));
texts.add(value.stringValue());
continue;
}
if (YaCySchema.description.name().equals(fieldName)) {
@ -199,6 +198,8 @@ public class OpensearchResponseWriter implements QueryResponseWriter {
}
}
// compute snippet from texts
solitaireTag(writer, RSSMessage.Token.title.name(), title.length() == 0 ? (texts.size() == 0 ? "" : texts.get(0)) : title);
List<String> snippet = urlhash == null ? null : snippets.get(urlhash);
String tagname = RSSMessage.Token.description.name();
writer.write("<"); writer.write(tagname); writer.write('>');

Loading…
Cancel
Save