1

大家好,我是 Solr 的新手,想完成以下场景(如下),但不确定 Solr 是否能够处理这样的情况:

这个问题很简单,我想建立一个价格比较搜索。有我的理性数据库表:

t_company:
company_id
company_name

t_product:
product_id
product_price

t_company_product:
company_product_id
company_id
product_id

在 Solr 中,我想执行以下搜索 - 获取以最低 TOTAL 价格提供一种或多种特定产品的所有公司(因此,如果您选择螺钉、钉子和石板,我想给出最低总购买价格) .

当我设置我的架构时,我将业务设置为主要实体,并将 product_ids 和 product_prices 设置为两个多值字段。

我可以这样查询吗?我将如何求和?

这是我所有的 XML schema.xml 和 data-config.xml

<document name="companies">
<entity name="company" dataSource="dsCompany" 
        query="select 
                      newid() as row_id,
                      company_id, 
                      company_name
               from 
                    t_company WITH (NOLOCK)">
    <field column="row_id" name="row_id" />
    <field column="company_id" name="company_id" />
    <field column="company_name" name="company_name" />
    <entity name="products" query="select 
                                        company_product_id, 
                                        product_id,
                                        price
                                   from 
                                        t_company_product WITH (NOLOCK)
                                   where 
                                        company_id='${company.company_id}'"
                                        dataSource="dsCompany">
        <field name="company_product_id" column="company_product_id" />
        <field name="product_id" column="product_id" />
        <field name="price" column="price" />                       
    </entity>
</entity>

<fields>
    <field name="row_id" type="string" indexed="true" stored="true" required="true"/>
    <field name="company_id" type="integer" indexed="true" stored="true" required="true" />
    <field name="company_name" type="text" indexed="true" stored="true"/>
    <field name="service_id" type="integer" indexed="true" stored="true" required="true" />
    <field name="price" type="tfloat" indexed="true" stored="true" required="true" />
 </fields>

任何反馈将不胜感激!!!

4

4 回答 4

1

您可以使用函数查询按总和对结果进行排序,请参见此处。在我的上一个项目中,我们使用了每晚构建的 4.0,它运行良好。它包含比 1.4 多得多的功能,值得您使用非发布版本冒的小风险。

更新:
要使用总和,您可以尝试为每个产品价格添加一个动态字段(我不知道如何将总和与多值字段一起使用,或者是否可能)。

添加到数据配置
<field name="price_${products.product_id}" column="price" />

添加到 schema.xml
<dynamicField name="price_*" type="decimal" indexed="false" stored="true" />

如果我理解正确,您应该可以使用如下查询:
q= : &sort=sum(price_"id for nails",price_"id for screw",price_"id for ...") asc

于 2011-04-05T16:58:07.923 回答
0

Solr 并非旨在取代关系数据库。如果您仍想索引关系内容,则需要对它们进行非规范化,因此将包含冗余数据。因此,对于大多数查询,结果的计数将关闭,例如,仅搜索公司名称将产生比预期更高的结果总数。但是,随着字段崩溃,您可以摆脱它。但是,如果您使用刻面,则不可能从那里消除重复项。

如果你用你提到的所有数据形成一个单一的模式,那么你可以在一定程度上执行关系查询。谷歌“solr issue 2272”以获取详细信息。目前只能在单个模式中实现。

我相信此时在搜索引擎中执行求和操作是不可能的。我可能是错的,如果有人知道怎么做,我也会很感兴趣。

于 2011-04-05T14:33:34.320 回答
0

我想您可能会问如何自定义评分。这是 lucene 中的一个示例。
http://sujitpal.blogspot.com/2010/10/custom-scoring-with-lucene-payloads.html

来自 LucidImagination http://www.lucidimagination.com/blog/2009/08/05/getting-started-with-payloads/

于 2011-04-09T15:36:33.557 回答
0

在 1.4.1 中可能,在当前的主干(4.0)中没有或至少不容易。

在 solr 1.4 中有可以对返回的记录执行聚合的字段折叠。在trunk solr 4.0中,这已经变成了一个只能执行最小/最大类型查询的分组选项(据我所知)。

文档可以在这里找到:

http://wiki.apache.org/solr/FieldCollapsing

请记住,您必须扩展关系(将其视为所涉及表的 1 个大型非规范化视图)。

于 2011-03-31T14:08:51.827 回答