5

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

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

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

我基本上需要

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

现在,如果您需要更多详细信息,可以在 https://github.com/deanhiller/nosqlORM/blob/master/input/javasrc/com/alvazan/orm/layer3/spi/index/找到项目的主要查询代码内存/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

谢谢,院长

4

2 回答 2

9

示例 SOLR schema.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])。花车等也是如此。

于 2012-05-02T00:13:37.233 回答
2

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

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

于 2012-05-13T14:27:34.663 回答