gpt4 book ai didi

solr - 如何在lucene中查询整数、 float 以及如何存储(NumericComparator)?

转载 作者:行者123 更新时间:2023-12-04 17:11:36 25 4
gpt4 key购买 nike

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

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

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

我基本上需要

  • 弄清楚如何存储整数、浮点数等。
  • 当目标是字符串、浮点数、整数等时,弄清楚如何编写 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) 检索到的主索引接口(interface)是(虽然不确定它是否重要)..
    https://github.com/deanhiller/nosqlORM/blob/master/input/javasrc/com/alvazan/orm/api/Index.java

    谢谢,
    院长

    最佳答案

    来自 example 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] )。花车等也是如此。

    关于solr - 如何在lucene中查询整数、 float 以及如何存储(NumericComparator)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10405715/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com