<bdo id='FHflg'></bdo><ul id='FHflg'></ul>
<tfoot id='FHflg'></tfoot>

  • <legend id='FHflg'><style id='FHflg'><dir id='FHflg'><q id='FHflg'></q></dir></style></legend>
      1. <small id='FHflg'></small><noframes id='FHflg'>

        <i id='FHflg'><tr id='FHflg'><dt id='FHflg'><q id='FHflg'><span id='FHflg'><b id='FHflg'><form id='FHflg'><ins id='FHflg'></ins><ul id='FHflg'></ul><sub id='FHflg'></sub></form><legend id='FHflg'></legend><bdo id='FHflg'><pre id='FHflg'><center id='FHflg'></center></pre></bdo></b><th id='FHflg'></th></span></q></dt></tr></i><div id='FHflg'><tfoot id='FHflg'></tfoot><dl id='FHflg'><fieldset id='FHflg'></fieldset></dl></div>

        在 Java api 中的 Solr 搜索中需要搜索的文本和围绕它的几行

        Need searched text and a few lines around it in Solr search in java api(在 Java api 中的 Solr 搜索中需要搜索的文本和围绕它的几行)
          <legend id='rAvgO'><style id='rAvgO'><dir id='rAvgO'><q id='rAvgO'></q></dir></style></legend>

          <small id='rAvgO'></small><noframes id='rAvgO'>

          <tfoot id='rAvgO'></tfoot>

              • <i id='rAvgO'><tr id='rAvgO'><dt id='rAvgO'><q id='rAvgO'><span id='rAvgO'><b id='rAvgO'><form id='rAvgO'><ins id='rAvgO'></ins><ul id='rAvgO'></ul><sub id='rAvgO'></sub></form><legend id='rAvgO'></legend><bdo id='rAvgO'><pre id='rAvgO'><center id='rAvgO'></center></pre></bdo></b><th id='rAvgO'></th></span></q></dt></tr></i><div id='rAvgO'><tfoot id='rAvgO'></tfoot><dl id='rAvgO'><fieldset id='rAvgO'></fieldset></dl></div>
                  <bdo id='rAvgO'></bdo><ul id='rAvgO'></ul>
                    <tbody id='rAvgO'></tbody>

                • 本文介绍了在 Java api 中的 Solr 搜索中需要搜索的文本和围绕它的几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 solr 7.7.2,我使用 solrj 在 Solr 中编写了一个 Java 程序,该程序在一个巨大的文本文件中搜索一个单词.我使用以下代码来显示代表整个文本的搜索结果.

                  SolrQuery 参数 = new SolrQuery();params.setQuery("content:word for search");

                  如何在该行中只显示一行文字?

                  所有代码都是这样的

                  public static void main(String args[]) throws SolrServerException, IOException{String urlString = "http://localhost:8983/solr/test_core";SolrClient Solr = new HttpSolrClient.Builder(urlString).build();SolrQuery 参数 = 新 SolrQuery();params.setQuery("content:word for search");params.setSort("score", SolrQuery.ORDER.desc);QueryResponse queryResponse = Solr.query(params);SolrDocumentList 结果 = queryResponse.getResults();for (int i = 0 ; i < result.size(); i++ ){System.out.println(result.get(i) + "
                  ");}}

                  解决方案

                  Highlighting 是 solr 的一项功能.你必须通过查询参数来实现高亮如下:-

                  hl – 设置为 true,它可以在查询响应中生成突出显示的片段.

                  hl.fl – 提及要突出显示的字段列表.char * 将突出显示所有字段

                  hl.fragsize – 荧光笔创建的片段(又名片段)的大小(以字符为单位).在原来的 Highlighter 中,0"表示应该使用整个字段值,不要分片.默认情况下,片段大小为 100 个字符

                  通过添加以下代码进行检查.

                  params.setHighlight(true).setHighlightSnippets(1);params.setParam("hl.fl", "*");params.setParam("hl.fragsize", "0");

                  这里有完整的代码供你尝试.

                  注意:请忽略代码中硬编码的内容,像硬编码的 url "solrUrl = "

                  i'm using solr 7.7.2 and I wrote a Java program in Solr using solrj that searches for a word in a huge text file. I use following code to show the search results that represent the whole text.

                  SolrQuery params = new SolrQuery();
                  params.setQuery("content:word for search");
                  

                  How to display only one line of text where the word is in that line?

                  All code is like this

                  public static void main(String args[]) throws SolrServerException, IOException
                      {
                          String urlString = "http://localhost:8983/solr/test_core";
                          SolrClient Solr = new HttpSolrClient.Builder(urlString).build();
                  
                          SolrQuery params = new SolrQuery();
                          params.setQuery("content:word for search");
                  
                          params.setSort("score", SolrQuery.ORDER.desc);
                  
                          QueryResponse queryResponse = Solr.query(params);
                  
                          SolrDocumentList result = queryResponse.getResults();
                          for (int i = 0 ; i < result.size(); i++ )
                          {
                              System.out.println(result.get(i) + " 
                  ");
                          }
                      }
                  
                  

                  解决方案

                  Highlighting is one of solr feature. You have to pass query Parameters to achieve highlighting are as follows:-

                  hl – set to true, it enables highlighted snippets to be generated in the query response.

                  hl.fl – mention a list of fields to highlight. char * will highlight all the fields

                  hl.fragsize – The size, in characters, of the snippets (aka fragments) created by the highlighter. In the original Highlighter, "0" indicates that the whole field value should be used with no fragmenting. By default fragment is of size 100 characters

                  Check by adding the below code.

                  params.setHighlight(true).setHighlightSnippets(1);
                  params.setParam("hl.fl", "*");
                  params.setParam("hl.fragsize", "0");
                  

                  Here is the full code for you to try.

                  Note : Please ignore the hardcoded things from the code, like hardcoded url "solrUrl = "http://localhost:8983/solr" and string "return "Success"". Those should be read from the properties file and from a constant file. Expect you do the same. Never use System out in your production code.

                  public String getResult() throws SolrServerException, IOException {
                  
                          final SolrClient client = getSolrClient();
                          ModifiableSolrParams params = new ModifiableSolrParams ();
                  
                  
                          params.set ("q", "comment_t:pizza");
                          params.set ("fl", "id, comment_t");
                          params.set ("sort", "id asc");
                          params.set("hl", true);
                          params.set("hl.q", "pizza");
                          params.set("hl.simple.pre", "<strong>");
                          params.set("hl.simple.post", "</strong>");
                          params.set("hl.fl", "comment_t");
                          params.set("hl.fragsize", "100");
                  
                          final QueryResponse response = client.query("demo", params);
                          response.getHighlighting();
                  
                          final SolrDocumentList documents = response.getResults();
                  
                          System.out.println("Found " + documents.getNumFound() + " documents");
                          for (SolrDocument document : documents) {
                              final String id = (String) document.getFirstValue("id");
                              final String name = (String) document.getFirstValue("comment_t");
                  
                              System.out.println("id: " + id + "; comment_t: " + name);
                  
                              if(response.getHighlighting() != null){
                                  System.out.println("highlighted text :: " + response.getHighlighting());
                              }
                          }
                          return "Success";
                      }
                  
                  
                  
                  private SolrClient getSolrClient() {
                  
                          final String solrUrl = "http://localhost:8983/solr";
                          return new HttpSolrClient.Builder(solrUrl).withConnectionTimeout(10000).withSocketTimeout(60000).build();
                      }
                  

                  Please find the screenshot of the output :

                  这篇关于在 Java api 中的 Solr 搜索中需要搜索的文本和围绕它的几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
                  <tfoot id='SkljH'></tfoot>

                      <i id='SkljH'><tr id='SkljH'><dt id='SkljH'><q id='SkljH'><span id='SkljH'><b id='SkljH'><form id='SkljH'><ins id='SkljH'></ins><ul id='SkljH'></ul><sub id='SkljH'></sub></form><legend id='SkljH'></legend><bdo id='SkljH'><pre id='SkljH'><center id='SkljH'></center></pre></bdo></b><th id='SkljH'></th></span></q></dt></tr></i><div id='SkljH'><tfoot id='SkljH'></tfoot><dl id='SkljH'><fieldset id='SkljH'></fieldset></dl></div>

                        <small id='SkljH'></small><noframes id='SkljH'>

                          <bdo id='SkljH'></bdo><ul id='SkljH'></ul>
                        • <legend id='SkljH'><style id='SkljH'><dir id='SkljH'><q id='SkljH'></q></dir></style></legend>
                              <tbody id='SkljH'></tbody>