I m taking taming text book as an example to add custom QueryResponseWriter
in solr. But it is not shown in wt
as tah
When I hit following query, empty response is shown
http://localhost:8983/solr/collectiona/type-ahead?q=fayes&wt=tah
In my solr config, I have placed following dir path of my lib
<lib dir="${solr.install.dir:../../../..}/contrib/customresponsewriter" regex=".*\.jar" />
I have created a jar file for this as mentioned in the book. Here is my java class
public class TypeAheadResponseWriter implements QueryResponseWriter {
private Set<String> fields;
public void write(Writer writer, SolrQueryRequest solrQueryRequest, SolrQueryResponse solrQueryResponse) throws IOException {
SolrIndexSearcher searcher = solrQueryRequest.getSearcher();
NamedList namedList = solrQueryResponse.getValues();
int size = namedList.size();
for (int i = 0; i < size; i++) {
Object val = namedList.getVal(i);
if (val instanceof DocList) {
DocList docList = (DocList) val;
DocIterator docIterator = docList.iterator();
writer.append("<ul>\n");
while (docIterator.hasNext()) {
int id = docIterator.nextDoc();
Document doc = searcher.doc(id, fields);
String name = doc.get("title");
writer.append("<li>" + name + "</li>");
}
writer.append("</ul>\n");
}
}
}
public String getContentType(SolrQueryRequest solrQueryRequest, SolrQueryResponse solrQueryResponse) {
return "text/html;charset=UTF-8";
}
public void init(NamedList namedList) {
fields = new HashSet<String>();
fields.add("title");
}
}
Here is my solr config for queryResponsewriter
<queryResponseWriter name="tah" class="cqw.TypeAheadResponseWriter"/>
<requestHandler name="/type-ahead" class="solr.SearchHandler">
<lst name="defaults">
<str name="wt">tah</str>
<str name="defType">dismax</str>
<str name="qf">title_prefix_typeahead^1.0</str>
</lst>
</requestHandler>
custom library is loaded during startup of solr, here is my Solr log
Added 63 libs to classloader, from paths: [/home/bibek/software/java/solr-7.3.0/contrib/clustering/lib, /home/bibek/software/java/solr-7.3.0/contrib/customresponsewriter, /home/bibek/software/java/solr-7.3.0/contrib/extraction/lib, /home/bibek/software/java/solr-7.3.0/contrib/langid/lib, /home/bibek/software/java/solr-7.3.0/contrib/velocity/lib, /home/bibek/software/java/solr-7.3.0/dist]