⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productsearch.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        public void setSortOrder(ProductSearchContext productSearchContext) {            if (productSearchContext.includedKeywordSearch) {                // we have to check this in order to be sure that there is a totalRelevancy to sort by...                productSearchContext.orderByList.add("-totalRelevancy");                productSearchContext.fieldsToSelect.add("totalRelevancy");            }        }        public String getOrderName() {            return "KeywordRelevancy";        }        public String prettyPrintSortOrder(boolean detailed) {            return "Keyword Relevancy";        }        public boolean isAscending() {            return false;        }    }    public static class SortProductField extends ResultSortOrder {        protected String fieldName;        protected boolean ascending;        /** Some good field names to try might include:         * [productName]         * [totalQuantityOrdered] for most popular or most purchased         * [lastModifiedDate]         *         *  You can also include any other field on the Product entity.         */        public SortProductField(String fieldName, boolean ascending) {            this.fieldName = fieldName;            this.ascending = ascending;        }        public void setSortOrder(ProductSearchContext productSearchContext) {            if (productSearchContext.getDelegator().getModelEntity("Product").isField(fieldName)) {                productSearchContext.dynamicViewEntity.addAlias("PROD", fieldName);            } else if (productSearchContext.getDelegator().getModelEntity("ProductCalculatedInfo").isField(fieldName)) {                productSearchContext.dynamicViewEntity.addAlias("PRODCI", fieldName);            }            if (ascending) {                productSearchContext.orderByList.add("+" + fieldName);            } else {                productSearchContext.orderByList.add("-" + fieldName);            }            productSearchContext.fieldsToSelect.add(fieldName);        }        public String getOrderName() {            return "ProductField:" + this.fieldName;        }        public String prettyPrintSortOrder(boolean detailed) {            if ("productName".equals(this.fieldName)) {                return "Product Name";            } else if ("totalQuantityOrdered".equals(this.fieldName)) {                return "Popularity by Orders";            } else if ("totalTimesViewed".equals(this.fieldName)) {                return "Popularity by Views";            } else if ("averageCustomerRating".equals(this.fieldName)) {                return "Customer Rating";            }            return this.fieldName;        }        public boolean isAscending() {            return this.ascending;        }    }    public static class SortProductPrice extends ResultSortOrder {        protected String productPriceTypeId;        protected String currencyUomId;        protected String productStoreGroupId;        protected boolean ascending;        public SortProductPrice(String productPriceTypeId, boolean ascending) {            this.productPriceTypeId = productPriceTypeId;            this.ascending = ascending;        }        public SortProductPrice(String productPriceTypeId, String currencyUomId, String productStoreGroupId, boolean ascending) {            this.productPriceTypeId = productPriceTypeId;            this.currencyUomId = currencyUomId;            this.productStoreGroupId = productStoreGroupId;            this.ascending = ascending;        }        public void setSortOrder(ProductSearchContext productSearchContext) {            if (this.currencyUomId == null) {                this.currencyUomId = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD");            }            if (this.productStoreGroupId == null) {                this.productStoreGroupId = "_NA_";            }            // SortProductPrice, this will be a bit more complex, need to add a ProductPrice member entity            productSearchContext.dynamicViewEntity.addMemberEntity("SPPRC", "ProductPrice");            productSearchContext.dynamicViewEntity.addViewLink("PROD", "SPPRC", Boolean.TRUE, UtilMisc.toList(new ModelKeyMap("productId", "productId")));            productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortProductPriceTypeId", "productPriceTypeId", null, null, null, null);            productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortCurrencyUomId", "currencyUomId", null, null, null, null);            productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortProductStoreGroupId", "productStoreGroupId", null, null, null, null);            productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortFromDate", "fromDate", null, null, null, null);            productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortThruDate", "thruDate", null, null, null, null);            productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortPrice", "price", null, null, null, null);                        productSearchContext.entityConditionList.add(new EntityExpr("sortProductPriceTypeId", EntityOperator.EQUALS, this.productPriceTypeId));            productSearchContext.entityConditionList.add(new EntityExpr("sortCurrencyUomId", EntityOperator.EQUALS, this.currencyUomId));            productSearchContext.entityConditionList.add(new EntityExpr("sortProductStoreGroupId", EntityOperator.EQUALS, this.productStoreGroupId));            productSearchContext.entityConditionList.add(new EntityExpr("sortFromDate", EntityOperator.LESS_THAN_EQUAL_TO, productSearchContext.nowTimestamp));            productSearchContext.entityConditionList.add(new EntityExpr(                    new EntityExpr("sortThruDate", EntityOperator.EQUALS, null), EntityOperator.OR,                     new EntityExpr("sortThruDate", EntityOperator.GREATER_THAN_EQUAL_TO, productSearchContext.nowTimestamp)));            if (ascending) {                productSearchContext.orderByList.add("+sortPrice");            } else {                productSearchContext.orderByList.add("-sortPrice");            }            productSearchContext.fieldsToSelect.add("sortPrice");        }        public String getOrderName() {            return "ProductPrice:" + productPriceTypeId;        }        public String prettyPrintSortOrder(boolean detailed) {            String priceTypeName = null;            if ("LIST_PRICE".equals(this.productPriceTypeId)) {                priceTypeName = "List Price";            } else if ("DEFAULT_PRICE".equals(this.productPriceTypeId)) {                priceTypeName = "Default Price";            } else if ("AVERAGE_COST".equals(this.productPriceTypeId)) {                priceTypeName = "Average Cost";            }            return (priceTypeName == null ? "Price" : priceTypeName) + " (" + (this.ascending ? "Low to High)" : "High to Low)");        }        public boolean isAscending() {            return this.ascending;        }    }    /** A rather large and verbose method that doesn't use the cool constraint and sort order objects */    /*    public static ArrayList parametricKeywordSearchStandAlone(Set featureIdSet, String keywordsString, GenericDelegator delegator, String productCategoryId, boolean includeSubCategories, String visitId, boolean anyPrefix, boolean anySuffix, boolean isAnd) {        // TODO: implement this for the new features        boolean removeStems = UtilProperties.propertyValueEquals("prodsearch", "remove.stems", "true");        Timestamp nowTimestamp = UtilDateTime.nowTimestamp();        // make view-entity & EntityCondition        int index = 1;        List entityConditionList = new LinkedList();        List orderByList = new LinkedList();        List fieldsToSelect = UtilMisc.toList("productId");        DynamicViewEntity dynamicViewEntity = new DynamicViewEntity();        dynamicViewEntity.addMemberEntity("PROD", "Product");        dynamicViewEntity.addAlias("PROD", "productName");        boolean productIdGroupBy = false;        // Category        if (productCategoryId != null && productCategoryId.length() > 0) {            List productCategoryIdList = null;            if (includeSubCategories) {                // find all sub-categories recursively, make a Set of productCategoryId                Set productCategoryIdSet = new HashSet();                getAllSubCategoryIds(productCategoryId, productCategoryIdSet, delegator, nowTimestamp);                productCategoryIdList = new ArrayList(productCategoryIdSet);            } else {                productCategoryIdList = UtilMisc.toList(productCategoryId);            }            // make index based values and increment            String entityAlias = "PCM" + index;            String prefix = "pcm" + index;            index++;            dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember");            dynamicViewEntity.addAlias(entityAlias, prefix + "ProductCategoryId", "productCategoryId", null, null, null, null);            dynamicViewEntity.addAlias(entityAlias, prefix + "FromDate", "fromDate", null, null, null, null);            dynamicViewEntity.addAlias(entityAlias, prefix + "ThruDate", "thruDate", null, null, null, null);            dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId"));            entityConditionList.add(new EntityExpr(prefix + "ProductCategoryId", EntityOperator.IN, productCategoryIdList));            entityConditionList.add(new EntityExpr(new EntityExpr(prefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(prefix + "ThruDate", EntityOperator.GREATER_THAN, nowTimestamp)));            entityConditionList.add(new EntityExpr(prefix + "FromDate", EntityOperator.LESS_THAN, nowTimestamp));        }        // Keyword        List keywordFirstPass = KeywordSearch.makeKeywordList(keywordsString);        List keywordList = KeywordSearch.fixKeywords(keywordFirstPass, anyPrefix, anySuffix, removeStems, isAnd);        if (keywordList.size() > 0) {            if (isAnd) {                // add up the relevancyWeight fields from all keyword member entities for a total to sort by                ComplexAlias complexAlias = new ComplexAlias("+");                Iterator keywordIter = keywordList.iterator();                while (keywordIter.hasNext()) {                    String keyword = (String) keywordIter.next();                    // make index based values and increment                    String entityAlias = "PK" + index;                    String prefix = "pk" + index;                    index++;                    dynamicViewEntity.addMemberEntity(entityAlias, "ProductKeyword");                    dynamicViewEntity.addAlias(entityAlias, prefix + "Keyword", "keyword", null, null, null, null);                    dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId"));                    entityConditionList.add(new EntityExpr(prefix + "Keyword", EntityOperator.LIKE, keyword));                    //don't add an alias for this, will be part of a complex alias: dynamicViewEntity.addAlias(entityAlias, prefix + "RelevancyWeight", "relevancyWeight", null, null, null, null);                    complexAlias.addComplexAliasMember(new ComplexAliasField(entityAlias, "relevancyWeight"));                }                dynamicViewEntity.addAlias(null, "totalRelevancy", null, null, null, null, null, complexAlias);                orderByList.add("-totalRelevancy");                fieldsToSelect.add("totalRelevancy");            } else {                // make index based values and increment                String entityAlias = "PK" + index;                String prefix = "pk" + index;                index++;                dynamicViewEntity.addMemberEntity(entityAlias, "ProductKeyword");                dynamicViewEntity.addAlias(entityAlias, "totalRelevancy", "relevancyWeight", null, null, null, "sum");                dynamicViewEntity.addAlias(entityAlias, prefix + "Keyword", "keyword", null, null, null, null);                dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId"));                orderByList.add("-totalRelevancy");                fieldsToSelect.add("totalRelevancy");                List keywordOrList = new LinkedList();                Iterator keywordIter = keywordList.iterator();                while (keywordIter.hasNext()) {                    String keyword = (String) keywordIter.next();                    keywordOrList.add(new EntityExpr(prefix + "Keyword", EntityOperator.LIKE, keyword));                }                entityConditionList.add(new EntityConditionList(keywordOrList, EntityOperator.OR));                productIdGroupBy = true;            }        }        // Features        if (featureIdSet != null && featureIdSet.size() > 0) {            Iterator featureIdIter = featureIdSet.iterator();            while (featureIdIter.hasNext()) {                String productFeatureId = (String) featureIdIter.next();                // make index based values and increment                String entityAlias = "PFA" + index;                String prefix = "pfa" + index;                index++;               

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -