索引具有mm关系的表

时间:2014-10-08 08:36:58

标签: solr typo3 extbase

我正在使用TYPO3 6.2.x实例和lucene solr。该网站项目包含一个产品目录,显示(谁会猜到?!)产品及其可能的组件。

索引产品或特定组件的数据库表是没有问题的。

第三个表通过存储产品和组件的specificix uid来保存这两个表之间的关系。

我不知道如何索引关系。最后,我想搜索一个产品,并且应该获得自己以及该产品的组件。

也许有人有类似的问题。

2 个答案:

答案 0 :(得分:1)

正如Jost在评论中提到的那样,Solr的内容被归一化为第一个标准。所以你必须决定你想要找到的实体。在您的情况下,这是回答:产品。

enter image description here 使用DrawIO

创建

因此,在Solr中,您可以将其归结为具有组件列表的产品。此任务的架构将非常简单,如下所示。此示例简化为您的问题,因此您可能需要使用其他字段和fieldTypes扩展它。

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="products" version="1.0">

  <types>
      <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
      <fieldType name="tint" class="solr.TrieIntField"  
        precisionStep="8" positionIncrementGap="0" />
      <fieldType name="long" class="solr.TrieLongField" 
        precisionStep="0" positionIncrementGap="0" />
  </types>


  <fields>
      <field name="id"         type="long"   indexed="true" stored="true" 
        multiValued="false" required="true" />
      <field name="name"       type="string" indexed="true" stored="true" 
        multiValued="false" />
      <field name="components" type="string" indexed="true" stored="true" 
        multiValued="true"  />
      <field name="_version_"  type="long"   indexed="true"   stored="true" />
  </fields>

  <uniqueKey>id</uniqueKey>

</schema>

正如您所看到的,它只包含三个相关字段,版本字段用于Solr内部版本控制,只需要存在。

  • id 这是产品的UID,因为它是您的主要实体,并且应该在结果中找到,它是必需的,唯一的和单值的。
  • 名称这是您的产品的名称,因为它是您的主要实体,并且在结果中可以找到它,它是唯一且单值的。如果它应该是唯一的或者不是我不知道的东西。
  • 组件这是一个多值字段。它将包含属于产品的组件的名称列表。是的,这似乎是多余的,但这是Solr的工作方式。

现在我们需要将数据导入到这个模式中,正如您所写,您已经有了dataimport。上面架构的 DIH配置可能如下所示。

<dataConfig>
<dataSource driver="xxx" url="xxx" user="xxx" />
    <document name="product">
        <entity name="item" query="select * from product">

            <field column="ID" name="id" />
            <field column="NAME" name="name" />

            <entity name="component" query="select name as component_name from component, product_components where product_id='${item.ID}' and component.id = component_id">
                <field column="COMPONENT_NAME" name="components" />
            </entity>

        </entity>
    </document>
</dataConfig>

产品的映射应该是直截了当的,唯一有趣的事实是product的名称映射到item。因此,当solr-internal时,产品列以item为前缀。与where product_id='${item.ID}'一样。

为了展平多对多关系,引入了嵌套实体组件。正如您在查询中看到的那样,此查询通过关系表执行连接以获取属于某个特定产品的所有组件。然后将这些组件映射到多值字段组件。


然而,这个解决方案有一个警告。 Solr的DIH将为每个嵌套实体执行一个查询。这意味着如果您有1.000个产品,DIH将执行一个查询以获取所有产品以及1.000个查询以获取每个产品的组件。这可能会产生性能问题。

要解决此问题, CachedSqlEntityProcessor ,但由于这不是您问题的目标,我不会在此详述。关于这个主题有几个问题和博客文章。

答案 1 :(得分:1)

谢谢你的详细解答,谢谢。

同时我使用了另一种解决方案。我创建了一个包含所有想要数据的mysql视图,并使用solr索引此视图。

SELECT
    concat(comp.uid, series.uid) As uid,
    comp.uid As cuid,
    comp.pid, comp.name, comp.teaser_text, comp.tstamp,comp.crdate, comp.cruser_id, comp.deleted, comp.hidden, comp.starttime, comp.endtime,
    comp.t3ver_oid, comp.t3ver_id, comp.t3ver_wsid, comp.t3ver_label, comp.t3ver_state, comp.t3ver_stage, comp.t3ver_count,
    comp.t3ver_tstamp, comp.t3ver_move_id, comp.sys_language_uid, comp.l10n_parent, comp.l10n_diffsource
FROM tx_productcatalog_domain_model_component As comp
    LEFT JOIN tx_productcatalog_series_component_mm As mm
        ON mm.uid_foreign = comp.uid
    LEFT JOIN tx_productcatalog_domain_model_series As series
        ON series.uid = mm.uid_local

此外,常见的TYPO3 tx_solr扩展需要一个TCA用于此视图,就像它是一个域模型一样。只需在包含数据的扩展的“ext_tables.php”中创建一个基本的TCA条目。

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_productcatalog_view_component');
$GLOBALS['TCA']['tx_productcatalog_view_component'] = array(
        'ctrl' => array(
                'sortby' => 'sorting',
                'title' => 'Component View',
                'label' => 'name',
                'tstamp' => 'tstamp',
                'crdate' => 'crdate',
                'cruser_id' => 'cruser_id',
                'dividers2tabs' => TRUE,

                'versioningWS' => 2,
                'versioning_followPages' => TRUE,

                'languageField' => 'sys_language_uid',
                'transOrigPointerField' => 'l10n_parent',
                'transOrigDiffSourceField' => 'l10n_diffsource',
                'delete' => 'deleted',
                'enablecolumns' => array(
                        'disabled' => 'hidden',
                        'starttime' => 'starttime',
                        'endtime' => 'endtime',
                ),
                'searchFields' => 'name, category, teaser_text, series_name',
                'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/haseke.gif'
        ),
);