1

我是 Solr 和 Broadleaf 的新手。

我在 Broadleaf 工作,因为他们使用 solr 搜索。这是非常好的和工作条件。产品表现在有类别字段和按类别搜索的阔叶根据要求,我扩展了产品表并使用公司 ID 创建了新表,所以在我的扩展产品表中有两个字段 companyId 和 productId(fk with product table) 现在我想也可以通过 companyId 获取产品列表。

我们的 schema.xml 文件如下所示

    <?xml version="1.0" encoding="UTF-8" ?>
<schema name="example" version="1.5">
    <fields>
        <field name="namespace" type="string" indexed="true" stored="false" />
        <field name="id" type="string" indexed="true" stored="true" />
        <field name="productId" type="long" indexed="true" stored="true" />
        <field name="category" type="long" indexed="true" stored="false" multiValued="true" />
        <field name="explicitCategory" type="long" indexed="true" stored="false" multiValued="true" />
        <field name="searchable" type="text_general" indexed="true" stored="false" />
        <dynamicField name="*_searchable" type="text_general" indexed="true" stored="false" />

        <dynamicField name="*_i" type="int" indexed="true" stored="false" />
        <dynamicField name="*_is" type="int" indexed="true" stored="false" multiValued="true" />
        <dynamicField name="*_s" type="string" indexed="true" stored="false" />
        <dynamicField name="*_ss" type="string" indexed="true" stored="false" multiValued="true" />
        <dynamicField name="*_l" type="long" indexed="true" stored="false" />
        <dynamicField name="*_ls" type="long" indexed="true" stored="false" multiValued="true" />
        <dynamicField name="*_t" type="text_general" indexed="true" stored="false" />
        <dynamicField name="*_txt" type="text_general" indexed="true" stored="false" multiValued="true" />
        <dynamicField name="*_b" type="boolean" indexed="true" stored="false" />
        <dynamicField name="*_bs" type="boolean" indexed="true" stored="false" multiValued="true" />
        <dynamicField name="*_d" type="double" indexed="true" stored="false" />
        <dynamicField name="*_ds" type="double" indexed="true" stored="false" multiValued="true" />
        <dynamicField name="*_p" type="double" indexed="true" stored="false" />

        <dynamicField name="*_dt" type="date" indexed="true" stored="false" />
        <dynamicField name="*_dts" type="date" indexed="true" stored="false" multiValued="true" />

        <!-- some trie-coded dynamic fields for faster range queries -->
        <dynamicField name="*_ti" type="tint" indexed="true" stored="false" />
        <dynamicField name="*_tl" type="tlong" indexed="true" stored="false" />
        <dynamicField name="*_td" type="tdouble" indexed="true" stored="false" />
        <dynamicField name="*_tdt" type="tdate" indexed="true" stored="false" />
    </fields>

    <uniqueKey>id</uniqueKey>

    <types>
        <!-- The StrField type is not analyzed, but indexed/stored verbatim. -->
        <fieldType name="string" class="solr.StrField" sortMissingLast="true" />

        <!-- boolean type: "true" or "false" -->
        <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" />

        <!-- Default numeric field types. For faster range queries, consider the 
            tint/tlong/tdouble types. -->
        <fieldType name="int" class="solr.TrieIntField" 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="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0" />
        <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0" />

        <!-- The format for this date field is of the form 1995-12-31T23:59:59Z, 
            and is a more restricted form of the canonical representation of dateTime 
            http://www.w3.org/TR/xmlschema-2/#dateTime The trailing "Z" designates UTC 
            time and is mandatory. Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z 
            All other components are mandatory. Expressions can also be used to denote 
            calculations that should be performed relative to "NOW" to determine the 
            value, ie... NOW/HOUR ... Round to the start of the current hour NOW-1DAY 
            ... Exactly 1 day prior to now NOW/DAY+6MONTHS+3DAYS ... 6 months and 3 days 
            in the future from the start of the current day Consult the DateField javadocs 
            for more information. Note: For faster range queries, consider the tdate 
            type -->
        <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0" />

        <!-- A Trie based date field for faster date range queries and date faceting. -->
        <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" />

        <!-- A general text field that has reasonable, generic cross-language defaults: 
            it tokenizes with StandardTokenizer and down cases. -->
        <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
            <analyzer type="index">
                <tokenizer class="solr.StandardTokenizerFactory" />
                <filter class="solr.LowerCaseFilterFactory" />
            </analyzer>
            <analyzer type="query">
                <tokenizer class="solr.StandardTokenizerFactory" />
                <filter class="solr.LowerCaseFilterFactory" />
            </analyzer>
        </fieldType>

    </types>
</schema>

和 solrConfig.xml 文件看起来像

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <abortOnConfigurationError>${solr.abortOnConfigurationError:true} </abortOnConfigurationError>
    <luceneMatchVersion>LUCENE_40</luceneMatchVersion>
    <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}" />
    <updateHandler class="solr.DirectUpdateHandler2" />

    <query>
        <maxBooleanClauses>1024</maxBooleanClauses>

        <filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0" />
        <queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
        <documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />

        <enableLazyFieldLoading>true</enableLazyFieldLoading>

        <queryResultWindowSize>20</queryResultWindowSize>
        <queryResultMaxDocsCached>200</queryResultMaxDocsCached>

        <listener event="newSearcher" class="solr.QuerySenderListener" />
        <listener event="firstSearcher" class="solr.QuerySenderListener">
            <arr name="queries">
                <lst>
                    <str name="q">static firstSearcher warming in solrconfig.xml</str>
                </lst>
            </arr>
        </listener>

        <useColdSearcher>false</useColdSearcher>
        <maxWarmingSearchers>2</maxWarmingSearchers>
    </query>

    <requestDispatcher>
        <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048000" />
        <httpCaching never304="true" />
    </requestDispatcher>

    <requestHandler name="/select" class="solr.SearchHandler">
        <lst name="defaults">
            <str name="echoParams">explicit</str>
            <int name="rows">4</int>
            <str name="df">name_t</str>
        </lst>
    </requestHandler>

    <requestHandler name="/update" class="solr.UpdateRequestHandler" />
    <requestHandler name="/update/csv" class="solr.CSVRequestHandler" startup="lazy" />
    <requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler" startup="lazy" />

    <queryResponseWriter name="json" class="solr.JSONResponseWriter">
        <str name="content-type">text/plain; charset=UTF-8</str>
    </queryResponseWriter>

</config>

现在在阔叶中,他们正在查询类别:2023。下面是 SolrQuery.toString 看起来像 q=category%3A2003&fl=id&rows=15&fq=namespace%3Ad&start=0

我仍然无法找出表名的配置方式/位置。

我也想按 companyId 查找产品,我应该做哪些更改?

提前致谢, Ankit

4

1 回答 1

3

主要文档链接位于http://docs.broadleafcommerce.org/current/Catalog-and-Search.html

其要点复制如下:

动态字段

这些字段由用户通过 blc_field 和 blc_field_search_types 中的数据库条目指定。在我们讨论 Field 的具体内容之前,我们必须先了解一下 Solr 中的动态字段是什么。如果您打开 schema.xml,您将看到许多不同字段的列表。摘录如下:

在这里,我们定义了一些动态字段。例如,如果我们要创建一个名为 manufactuer_s 的字段,它将被 Solr 索引为 Solr.StrField。

另一个重要的区别是 FieldImpl 中的两个属性:searchableFieldTypes 和 facetFieldType。可搜索的字段类型将内置到 Solr 索引中,其中您可能有多种类型。例如,您可能希望将字段索引为字符串字段和文本字段(文本字段允许部分匹配)。但是,您只想在字符串字段上进行分面。Broadleaf Field 实现为您提供了这种自由。另请注意,facet 字段还控制用于排序的 Solr 索引。

举个简单的例子,让我们看看如果我们定义了以下字段会发生什么:

制造商,facetFieldType:“s”,searchableFieldTypes:{“s”,“t”} defaultSku.retailPrice,facetFieldType:“d”defaultSku.name,facetField:“s”,searchableFieldTypes:{“s”,“t”}和我们索引一个示例产品。JSON 中合适的 Solr 表示形式是:

{ id : 100, category : [2000, 2002], manufacturer_s : "Spice Exchange",
manufacturer_t : "Spice Exchange",
defaultSku.retailPrice_d : 6.99, defaultSku.name_s : "Day of the Dead Scotch Bonnet Hot Sauce", defaultSku。 name_t:“死亡苏格兰帽辣酱日”,可搜索:“死亡苏格兰帽辣酱的香料交换日”}

您可能想知道该可搜索字段是什么。当您将字段指定为可搜索时,我们会将字段的值复制到可搜索的 solr 索引字段中。当我们稍后进行查询时,他们将反对该字段。

我们将很快回到这一点,看看排序、搜索和分面将如何作用于这个产品。

因此,基本上,您在 BLC_FIELD(即 FieldImpl Java 类)中定义一个条目,该条目具有 propertyName 字段的“companyId”。从项目中的 load_catalog_data.sql 中,导入“制造商”字段以供搜索:

INSERT INTO BLC_FIELD (FIELD_ID, ENTITY_TYPE, PROPERTY_NAME, ABBREVIATION, SEARCHABLE, FACET_FIELD_TYPE) VALUES (1, 'PRODUCT', 'manufacturer', 'mfg', 1, 's');
于 2013-06-07T15:53:52.620 回答