📄 productsearch.java
字号:
if (includeSubCategories) {
ppBuf.append(" (and all sub-categories)");
}
return ppBuf.toString();
}
public boolean equals(Object obj) {
ProductSearchConstraint psc = (ProductSearchConstraint) obj;
if (psc instanceof CategoryConstraint) {
CategoryConstraint that = (CategoryConstraint) psc;
if (this.includeSubCategories != that.includeSubCategories) {
return false;
}
if (this.productCategoryId == null) {
if (that.productCategoryId != null) {
return false;
}
} else {
if (!this.productCategoryId.equals(that.productCategoryId)) {
return false;
}
}
return true;
} else {
return false;
}
}
}
public static class FeatureConstraint extends ProductSearchConstraint {
public static final String constraintName = "Feature";
protected String productFeatureId;
public FeatureConstraint(String productFeatureId) {
this.productFeatureId = productFeatureId;
}
public void addConstraint(ProductSearchContext productSearchContext) {
// make index based values and increment
String entityAlias = "PFA" + productSearchContext.index;
String prefix = "pfa" + productSearchContext.index;
productSearchContext.index++;
productSearchContext.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl");
productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ProductFeatureId", "productFeatureId", null, null, null, null);
productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "FromDate", "fromDate", null, null, null, null);
productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ThruDate", "thruDate", null, null, null, null);
productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId"));
productSearchContext.entityConditionList.add(new EntityExpr(prefix + "ProductFeatureId", EntityOperator.EQUALS, productFeatureId));
productSearchContext.entityConditionList.add(new EntityExpr(new EntityExpr(prefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(prefix + "ThruDate", EntityOperator.GREATER_THAN, productSearchContext.nowTimestamp)));
productSearchContext.entityConditionList.add(new EntityExpr(prefix + "FromDate", EntityOperator.LESS_THAN, productSearchContext.nowTimestamp));
// add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later
productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", this.productFeatureId)));
}
public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) {
GenericValue productFeature = null;
GenericValue productFeatureType = null;
try {
productFeature = delegator.findByPrimaryKeyCache("ProductFeature", UtilMisc.toMap("productFeatureId", productFeatureId));
productFeatureType = productFeature == null ? null : productFeature.getRelatedOne("ProductFeatureType");
} catch (GenericEntityException e) {
Debug.logError(e, "Error finding ProductFeature and Type information for constraint pretty print", module);
}
return (productFeatureType == null ? "Feature: " : productFeatureType.getString("description") + ": ") + (productFeature == null ? "[" + this.productFeatureId + "]" : productFeature.getString("description"));
}
public boolean equals(Object obj) {
ProductSearchConstraint psc = (ProductSearchConstraint) obj;
if (psc instanceof FeatureConstraint) {
FeatureConstraint that = (FeatureConstraint) psc;
if (this.productFeatureId == null) {
if (that.productFeatureId != null) {
return false;
}
} else {
if (!this.productFeatureId.equals(that.productFeatureId)) {
return false;
}
}
return true;
} else {
return false;
}
}
}
public static class KeywordConstraint extends ProductSearchConstraint {
public static final String constraintName = "Keyword";
protected String keywordsString;
protected boolean anyPrefix;
protected boolean anySuffix;
protected boolean isAnd;
protected boolean removeStems;
public KeywordConstraint(String keywordsString, boolean anyPrefix, boolean anySuffix, Boolean removeStems, boolean isAnd) {
this.keywordsString = keywordsString;
this.anyPrefix = anyPrefix;
this.anySuffix = anySuffix;
this.isAnd = isAnd;
if (removeStems != null) {
this.removeStems = removeStems.booleanValue();
} else {
this.removeStems = UtilProperties.propertyValueEquals("prodsearch", "remove.stems", "true");
}
}
public Set makeFullKeywordSet(GenericDelegator delegator) {
Set keywordSet = KeywordSearch.makeKeywordSet(this.keywordsString, null, true);
Set fullKeywordSet = new TreeSet();
// expand the keyword list according to the thesaurus and create a new set of keywords
Iterator keywordIter = keywordSet.iterator();
while (keywordIter.hasNext()) {
String keyword = (String) keywordIter.next();
Set expandedSet = new TreeSet();
boolean replaceEntered = KeywordSearch.expandKeywordForSearch(keyword, expandedSet, delegator);
fullKeywordSet.addAll(expandedSet);
if (!replaceEntered) {
fullKeywordSet.add(keyword);
}
}
return fullKeywordSet;
}
public void addConstraint(ProductSearchContext productSearchContext) {
// just make the fixed keyword lists and put them in the context
if (isAnd) {
// when isAnd is true we need to make a list of keyword sets where each set corresponds to one
//incoming/entered keyword and contains all of the expanded keywords plus the entered keyword if none of
//the expanded keywords are flagged as replacements; now the tricky part: each set should be or'ed together,
//but then the sets should be and'ed to produce the overall expression; create the SQL for this
//needs some work as the current method only support a list of and'ed words and a list of or'ed words, not
//a list of or'ed sets to be and'ed together
Set keywordSet = KeywordSearch.makeKeywordSet(this.keywordsString, null, true);
// expand the keyword list according to the thesaurus and create a new set of keywords
Iterator keywordIter = keywordSet.iterator();
while (keywordIter.hasNext()) {
String keyword = (String) keywordIter.next();
Set expandedSet = new TreeSet();
boolean replaceEntered = KeywordSearch.expandKeywordForSearch(keyword, expandedSet, productSearchContext.getDelegator());
if (!replaceEntered) {
expandedSet.add(keyword);
}
Set fixedSet = KeywordSearch.fixKeywordsForSearch(expandedSet, anyPrefix, anySuffix, removeStems, isAnd);
Set fixedKeywordSet = new HashSet();
fixedKeywordSet.addAll(fixedSet);
productSearchContext.keywordFixedOrSetAndList.add(fixedKeywordSet);
}
} else {
// when isAnd is false, just add all of the new entries to the big list
Set keywordFirstPass = makeFullKeywordSet(productSearchContext.getDelegator()); // includes keyword expansion, etc
Set keywordSet = KeywordSearch.fixKeywordsForSearch(keywordFirstPass, anyPrefix, anySuffix, removeStems, isAnd);
productSearchContext.orKeywordFixedSet.addAll(keywordSet);
}
// add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later
Map valueMap = UtilMisc.toMap("constraintName", constraintName, "infoString", this.keywordsString);
valueMap.put("anyPrefix", this.anyPrefix ? "Y" : "N");
valueMap.put("anySuffix", this.anySuffix ? "Y" : "N");
valueMap.put("isAnd", this.isAnd ? "Y" : "N");
valueMap.put("removeStems", this.removeStems ? "Y" : "N");
productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", valueMap));
}
/** pretty print for log messages and even UI stuff */
public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) {
return "Keyword(s): \"" + this.keywordsString + "\", where " + (isAnd ? "all words match" : "any word matches");
}
public boolean equals(Object obj) {
ProductSearchConstraint psc = (ProductSearchConstraint) obj;
if (psc instanceof KeywordConstraint) {
KeywordConstraint that = (KeywordConstraint) psc;
if (this.anyPrefix != that.anyPrefix) {
return false;
}
if (this.anySuffix != that.anySuffix) {
return false;
}
if (this.isAnd != that.isAnd) {
return false;
}
if (this.removeStems != that.removeStems) {
return false;
}
if (this.keywordsString == null) {
if (that.keywordsString != null) {
return false;
}
} else {
if (!this.keywordsString.equals(that.keywordsString)) {
return false;
}
}
return true;
} else {
return false;
}
}
}
public static class LastUpdatedRangeConstraint extends ProductSearchConstraint {
public static final String constraintName = "LastUpdatedRange";
protected Timestamp fromDate;
protected Timestamp thruDate;
public LastUpdatedRangeConstraint(Timestamp fromDate, Timestamp thruDate) {
this.fromDate = fromDate;
this.thruDate = thruDate;
}
public void addConstraint(ProductSearchContext productSearchContext) {
// TODO: implement LastUpdatedRangeConstraint makeEntityCondition
}
/** pretty print for log messages and even UI stuff */
public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) {
// TODO: implement the pretty print for log messages and even UI stuff
return null;
}
public boolean equals(Object obj) {
ProductSearchConstraint psc = (ProductSearchConstraint) obj;
if (psc instanceof LastUpdatedRangeConstraint) {
LastUpdatedRangeConstraint that = (LastUpdatedRangeConstraint) psc;
if (this.fromDate == null) {
if (that.fromDate != null) {
return false;
}
} else {
if (!this.fromDate.equals(that.fromDate)) {
return false;
}
}
if (this.thruDate == null) {
if (that.thruDate != null) {
return false;
}
} else {
if (!this.thruDate.equals(that.thruDate)) {
return false;
}
}
return true;
} else {
return false;
}
}
}
public static class ListPriceRangeConstraint extends ProductSearchConstraint {
public static final String constraintName = "ListPriceRange";
protected Double lowPrice;
protected Double highPrice;
public ListPriceRangeConstraint(Double lowPrice, Double highPrice) {
this.lowPrice = lowPrice;
this.highPrice = highPrice;
}
public void addConstraint(ProductSearchContext productSearchContext) {
// TODO: implement ListPriceRangeConstraint makeEntityCondition
}
/** pretty print for log messages and even UI stuff */
public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) {
// TODO: implement the pretty print for log messages and even UI stuff
return null;
}
public boolean equals(Object obj) {
ProductSearchConstraint psc = (ProductSearchConstraint) obj;
if (psc instanceof ListPriceRangeConstraint) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -