• <small id='iYY4c'></small><noframes id='iYY4c'>

  • <tfoot id='iYY4c'></tfoot>

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

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

          <bdo id='iYY4c'></bdo><ul id='iYY4c'></ul>
      1. Lucene RangeQuery 没有正确过滤

        时间:2023-09-14

      2. <legend id='8NCaZ'><style id='8NCaZ'><dir id='8NCaZ'><q id='8NCaZ'></q></dir></style></legend>

        • <small id='8NCaZ'></small><noframes id='8NCaZ'>

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

                • 本文介绍了Lucene RangeQuery 没有正确过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 RangeQuery 来获取数量在 0 到 2 之间的所有文档.当我执行查询时,Lucene 也会给我数量大于 2 的文档.我在这里错过了什么?

                  I'm using RangeQuery to get all the documents which have amount between say 0 to 2. When i execute the query, Lucene gives me documents which have amount greater than 2 also. What am I missing here?

                  这是我的代码:

                  Term lowerTerm = new Term("amount", minAmount);
                  Term upperTerm = new Term("amount", maxAmount);
                  
                  RangeQuery amountQuery = new RangeQuery(lowerTerm, upperTerm, true);
                  
                  finalQuery.Add(amountQuery, BooleanClause.Occur.MUST);
                  

                  这是我索引中的内容:

                  doc.Add(new Field("amount", amount.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.YES));
                  

                  推荐答案

                  UPDATE:就像@basZero在他的评论中所说,从Lucene 2.9开始,你可以添加数字字段到您的文档.只要记住使用 NumericRangeQuery 搜索时代替 RangeQuery.

                  UPDATE: Like @basZero said in his comment, starting with Lucene 2.9, you can add numeric fields to your documents. Just remember to use NumericRangeQuery instead of RangeQuery when you search.

                  Lucene 将数字视为单词,因此它们的顺序是字母顺序:

                  Lucene treats numbers as words, so their order is alphabetic:

                  0
                  1
                  12
                  123
                  2
                  22
                  

                  这意味着对于 Lucene,12 介于 0 和 2 之间.如果要进行适当的数字范围,则需要索引数字零填充,然后执行 [0000 TO 0002] 的范围搜索.(您需要的填充量取决于预期的值范围).

                  That means that for Lucene, 12 is between 0 and 2. If you want to do a proper numerical range, you need to index the numbers zero-padded, then do a range search of [0000 TO 0002]. (The amount of padding you need depends on the expected range of values).

                  如果您有负数,只需为非负数添加另一个零.(错错了.查看更新)

                  If you have negative numbers, just add another zero for non-negative numbers. ( WRONG WRONG WRONG. See update)

                  如果您的数字包含小数部分,请保持原样,仅对整数部分进行零填充.

                  If your numbers include a fraction part, leave it as is, and zero-pad the integer part only.

                  例子:

                  <罢工>

                  -00002.12
                  -00001
                  

                  000000
                  000001
                  000003.1415
                  000022
                  

                  更新:负数有点棘手,因为 -1 按字母顺序排在 -2 之前.这篇文章给出了关于在 Lucene 中处理负数和一般数字的完整解释.基本上,您必须将数字编码"成使项目的顺序有意义的东西.

                  UPDATE: Negative numbers are a bit tricky, since -1 comes before -2 alphabetically. This article gives a complete explanation about dealing with negative numbers and numbers in general in Lucene. Basically, you have to "encode" numbers into something that makes the order of the items make sense.

                  这篇关于Lucene RangeQuery 没有正确过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 ASP.NET MVC 站点中正确构建 Lucene.Net 使用 下一篇:Lucene - 短语中的通配符

                  相关文章

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

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

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

                    1. <legend id='aJN8f'><style id='aJN8f'><dir id='aJN8f'><q id='aJN8f'></q></dir></style></legend>