|
|
@@ -223,9 +223,12 @@ public class ObjectToDocumentUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public static Document toDocument(Goods goods) {
|
|
|
- if (goods == null || goods.getComponent() == null || StringUtils.isEmpty(goods.getComponent().getId()) ||
|
|
|
- StringUtils.isEmpty(goods.getComponent().getCode()) || goods.getComponent().getKind() == null ||
|
|
|
- goods.getComponent().getBrand() == null) {
|
|
|
+ if (goods == null ||
|
|
|
+ (goods.getComponent() != null &&
|
|
|
+ (StringUtils.isEmpty(goods.getComponent().getId()) ||
|
|
|
+ StringUtils.isEmpty(goods.getComponent().getCode()) ||
|
|
|
+ goods.getComponent().getKind() == null ||
|
|
|
+ goods.getComponent().getBrand() == null))) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -273,74 +276,76 @@ public class ObjectToDocumentUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Component component = goods.getComponent();
|
|
|
- document.add(new StringField(SearchConstants.GOODS_CMP_ID_FIELD, String.valueOf(component.getId()), Store.YES));
|
|
|
- document.add(new StringField(SearchConstants.GOODS_CMP_CODE_FIELD, component.getCode().toLowerCase(), Store.YES));
|
|
|
- document.add(new BinaryDocValuesField(SearchConstants.GOODS_CMP_CODE_FIELD, new BytesRef(component.getCode())));
|
|
|
- if (component.getDescription() != null) {
|
|
|
- document.add(new TextField(SearchConstants.GOODS_CMP_DESCRIPTION_FIELD, component.getDescription(), Store.YES));
|
|
|
- }
|
|
|
- if (component.getVisitCount() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_CMP_VISIT_COUNT_FIELD, component.getVisitCount()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_CMP_VISIT_COUNT_FIELD, component.getVisitCount(), Store.YES));
|
|
|
- }
|
|
|
- if (component.getSearchCount() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD, component.getSearchCount()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD, component.getSearchCount(), Store.YES));
|
|
|
- }
|
|
|
+ if(goods.getComponent() != null){
|
|
|
+ Component component = goods.getComponent();
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_CMP_ID_FIELD, String.valueOf(component.getId()), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_CMP_CODE_FIELD, component.getCode().toLowerCase(), Store.YES));
|
|
|
+ document.add(new BinaryDocValuesField(SearchConstants.GOODS_CMP_CODE_FIELD, new BytesRef(component.getCode())));
|
|
|
+ if (component.getDescription() != null) {
|
|
|
+ document.add(new TextField(SearchConstants.GOODS_CMP_DESCRIPTION_FIELD, component.getDescription(), Store.YES));
|
|
|
+ }
|
|
|
+ if (component.getVisitCount() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_CMP_VISIT_COUNT_FIELD, component.getVisitCount()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_CMP_VISIT_COUNT_FIELD, component.getVisitCount(), Store.YES));
|
|
|
+ }
|
|
|
+ if (component.getSearchCount() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD, component.getSearchCount()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD, component.getSearchCount(), Store.YES));
|
|
|
+ }
|
|
|
|
|
|
- Kind kind = component.getKind();
|
|
|
- if (kind.getId() != null) {
|
|
|
- document.add(new StringField(SearchConstants.GOODS_KI_ID_FIELD, String.valueOf(kind.getId()), Store.YES));
|
|
|
- }
|
|
|
- if (kind.getNameCn() != null) {
|
|
|
- document.add(new TextField(SearchConstants.GOODS_KI_NAME_CN_FIELD, kind.getNameCn(), Store.YES));
|
|
|
- }
|
|
|
- if (kind.getLevel() != null) {
|
|
|
- document.add(new NumericDocValuesField(SearchConstants.GOODS_KI_LEVEL_FIELD, kind.getIsLeaf()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_KI_LEVEL_FIELD, kind.getIsLeaf(), Store.YES));
|
|
|
- }
|
|
|
- if (kind.getIsLeaf() != null) {
|
|
|
- document.add(
|
|
|
- new StringField(SearchConstants.GOODS_KI_ISLEAF_FIELD, String.valueOf(kind.getLevel()), Store.YES));
|
|
|
- }
|
|
|
- if (kind.getVisitCount() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_KI_VISIT_COUNT_FIELD, kind.getVisitCount()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_KI_VISIT_COUNT_FIELD, kind.getVisitCount(), Store.YES));
|
|
|
- }
|
|
|
- if (kind.getSearchCount() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_KI_SEARCH_COUNT_FIELD, kind.getSearchCount()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_KI_SEARCH_COUNT_FIELD, kind.getSearchCount(), Store.YES));
|
|
|
- }
|
|
|
+ Kind kind = component.getKind();
|
|
|
+ if (kind.getId() != null) {
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_KI_ID_FIELD, String.valueOf(kind.getId()), Store.YES));
|
|
|
+ }
|
|
|
+ if (kind.getNameCn() != null) {
|
|
|
+ document.add(new TextField(SearchConstants.GOODS_KI_NAME_CN_FIELD, kind.getNameCn(), Store.YES));
|
|
|
+ }
|
|
|
+ if (kind.getLevel() != null) {
|
|
|
+ document.add(new NumericDocValuesField(SearchConstants.GOODS_KI_LEVEL_FIELD, kind.getIsLeaf()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_KI_LEVEL_FIELD, kind.getIsLeaf(), Store.YES));
|
|
|
+ }
|
|
|
+ if (kind.getIsLeaf() != null) {
|
|
|
+ document.add(
|
|
|
+ new StringField(SearchConstants.GOODS_KI_ISLEAF_FIELD, String.valueOf(kind.getLevel()), Store.YES));
|
|
|
+ }
|
|
|
+ if (kind.getVisitCount() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_KI_VISIT_COUNT_FIELD, kind.getVisitCount()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_KI_VISIT_COUNT_FIELD, kind.getVisitCount(), Store.YES));
|
|
|
+ }
|
|
|
+ if (kind.getSearchCount() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_KI_SEARCH_COUNT_FIELD, kind.getSearchCount()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_KI_SEARCH_COUNT_FIELD, kind.getSearchCount(), Store.YES));
|
|
|
+ }
|
|
|
|
|
|
- Brand brand = component.getBrand();
|
|
|
- if (brand.getId() != null) {
|
|
|
- document.add(new StringField(SearchConstants.GOODS_BR_ID_FIELD, String.valueOf(brand.getId()), Store.YES));
|
|
|
- }
|
|
|
- if (brand.getNameCn() != null) {
|
|
|
- document.add(new TextField(SearchConstants.GOODS_BR_NAME_CN_FIELD, brand.getNameCn(), Store.YES));
|
|
|
- document.add(new StringField(SearchConstants.GOODS_BR_NAME_CN_UNTOKENIZED_FIELD, brand.getNameCn().toLowerCase(), Store.YES));
|
|
|
- document.add(new BinaryDocValuesField(SearchConstants.GOODS_BR_NAME_CN_UNTOKENIZED_FIELD, new BytesRef(brand.getNameCn())));
|
|
|
- }
|
|
|
- if (brand.getNameEn() != null) {
|
|
|
- document.add(new TextField(SearchConstants.GOODS_BR_NAME_EN_FIELD, brand.getNameEn(), Store.YES));
|
|
|
- document.add(new StringField(SearchConstants.GOODS_BR_NAME_EN_UNTOKENIZED_FIELD, brand.getNameEn().toLowerCase(), Store.YES));
|
|
|
- document.add(new BinaryDocValuesField(SearchConstants.GOODS_BR_NAME_EN_UNTOKENIZED_FIELD, new BytesRef(brand.getNameEn())));
|
|
|
- }
|
|
|
- if (brand.getUuid() != null) {
|
|
|
- document.add(new StringField(SearchConstants.GOODS_BR_UUID_FIELD, brand.getUuid(), Store.YES));
|
|
|
- }
|
|
|
- if (brand.getVisitCount() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_BR_VISIT_COUNT_FIELD, brand.getVisitCount()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_BR_VISIT_COUNT_FIELD, brand.getVisitCount(), Store.YES));
|
|
|
- }
|
|
|
- if (brand.getSearchCount() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_BR_SEARCH_COUNT_FIELD, brand.getSearchCount()));
|
|
|
- document.add(new LongField(SearchConstants.GOODS_BR_SEARCH_COUNT_FIELD, brand.getSearchCount(), Store.YES));
|
|
|
- }
|
|
|
- if (brand.getWeight() != null) {
|
|
|
- document.add(new DoubleDocValuesField(SearchConstants.GOODS_BR_WEIGHT_FIELD, brand.getWeight()));
|
|
|
- document.add(new DoubleField(SearchConstants.GOODS_BR_WEIGHT_FIELD, brand.getWeight(), Store.YES));
|
|
|
+ Brand brand = component.getBrand();
|
|
|
+ if (brand.getId() != null) {
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_BR_ID_FIELD, String.valueOf(brand.getId()), Store.YES));
|
|
|
+ }
|
|
|
+ if (brand.getNameCn() != null) {
|
|
|
+ document.add(new TextField(SearchConstants.GOODS_BR_NAME_CN_FIELD, brand.getNameCn(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_BR_NAME_CN_UNTOKENIZED_FIELD, brand.getNameCn().toLowerCase(), Store.YES));
|
|
|
+ document.add(new BinaryDocValuesField(SearchConstants.GOODS_BR_NAME_CN_UNTOKENIZED_FIELD, new BytesRef(brand.getNameCn())));
|
|
|
+ }
|
|
|
+ if (brand.getNameEn() != null) {
|
|
|
+ document.add(new TextField(SearchConstants.GOODS_BR_NAME_EN_FIELD, brand.getNameEn(), Store.YES));
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_BR_NAME_EN_UNTOKENIZED_FIELD, brand.getNameEn().toLowerCase(), Store.YES));
|
|
|
+ document.add(new BinaryDocValuesField(SearchConstants.GOODS_BR_NAME_EN_UNTOKENIZED_FIELD, new BytesRef(brand.getNameEn())));
|
|
|
+ }
|
|
|
+ if (brand.getUuid() != null) {
|
|
|
+ document.add(new StringField(SearchConstants.GOODS_BR_UUID_FIELD, brand.getUuid(), Store.YES));
|
|
|
+ }
|
|
|
+ if (brand.getVisitCount() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_BR_VISIT_COUNT_FIELD, brand.getVisitCount()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_BR_VISIT_COUNT_FIELD, brand.getVisitCount(), Store.YES));
|
|
|
+ }
|
|
|
+ if (brand.getSearchCount() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_BR_SEARCH_COUNT_FIELD, brand.getSearchCount()));
|
|
|
+ document.add(new LongField(SearchConstants.GOODS_BR_SEARCH_COUNT_FIELD, brand.getSearchCount(), Store.YES));
|
|
|
+ }
|
|
|
+ if (brand.getWeight() != null) {
|
|
|
+ document.add(new DoubleDocValuesField(SearchConstants.GOODS_BR_WEIGHT_FIELD, brand.getWeight()));
|
|
|
+ document.add(new DoubleField(SearchConstants.GOODS_BR_WEIGHT_FIELD, brand.getWeight(), Store.YES));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(goods.getProducts() != null){
|