【问题标题】:Hybris Solr SortHybris Solr 排序
【发布时间】:2018-03-27 12:12:43
【问题描述】:

我修改了我的代码,为价格添加了新的 solr 排序。

INSERT_UPDATE FieldSolrSort;sort(indexedType(identifier),code)[unique=true];fieldName[unique=true];descending[unique=true];$IndexedType:price;priceValue;true

我目前有两个 solr 排序

  • 名称升序
  • 名称降序

我为价格添加了新的 solr 排序

  • 价格上涨
  • 价格递减

但我希望我的新 solr 排序仅在用户登录时显示。有人知道吗?谢谢

【问题讨论】:

    标签: sorting solr hybris


    【解决方案1】:

    第 1 步:导入 impex 以启用价格排序选项

    如果您推荐任何 OOTB 商店 (apparelstore),您可以在 Impex 中看到价格排序 (price-asc) 选项。我在下面突出显示了 Impex。

    第 2 步:对匿名用户隐藏

    在匿名用户的情况下不要呈现价格排序。正如我在下面提到的,您可以借助 JSTL 条件来检查。

    请注意:以下代码仅供参考,我没有测试过

    orderFormPagination.tag

                            <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
                            <%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions"%>
                            <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
    
                            <c:set var="isLoggedInUser" value="false" />
                            <sec:authorize ifNotGranted="ROLE_ANONYMOUS">
                                <c:set var="isLoggedInUser" value="true" />
                            </sec:authorize>
    
                            <select id="sortOptions${top ? '1' : '2'}" name="sort" class="form-control">
                                <option disabled><spring:theme
                                        code="${themeMsgKey}.sortTitle" /></option>
                                <c:forEach items="${searchPageData.sorts}" var="sort">
    
                                    <c:if test="${isLoggedInUser || (!isLoggedInUser && !fn:startsWith(sort.code, 'price'))}">
                                        <option value="${sort.code}"
                                            ${sort.selected? 'selected="selected"' : ''}>
                                            <c:choose>
                                                <c:when test="${not empty sort.name}">
                                            ${sort.name}
                                        </c:when>
                                                <c:otherwise>
                                                    <spring:theme code="${themeMsgKey}.sort.${sort.code}" />
                                                </c:otherwise>
                                            </c:choose>
                                        </option>
                                    </c:if>
                                </c:forEach>
                            </select>
    

    Impex


    定义 SolrIndexedProperty

    INSERT_UPDATE SolrIndexedProperty ; solrIndexedType(identifier)[unique=true] ; name[unique=true]      ; type(code) ; sortableType(code) ; currency[default=false] ; localized[default=false] ; multiValue[default=false] ; useForSpellchecking[default=false] ; useForAutocomplete[default=false] ; fieldValueProvider                      ; ftsPhraseQuery[default=false] ; ftsPhraseQueryBoost ; ftsQuery[default=false] ; ftsQueryBoost ; ftsFuzzyQuery[default=false] ; ftsFuzzyQueryBoost ; ftsWildcardQuery[default=false] ; ftsWildcardQueryType(code)[default=POSTFIX] ; ftsWildcardQueryBoost ; ftsWildcardQueryMinTermLength
                                      ; $solrIndexedType                         ; name                   ; text       ; sortabletext       ;                         ; true                     ;                           ; true                               ; true                              ;                                         ; true                          ; 100                 ; true                    ; 50            ; true                         ; 25                 ;                                 ;                                             ;                       ;
                                      ; $solrIndexedType                         ; priceValue             ; double     ;                    ; true                    ;                          ;                           ;                                    ;                                   ; productPriceValueProvider               ;                               ;                     ;                         ;               ;                              ;                    ;                                 ;                                             ;                       ;                              
    

    定义可用的排序

    INSERT_UPDATE SolrSort ; &sortRefID ; indexedType(identifier)[unique=true] ; code[unique=true] ; useBoost  
                           ; sortRef3   ; $solrIndexedType                     ; name-asc          ; false   
                           ; sortRef4   ; $solrIndexedType                     ; name-desc         ; false   
                           ; sortRef5   ; $solrIndexedType                     ; price-asc         ; false   
                           ; sortRef6   ; $solrIndexedType                     ; price-desc        ; false   
    

    定义排序字段

    INSERT_UPDATE SolrSortField ; sort(indexedType(identifier),code)[unique=true] ; fieldName[unique=true] ; ascending[unique=true]                
                                ; $solrIndexedType:name-asc                       ; name                   ; true                  
                                ; $solrIndexedType:name-desc                      ; name                   ; false                 
                                ; $solrIndexedType:price-asc                      ; priceValue             ; true                  
                                ; $solrIndexedType:price-desc                     ; priceValue             ; false                 
    

    更新索引类型产品中的排序选项

    INSERT_UPDATE SolrIndexedType ; identifier[unique=true] ; type(code) ; variant ; sorts(&sortRefID)                                    
                                  ; $solrIndexedType        ; Product    ; false   ; sortRef3,sortRef4,sortRef5,sortRef6
    

    找到detail post here


    如果你想知道how to add custom Sort By Option with custom AttributeComparator?

    【讨论】:

    • 我已经添加了具有正确功能的新 solr 排序,现在我希望只有登录用户才能看到新添加的 solr 排序。谢谢
    • 不要通过在JSP/tag 中添加条件来呈现Price 选项。检查我更新的帖子。
    • 如果用户知道 URL,即使这样也不会让匿名用户按价格排序,因为我们只是从 UI 中隐藏它。您需要在服务器端处理它以完全限制它。
    • .tag 文件中的代码是否只隐藏来自匿名用户的价格排序选项?
    • 是的,可以看到条件!isLoggedInUser &amp;&amp; !fn:startsWith(sort.code, 'price')
    猜你喜欢
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多