<tfoot id='vFRSk'></tfoot>
      <legend id='vFRSk'><style id='vFRSk'><dir id='vFRSk'><q id='vFRSk'></q></dir></style></legend>
          <bdo id='vFRSk'></bdo><ul id='vFRSk'></ul>
      1. <small id='vFRSk'></small><noframes id='vFRSk'>

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

        向 Lucene 文档添加多值字符串字段,逗号重要吗?

        Adding a multi-valued string field to a Lucene Document, do commas matter?(向 Lucene 文档添加多值字符串字段,逗号重要吗?)
          <bdo id='4vIjR'></bdo><ul id='4vIjR'></ul>
        • <small id='4vIjR'></small><noframes id='4vIjR'>

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

                1. <legend id='4vIjR'><style id='4vIjR'><dir id='4vIjR'><q id='4vIjR'></q></dir></style></legend>
                    <tbody id='4vIjR'></tbody>
                  本文介绍了向 Lucene 文档添加多值字符串字段,逗号重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在构建一个 Lucene 索引并添加文档.

                  I'm building a Lucene Index and adding Documents.

                  我有一个多值字段,在本例中我将使用类别.

                  I have a field that is multi-valued, for this example I'll use Categories.

                  一个项目可以有很多类别,例如,牛仔裤可以属于服装、裤子、男装、女装等.

                  An Item can have many categories, for example, Jeans can fall under Clothing, Pants, Men's, Women's, etc.

                  将字段添加到文档时,逗号会有所不同吗?Lucene 会直接忽略它们吗?如果我将逗号更改为空格会有所不同吗?这会自动使该字段成为多值吗?

                  When adding the field to a document, do commas make a difference? Will Lucene simply ignore them? if I change commas to spaces will there be a difference? Does this automatically make the field multi-valued?

                  String categoriesForItem = getCategories(); // returns "category1, category2, cat3" from a DB call
                  
                  categoriesForItem = categoriesForItem.replaceAll(",", " ").trim(); // not sure if to remove comma
                  
                  doc.add(new StringField("categories", categoriesForItem , Field.Store.YES)); // doc is a Document
                  

                  我这样做正确吗?还是有其他方法可以创建多值字段?

                  Am I doing this correctly? or is there another way to create multivalued fields?

                  感谢任何帮助/建议.

                  推荐答案

                  这将是为每个文档索引多值字段的更好方法

                  This would be a better way to index multiValued fields per document

                  String categoriesForItem = getCategories(); // get "category1, category2, cat3" from a DB call
                  
                  String [] categoriesForItems = categoriesForItem.split(","); 
                  for(String cat : categoriesForItems) {
                      doc.add(new StringField("categories", cat , Field.Store.YES)); // doc is a Document 
                  }
                  

                  当同名的多个字段出现在一个文档中时,倒排索引和术语向量都会按照添加字段的顺序在逻辑上将字段的标记相互附加.

                  Whenever multiple fields with the same name appear in one document, both the inverted index and term vectors will logically append the tokens of the field to one another, in the order the fields were added.

                  同样在分析阶段,两个不同的值将通过 setPositionIncrementGap() 自动通过位置增量分隔.让我解释一下为什么需要这样做.

                  Also during the analysis phase two different values will be seperated by a position increment via setPositionIncrementGap() automatically. Let me explain why this is needed.

                  文档 D1 中的类别"字段有两个值 - foo bar"和foo baz"现在,如果您要进行短语查询bar foo",则不应出现 D1.这是通过在同一字段的两个值之间添加额外的增量来确保的.

                  Your field "categories" in Document D1 has two values - "foo bar" and "foo baz" Now if you were to do a phrase query "bar foo" D1 should not come up. This is ensure by adding an extra increment between two values of the same field.

                  如果您自己连接字段值并依赖分析器将其拆分为多个值,bar foo"将返回 D1,这是不正确的.

                  If you yourself concatenate the field values and rely on the analyzer to split it into multiple values "bar foo" would return D1 which would be incorrect.

                  这篇关于向 Lucene 文档添加多值字符串字段,逗号重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='tlHtk'></tfoot>

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

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

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