首页 \ 问答 \ 自定义QueryResponseWriter在solr 7.3.0中不起作用(custom QueryResponseWriter is not working in solr 7.3.0)

自定义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 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]


原文:https://stackoverflow.com/questions/50312621
更新时间:2023-12-07 06:12

最满意答案

我想通了......我的标签标签是未闭合的:

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 ...
  • 您不能在具有相同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 ...
  • 我终于使用了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 ...
  • 我想通了......我的标签标签是未闭合的: echo "
  • 在此设置中要克服的问题是每个单选按钮在浏览器中具有默认的真/假行为,即使在任何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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)