阔叶Solr查询 [英] solr query in broadleaf

查看:74
本文介绍了阔叶Solr查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Solr和Broadleaf的新手。

I am new to Solr and Broadleaf.

我在Broadleaf工作,因为他们使用solr搜索。那是完美的工作条件。
产品表现在具有类别字段和按类别分类的阔叶搜索
根据要求,我扩展了产品表并使用公司ID制作了新表,因此在我的ExtendedProduct表中有两个字段companyId和productId(fk带有产品表)
现在我也想按companyId获取产品列表。

I am working in Broadleaf, in that they using the solr search. that's perfectly fine and working condition. Product table has category field and broadleaf searches by category right now As per requirement i extend the Product table and make new table with company id, so in my ExtendedProduct table there are two fields companyId and productId(fk with product table) Now i want to get product list by companyId also.

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

our schema.xml file looks below

    <?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文件看起来像

and solrConfig.xml files looks like

<?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

Right now in broadleaf they are placing query for category:2023. below are the SolrQuery.toString looks like q=category%3A2003&fl=id&rows=15&fq=namespace%3Ad&start=0

我仍然不知道如何在其中配置表名。

I still can't find out how/where table name is configured into this.

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

I want to find product by companyId also, which change should i make to do this ?

感谢Advance,
Ankit

Thanks in advance, Ankit

推荐答案

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

The main documentation link for this is at http://docs.broadleafcommerce.org/current/Catalog-and-Search.html.

其显着点复制如下:


动态字段

Dynamic fields

这些字段由用户通过
blc_field和blc_field_search_types中的数据库条目指定。在讨论
到底在字段中发生什么之前,我们必须首先介绍
Solr中的动态字段是什么。如果打开schema.xml,将看到许多
个不同字段的列表。以下是简短摘录:

These fields are specified by the user via database entries in blc_field and blc_field_search_types. Before we talk about what exactly goes in a Field, we must first cover what a dynamic field in Solr is. If you open up schema.xml, you will see a listing of many different fields. A short excerpt follows:







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

Here, we're defining a few dynamic fields. For example, if we were to create a field that was called manufactuer_s, it would be indexed by Solr as a Solr.StrField.

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

Another important distinction is between two properties in FieldImpl: searchableFieldTypes and facetFieldType. Searchable field types will be built into the Solr index, of which you may have multiple types. For example, you might want to index a field as both a String field and a Text field (text fields allow partial matches). However, you would only want to facet on the String field. The Broadleaf Field implementation gives you this freedom. Note, also, that the facet field also controls the Solr index to use for sorting.

作为一个简单的示例,让我们看一下可能发生的情况如果我们有
,则定义以下字段:

As a quick example, let's take a look at what might happen if we have the following fields defined:

制造商,facetFieldType: s,searchableFieldTypes:{ s, t}
defaultSku.retailPrice,facetFieldType: d defaultSku.name,
facetField: s,searchableFieldTypes:{ s, t},我们为
样本产品建立索引。 JSON中合适的Solr表示形式是:

manufacturer, facetFieldType: "s", searchableFieldTypes: { "s", "t" } defaultSku.retailPrice, facetFieldType: "d" defaultSku.name, facetField: "s", searchableFieldTypes: { "s", "t" } and we index a sample product. A suitable Solr representation in JSON would be:

{id:100,category:
[2000,2002],制造商: Spice Exchange,

制造商_t:香料交换,

defaultSku.retailPrice_d:6.99,defaultSku.name_s:
死苏格兰威士忌帽子酱汁的日,defaultSku.name_t:日
的苏格兰威士忌帽子酱辣酱,可搜索:
苏格兰威士忌帽子酱调味品交换日}}

{ 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 : "Day of the Dead Scotch Bonnet Hot Sauce", searchable : "Spice Exchange Day of the Dead Scotch Bonnet Hot Sauce" }

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

You might be wondering what that searchable field is. When you specify a Field as searchable, we will copy the Field's value into the solr index field searchable. When we do queries later on, they will be against this field.

我们将很快回到这一点,看看如何进行排序,搜索和
刻面将对此产品不利。

We'll get back to this shortly and see how sorting, searching and faceting would work against this product.

因此,基本上,您定义了BLC_FIELD条目(这是FieldImpl Java类),在propertyName字段中具有 companyId。从项目中的load_catalog_data.sql中,这就是导入 manufacturer字段以进行搜索的方式:

So basically, you define an entry into BLC_FIELD (which is the FieldImpl Java class) that has 'companyId' for the propertyName field. From load_catalog_data.sql in your project, this is how the 'manufacturer' field is imported to be searched on:

INSERT INTO BLC_FIELD (FIELD_ID, ENTITY_TYPE, PROPERTY_NAME, ABBREVIATION, SEARCHABLE, FACET_FIELD_TYPE) VALUES (1, 'PRODUCT', 'manufacturer', 'mfg', 1, 's');

这篇关于阔叶Solr查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆