如何查询整数,浮点数和如何存储(数字比较器)



一个更大的问题是solr甚至能够支持这一点吗? 我知道我已经看到lucene能够做到这一点,而solr是建立在lucene之上的。

我在某处看到过一个使用 google 的示例,但似乎无法再次找到它,并且该示例不完整,因为我认为它没有关于我如何为 lucene 编写查询语句的查询部分。 我记得看过一个NumericField,有这个NumericComparator。

基本上,我正在尝试一个提供索引(在 github 上(的 noSQL orm 解决方案(尽管客户端决定每个表有多少个索引和分区方法,但您将 entites 添加到索引并自己删除它们,并且可以使用 namedQuery,尽管您必须在查询之前先按名称获取索引,因为一个表可能有数百万个索引(。 我想要实现的两件主要事情是,它都可以与内存中的nosql假数据库和内存索引(lucene的RAMDirectory(一起使用,然后我想将它们切换到插入cassandra和SOLR。

我基本上需要

  1. 弄清楚如何存储整数、浮点数等。
  2. 弄清楚当目标是字符串、浮点数、整数等时如何编写 Lucene 查询。

现在,如果您需要更多详细信息,可以在以下位置找到项目的主要查询代码https://github.com/deanhiller/nosqlORM/blob/master/input/javasrc/com/alvazan/orm/layer3/spi/index/inmemory/MemoryIndexWriter.java

在第 172 行,您可以看到我每次都在添加一个新字段,但不幸的是,其中一些可能是整数。

大问题:SOLR甚至可以支持int与string吗? (如果没有,我将不得不在整数、长整型等的前面填充 0,因此所有整数的长度都相同(。

如果SOLR可以支持它,那么在lucene中最好的方法是什么,或者有一个很好的例子吗?

从NoSqlEntityManager.getIndex(Class clazz,String indexPartitionName(检索的主索引接口是(尽管不确定它是否重要(。https://github.com/deanhiller/nosqlORM/blob/master/input/javasrc/com/alvazan/orm/api/Index.java

谢谢院长

从示例 SOLR 架构.xml文件:

<!--
      Default numeric field types. For faster range queries, consider the tint/tfloat/tlong/tdouble types.
    -->
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
<!--
     Numeric field types that index each value at various levels of precision
     to accelerate range queries when the number of values between the range
     endpoints is large. See the javadoc for NumericRangeQuery for internal
     implementation details.
     Smaller precisionStep values (specified in bits) will lead to more tokens
     indexed per value, slightly larger index size, and faster range queries.
     A precisionStep of 0 disables indexing at different precision levels.
    -->
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>

因此,如果您将字段索引为上述字段类型之一,则通过其字段名称查询它(例如 myIntField:1234 (它将做"正确的事情",你也可以对它进行范围搜索(myIntField:[1200 TO 1300](。浮标等也是如此。

我认为我们可以利用org.apache.lucene.document.NumericField类。在这个类中,我们可以调用set方法,它可以支持int,log,float和double。对于其他数据类型(例如布尔值,日期时间(,我们可以进行特殊转换以将它们更改为int或long类型。

顺便说一句,我看到了lucene最新的源代码,涉及新的分支:FloatField,IntField,LongField和DoubleField。它将包含在下一个版本中。http://svn.apache.org/repos/asf/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/

最新更新