added default facet fields for json response format (stub)

pull/1/head
Michael Peter Christen 13 years ago
parent 2f218df55d
commit 975bc95ddf

@ -149,7 +149,7 @@ public class searchresult {
if (connector == null) return null;
// do the solr request
SolrQueryRequest req = connector.request(post.toSolrParams());
SolrQueryRequest req = connector.request(post.toSolrParams(null));
SolrQueryResponse response = null;
Exception e = null;
try {response = connector.query(req);} catch (SolrException ee) {e = ee;}

@ -38,11 +38,13 @@ import net.yacy.cora.services.federated.solr.SolrServlet;
import net.yacy.kelondro.logging.Log;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.search.index.YaCySchema;
import net.yacy.search.query.AccessTracker;
import net.yacy.search.query.SnippetProcess;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.FastWriter;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
@ -154,7 +156,9 @@ public class select {
"") : env.getConfig(SwitchboardConstants.GREETING, "");
((OpensearchResponseWriter) responseWriter).setTitle(promoteSearchPageGreeting);
}
if (responseWriter instanceof OpensearchResponseWriter) {
// if this is a call to YaCys special search formats, enhance the query with field assignments
if (responseWriter instanceof JsonResponseWriter || responseWriter instanceof OpensearchResponseWriter) {
// add options for snippet generation
post.put("hl", "true");
post.put("hl.fl", "text_t,h1,h2");
@ -167,8 +171,9 @@ public class select {
EmbeddedSolrConnector connector = (EmbeddedSolrConnector) sb.index.fulltext().getLocalSolr();
if (connector == null) return null;
// do the solr request
SolrQueryRequest req = connector.request(post.toSolrParams());
// do the solr request, generate facets if we use a special YaCy format
SolrParams params = post.toSolrParams(responseWriter instanceof JsonResponseWriter ? new YaCySchema[]{YaCySchema.host_s, YaCySchema.url_file_ext_s, YaCySchema.url_protocol_s} : null);
SolrQueryRequest req = connector.request(params);
SolrQueryResponse response = null;
Exception e = null;
try {response = connector.query(req);} catch (SolrException ee) {e = ee;}

@ -470,7 +470,7 @@ public class serverObjects extends HashMap<String, String> implements Cloneable
return param.toString();
}
public SolrParams toSolrParams() {
public SolrParams toSolrParams(YaCySchema[] facets) {
// check if all required post fields are there
if (!this.containsKey(CommonParams.DF)) this.put(CommonParams.DF, YaCySchema.text_t.name()); // set default field to all fields
if (!this.containsKey(CommonParams.START)) this.put(CommonParams.START, "0"); // set default start item
@ -480,6 +480,12 @@ public class serverObjects extends HashMap<String, String> implements Cloneable
for (Map.Entry<String, String> e: this.entrySet()) {
m.put(e.getKey(), new String[]{e.getValue()});
}
if (facets != null && facets.length > 0) {
m.put("facet", new String[]{"true"});
String[] fs = new String[facets.length];
for (int i = 0; i < facets.length; i++) fs[i] = facets[i].name();
m.put("facet.field", fs);
}
final SolrParams solrParams = new MultiMapSolrParams(m);
return solrParams;
}

@ -67,15 +67,16 @@ public class EnhancedXMLResponseWriter implements QueryResponseWriter {
@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp) throws IOException {
writer.write(XML_START);
NamedList<?> values = rsp.getValues();
assert rsp.getValues().get("responseHeader") != null;
assert rsp.getValues().get("response") != null;
assert values.get("responseHeader") != null;
assert values.get("response") != null;
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> responseHeader = (SimpleOrderedMap<Object>) rsp.getResponseHeader();
DocSlice response = (DocSlice) rsp.getValues().get("response");
DocSlice response = (DocSlice) values.get("response");
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) rsp.getValues().get("highlighting");
SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) values.get("highlighting");
writeProps(writer, "responseHeader", responseHeader); // this.writeVal("responseHeader", responseHeader);
writeDocs(writer, request, response); // this.writeVal("response", response);
writeProps(writer, "highlighting", highlighting);

@ -82,14 +82,21 @@ public class JsonResponseWriter implements QueryResponseWriter {
@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp) throws IOException {
assert rsp.getValues().get("responseHeader") != null;
assert rsp.getValues().get("response") != null;
NamedList<?> values = rsp.getValues();
assert values.get("responseHeader") != null;
assert values.get("response") != null;
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> responseHeader = (SimpleOrderedMap<Object>) rsp.getResponseHeader();
DocSlice response = (DocSlice) rsp.getValues().get("response");
DocSlice response = (DocSlice) values.get("response");
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> facetCounts = (SimpleOrderedMap<Object>) values.get("facet_counts");
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) rsp.getValues().get("highlighting");
SimpleOrderedMap<Object> facetFields = facetCounts == null || facetCounts.size() == 0 ? null : (SimpleOrderedMap<Object>) facetCounts.get("facet_fields");
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) values.get("highlighting");
Map<String, List<String>> snippets = OpensearchResponseWriter.highlighting(highlighting);
// parse response header
@ -202,6 +209,14 @@ public class JsonResponseWriter implements QueryResponseWriter {
}
writer.write("]\n".toCharArray());
writer.write(",\n\"navigation\":[\n");
@SuppressWarnings("unchecked")
NamedList<Integer> hosts = facetFields == null ? null : (NamedList<Integer>) facetFields.get(YaCySchema.host_s.name());
@SuppressWarnings("unchecked")
NamedList<Integer> exts = facetFields == null ? null : (NamedList<Integer>) facetFields.get(YaCySchema.url_file_ext_s.name());
@SuppressWarnings("unchecked")
NamedList<Integer> prots = facetFields == null ? null : (NamedList<Integer>) facetFields.get(YaCySchema.url_protocol_s.name());
writer.write("{\"facetname\":\"filetypes\",\"displayname\":\"Filetypes\",\"type\":\"String\",\"min\":\"0\",\"max\":\"0\",\"mean\":\"0\",\"elements\":[]},\n".toCharArray());
writer.write("{\"facetname\":\"protocols\",\"displayname\":\"Protocol\",\"type\":\"String\",\"min\":\"0\",\"max\":\"0\",\"mean\":\"0\",\"elements\":[]},\n".toCharArray());
writer.write("{\"facetname\":\"domains\",\"displayname\":\"Domains\",\"type\":\"String\",\"min\":\"0\",\"max\":\"0\",\"mean\":\"0\",\"elements\":[]},\n".toCharArray());

@ -94,14 +94,17 @@ public class OpensearchResponseWriter implements QueryResponseWriter {
@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp) throws IOException {
assert rsp.getValues().get("responseHeader") != null;
assert rsp.getValues().get("response") != null;
NamedList<?> values = rsp.getValues();
assert values.get("responseHeader") != null;
assert values.get("response") != null;
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> responseHeader = (SimpleOrderedMap<Object>) rsp.getResponseHeader();
DocSlice response = (DocSlice) rsp.getValues().get("response");
DocSlice response = (DocSlice) values.get("response");
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) rsp.getValues().get("highlighting");
SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) values.get("highlighting");
Map<String, List<String>> snippets = highlighting(highlighting);
// parse response header

Loading…
Cancel
Save