-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ issue #28 ] RDF faceting (facet fields)
- Loading branch information
agazzarini
committed
Mar 7, 2015
1 parent
dcb60bd
commit 1f99afb
Showing
14 changed files
with
383 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
solrdf/src/main/java/org/gazzax/labs/solrdf/graph/GraphEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.gazzax.labs.solrdf.graph; | ||
|
||
import com.hp.hpl.jena.graph.Triple; | ||
|
||
public interface GraphEventListener { | ||
public void afterTripleHasBeenBuilt(Triple triple, int docId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
solrdf/src/main/java/org/gazzax/labs/solrdf/response/CompoundXMLWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package org.gazzax.labs.solrdf.response; | ||
|
||
import static org.apache.solr.common.util.XML.escapeAttributeValue; | ||
import static org.gazzax.labs.solrdf.Strings.isNotNullOrEmptyString; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import org.apache.commons.io.output.WriterOutputStream; | ||
import org.apache.solr.common.params.CommonParams; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
import org.apache.solr.response.XMLWriter; | ||
|
||
import com.hp.hpl.jena.query.ResultSet; | ||
import com.hp.hpl.jena.sparql.resultset.XMLOutput; | ||
|
||
/** | ||
* A subclass of {@link XMLWriter} for mixing up Solr and Jena results. | ||
* Unfortunately something needs to be declared again here because, although it is not final, | ||
* I assume the {@link XMLWriter} hasn't been thought with extensibility in mind. | ||
* | ||
* @author Andrea Gazzarini | ||
* @since 1.0 | ||
*/ | ||
class CompoundXMLWriter extends XMLWriter { | ||
protected static final char[] XML_PROCESSING_INSTR = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".toCharArray(); | ||
protected static final char[] RESPONSE_ROOT_ELEMENT_START = ("<response>\n").toCharArray(); | ||
protected static final char[] RESPONSE_ROOT_ELEMENT_END = ("</response>").toCharArray(); | ||
|
||
protected static final char[] XML_STYLESHEET = "<?xml-stylesheet type=\"text/xsl\" href=\"".toCharArray(); | ||
protected static final char[] XML_STYLESHEET_END = "\"?>\n".toCharArray(); | ||
|
||
/** | ||
* Builds a new {@link CompoundXMLWriter} with the given data. | ||
* | ||
* @param writer the output {@link Writer}. | ||
* @param request the current {@link SolrQueryRequest}. | ||
* @param response the current {@link SolrQueryResponse}. | ||
*/ | ||
CompoundXMLWriter( | ||
final Writer writer, | ||
final SolrQueryRequest request, | ||
final SolrQueryResponse response) { | ||
super(writer, request, response); | ||
} | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
@Override | ||
public void writeResponse() throws IOException { | ||
writer.write(XML_PROCESSING_INSTR); | ||
|
||
final String stylesheet = req.getParams().get("stylesheet"); | ||
if (isNotNullOrEmptyString(stylesheet)) { | ||
writer.write(XML_STYLESHEET); | ||
|
||
escapeAttributeValue(stylesheet, writer); | ||
|
||
writer.write(XML_STYLESHEET_END); | ||
} | ||
|
||
writer.write(RESPONSE_ROOT_ELEMENT_START); | ||
|
||
final NamedList<?> responseValues = rsp.getValues(); | ||
if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) { | ||
responseValues.remove("responseHeader"); | ||
} else { | ||
((NamedList)responseValues.get("responseHeader")).add("query", responseValues.remove("query")); | ||
} | ||
|
||
for (final Entry<String, ?> entry : responseValues) { | ||
writeValue(entry.getKey(), entry.getValue(), responseValues); | ||
} | ||
|
||
writer.write(RESPONSE_ROOT_ELEMENT_END); | ||
} | ||
|
||
/** | ||
* Writes out a given name / value pair. | ||
* This is similar to {@link XMLWriter#writeVal(String, Object)}. | ||
* This is needed because that similar method is not extensible and cannot be overriden | ||
* (it is called recursively by other methods). | ||
* | ||
* @param name the name of the attribute. | ||
* @param value the value of the attribute. | ||
* @param data the complete set of response values. | ||
* @throws IOException in case of I/O failure. | ||
*/ | ||
public void writeValue(final String name, final Object value, final NamedList<?> data) throws IOException { | ||
if (value == null) { | ||
writeNull(name); | ||
} else if (value instanceof ResultSet) { | ||
final XMLOutput outputter = new XMLOutput(false); | ||
outputter.format(new WriterOutputStream(writer), (ResultSet)value) ; | ||
} else if (value instanceof String) { | ||
writeStr(name, value.toString(), false); | ||
} else if (value instanceof Number) { | ||
if (value instanceof Integer || value instanceof Short || value instanceof Byte) { | ||
writeInt(name, value.toString()); | ||
} else if (value instanceof Long) { | ||
writeLong(name, value.toString()); | ||
} else if (value instanceof Float) { | ||
writeFloat(name, ((Float) value).floatValue()); | ||
} else if (value instanceof Double) { | ||
writeDouble(name, ((Double) value).doubleValue()); | ||
} | ||
} else if (value instanceof Boolean) { | ||
writeBool(name, value.toString()); | ||
} else if (value instanceof Date) { | ||
writeDate(name, (Date) value); | ||
} else if (value instanceof Map) { | ||
writeMap(name, (Map<?,?>) value, false, true); | ||
} else if (value instanceof NamedList) { | ||
writeNamedList(name, (NamedList<?>) value); | ||
} else if (value instanceof Iterable) { | ||
writeArray(name, ((Iterable<?>) value).iterator()); | ||
} else if (value instanceof Object[]) { | ||
writeArray(name, (Object[]) value); | ||
} else if (value instanceof Iterator) { | ||
writeArray(name, (Iterator<?>) value); | ||
} | ||
} | ||
} |
Oops, something went wrong.