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

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

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

        lucene 在查询中获得匹配的术语

        时间:2023-09-30
          • <i id='Vocda'><tr id='Vocda'><dt id='Vocda'><q id='Vocda'><span id='Vocda'><b id='Vocda'><form id='Vocda'><ins id='Vocda'></ins><ul id='Vocda'></ul><sub id='Vocda'></sub></form><legend id='Vocda'></legend><bdo id='Vocda'><pre id='Vocda'><center id='Vocda'></center></pre></bdo></b><th id='Vocda'></th></span></q></dt></tr></i><div id='Vocda'><tfoot id='Vocda'></tfoot><dl id='Vocda'><fieldset id='Vocda'></fieldset></dl></div>

          • <legend id='Vocda'><style id='Vocda'><dir id='Vocda'><q id='Vocda'></q></dir></style></legend>

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

              <tbody id='Vocda'></tbody>
          • <tfoot id='Vocda'></tfoot>

                • <bdo id='Vocda'></bdo><ul id='Vocda'></ul>

                  本文介绍了lucene 在查询中获得匹配的术语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 lucene 中找出与给定文档匹配的查询中的哪些词的最佳方法是什么?

                  What is the best way to find out which terms in a query matched against a given document returned as a hit in lucene?

                  我尝试了一种奇怪的方法,涉及 lucene contrib 中的命中突出显示包,以及一种针对最顶层文档搜索查询中每个单词的方法(docId: xy AND description: each_word_in_query").

                  I have tried a weird method involving hit highlighting package in lucene contrib and also a method that searches for every word in the query against the top most document ("docId: xy AND description: each_word_in_query").

                  没有得到满意的结果?命中突出显示不报告与第一个文档以外的文档匹配的某些单词.我不确定第二种方法是否是最佳选择.

                  Do not get satisfactory results? Hit highlighting does not report some of the words that matched for a document other than the first one. I'm not sure if the second approach is the best alternative.

                  推荐答案

                  方法explain 在 Searcher 中是查看查询的哪个部分匹配以及如何匹配的好方法它会影响总分.

                  The method explain in the Searcher is a nice way to see which part of a query was matched and how it affects the overall score.

                  示例取自《Lucene In Action 2nd Edition》一书:

                  Example taken from the book Lucene In Action 2nd Edition:

                  public class Explainer {
                  
                    public static void main(String[] args) throws Exception {
                  
                       if (args.length != 2) {
                          System.err.println("Usage: Explainer <index dir> <query>");
                          System.exit(1);
                       }
                  
                       String indexDir = args[0];
                       String queryExpression = args[1];
                       Directory directory = FSDirectory.open(new File(indexDir));
                       QueryParser parser = new QueryParser(Version.LUCENE_CURRENT,
                                                       "contents", new SimpleAnalyzer());
                  
                       Query query = parser.parse(queryExpression);
                       System.out.println("Query: " + queryExpression);
                       IndexSearcher searcher = new IndexSearcher(directory);
                       TopDocs topDocs = searcher.search(query, 10);
                       for (int i = 0; i < topDocs.totalHits; i++) {
                          ScoreDoc match = topDocs.scoreDocs[i];
                          Explanation explanation = searcher.explain(query, match.doc);   
                          System.out.println("----------");
                          Document doc = searcher.doc(match.doc);
                          System.out.println(doc.get("title"));
                          System.out.println(explanation.toString());
                       }
                    }
                  }
                  

                  这将解释与查询匹配的每个文档的分数.

                  This will explain the score of each document that matches the query.

                  这篇关于lucene 在查询中获得匹配的术语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何解析/解压缩/解压缩 Nexus 生成的 Maven 存储库 下一篇:lucene 良好实践和线程安全

                  相关文章

                  最新文章

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

                    • <bdo id='dTx6L'></bdo><ul id='dTx6L'></ul>

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

                      <legend id='dTx6L'><style id='dTx6L'><dir id='dTx6L'><q id='dTx6L'></q></dir></style></legend>