<bdo id='4rnO5'></bdo><ul id='4rnO5'></ul>

      <tfoot id='4rnO5'></tfoot>
      <legend id='4rnO5'><style id='4rnO5'><dir id='4rnO5'><q id='4rnO5'></q></dir></style></legend>
    1. <i id='4rnO5'><tr id='4rnO5'><dt id='4rnO5'><q id='4rnO5'><span id='4rnO5'><b id='4rnO5'><form id='4rnO5'><ins id='4rnO5'></ins><ul id='4rnO5'></ul><sub id='4rnO5'></sub></form><legend id='4rnO5'></legend><bdo id='4rnO5'><pre id='4rnO5'><center id='4rnO5'></center></pre></bdo></b><th id='4rnO5'></th></span></q></dt></tr></i><div id='4rnO5'><tfoot id='4rnO5'></tfoot><dl id='4rnO5'><fieldset id='4rnO5'></fieldset></dl></div>
    2. <small id='4rnO5'></small><noframes id='4rnO5'>

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

        时间:2023-09-29

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

            • <tfoot id='JuKJs'></tfoot>
                <bdo id='JuKJs'></bdo><ul id='JuKJs'></ul>

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

                  <tbody id='JuKJs'></tbody>
                <legend id='JuKJs'><style id='JuKJs'><dir id='JuKJs'><q id='JuKJs'></q></dir></style></legend>
                  本文介绍了向 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 文档添加多值字符串字段,逗号重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Lucene 中索引和搜索日期 下一篇:Solr:结合 EdgeNGramFilterFactory 和 NGramFilterFactory

                  相关文章

                  最新文章

                1. <tfoot id='UUPN4'></tfoot>

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

                  1. <small id='UUPN4'></small><noframes id='UUPN4'>

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