自定义QueryResponseWriter在solr 7.3.0中不起作用(custom QueryResponseWriter is not working in solr 7.3.0)
我以驯服文本书为例,在solr中添加自定义的
QueryResponseWriter
。 但它没有显示在wt
中当我点击下面的查询时,显示空的响应
http://localhost:8983/solr/collectiona/type-ahead?q=fayes&wt=tah
在我的solr配置中,我已经放置了下面的lib目录
<lib dir="${solr.install.dir:../../../..}/contrib/customresponsewriter" regex=".*\.jar" />
正如本书所述,我已经为此创建了一个jar文件。 这是我的java类
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"); } }
这是我的solr config 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>
自定义库在solr启动过程中加载,这里是我的Solr日志
从路径添加了63个lib到classloader:[/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]
I m taking taming text book as an example to add custom
QueryResponseWriter
in solr. But it is not shown inwt
astah
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]
原文:https://stackoverflow.com/questions/50312621
最满意答案
我想通了......我的标签标签是未闭合的:
echo "<label>Select weekly or monthly deliveries: <label><br>";
应该:
echo "<label>Select weekly or monthly deliveries: </label><br>";
I figured it out...I had the label tag unclosed:
echo "<label>Select weekly or monthly deliveries: <label><br>";
should be:
echo "<label>Select weekly or monthly deliveries: </label><br>";
相关问答
更多-
使用.prop()代替.attr() 从文档: 属性与属性 在特定情况下,属性和属性之间的差异可能很重要。 在jQuery 1.6之前,.attr()方法有时在检索某些属性时会考虑属性值,这可能会导致行为不一致。 从jQuery 1.6开始,.prop()方法提供了一种显式检索属性值的方法,而.attr()则检索属性。 Use .prop() instead of .attr() From the documentation: Attributes vs. Properties The difference ...
-
但是,主要问题是,当我选择一个未选定的单选按钮时,它会在警报显示后立即取消选择它。 看起来你不能防止单选按钮的默认行为return false或e.preventDefault()因为单击处理器被触发时总是检查单选按钮。 解决这个问题的一个方法是向单选按钮添加一个单独的类并将其用作指示器。 $(".deselectRadioButton").click( function(e){ if($(this).hasClass("on")){ $(this).removeAttr('check ...
-
Radio Buttons jQuery(Radio Buttons jQuery)[2023-05-05]
您不能在具有相同ID的同一文档中包含两个元素。 您的选择器#companyreg正在查找第一个元素而不是第二个元素。 如果你要检查 $("#companyreg").length 你会看到1。 你可以通过使用来解决这个问题 $( '[id="companyreg"]' ) 虽然它不会修复你的无效文件。 最好的方法是删除ID并为这些元素添加一个类,然后通过该类选择。 我没有检查你的其余代码,看看这是否是唯一的问题,但我怀疑它是最大的问题。 You cannot have two elements in t ... -
我最终删除了以下代码,因为我还有一个关闭按钮 $(document).bind('click', function(event){ if(!$(event.target).closest(settings['selector']).length){ methods.close(); } }); I ended up removing the following code as I have a close button anyway $(document).bind('click', fu ...
-
jQuery移动单选按钮(jQuery mobile radio buttons)[2023-10-24]
我终于使用了omar的解决方案$('span.ui-icon').remove(); 。 但它看起来并不正确。 这只是一个解决方法。 I finally used omar's solution $('span.ui-icon').remove();. But it doesn't look right. This is just a work around. -
这就是你想要的代码。 我删除了select()事件,因为在使用鼠标选择文本时会触发该事件。 最好隐藏/显示元素而不是删除它们。 function myFun() { // 1. Find the first option and set as selected $("#sel").find('option').first().prop("selected",true) // 2. Find its not selected siblings and hide it .sib ...
-
单击此jquery日期选择器时,为什么单选按钮会重置(Why are the radio buttons resetting when clicking on this jquery datepicker)[2023-06-25]
我想通了......我的标签标签是未闭合的: echo " -
JQuery:通过单击其中一个来切换两个单选按钮(JQuery: Toggle two radio buttons by clicking on only one of it)[2023-08-09]
在此设置中要克服的问题是每个单选按钮在浏览器中具有默认的真/假行为,即使在任何jQuery / javascript事件侦听器触发之前也会触发。 解决这个问题的方法是向前和向后切换一个class ,然后只通过引用class来更新单选按钮的状态。 这是使用jQuery和本机javascript的这种直截了当的方法: jQuery的: $(document).ready(function(){ $('input[type="radio"]').click(function(){ $( ... -
这个jquery代码可以帮助你: $("a").click(function() { $(this).next().prop("checked", true); }); 演示: http : //jsfiddle.net/k5rkxkos/ 更新 在纯Javascript中(因为你说你不是jquery的专家;)),你可以这样做: var a = document.getElementsByTagName("a"); for ( var i = 0; i < a.length; i++ ) { ...
-
在页面加载期间,您将buttonset属性分配给类型为tag : radio元素。 您的DOM不存在此类元素。 您需要将div要应用按钮组的目标。 简而言之,您在选择器中缺少'#' 。 $(function () { console.log("ready!"); alert("Hi!"); $("#radio").buttonset(); }); During page load, you are assigning ...