Authored by hugufei

Merge branch 'master' into dev

# Conflicts:
#	deploy/pom.xml
#	deploy/src/main/META-INF/autoconf/auto-config.xml
#	deploy/src/main/META-INF/autoconf/bin/env.bat
#	deploy/src/main/META-INF/autoconf/bin/env.sh
#	deploy/src/main/META-INF/autoconf/conf/jboss/application.xml
#	deploy/src/main/META-INF/autoconf/conf/tomcat/server.xml
#	deploy/src/main/application.xml
#	deploy/src/main/assembly/assembly.xml
#	deploy/src/main/bin/env.bat
#	deploy/src/main/bin/env.sh
#	deploy/src/main/bin/jbossctl-dev.bat
#	deploy/src/main/bin/tomcat-dev.bat
#	deploy/src/main/conf/tomcat/server.xml
#	pom.xml
#	service/pom.xml
#	service/src/main/java/com/yoho/search/restapi/BrandController.java
#	service/src/main/java/com/yoho/search/restapi/SearchController.java
#	service/src/main/java/com/yoho/search/restapi/TblProductController.java
#	service/src/main/java/com/yoho/search/service/BrandSearchService.java
#	service/src/main/java/com/yoho/search/service/SearchService.java
#	service/src/main/java/com/yoho/search/service/SearchSortSizeService.java
#	service/src/main/java/com/yoho/search/service/TblProductService.java
#	web/pom.xml
#	web/src/main/resources/META-INF/spring/spring-web-context.xml
#	web/src/main/resources/config.properties
#	web/src/main/resources/configuration.xml
#	web/src/main/resources/databases.yml
#	web/src/main/resources/logback.xml
#	web/src/main/webapp/META-INF/autoconf/auto-config.xml
#	web/src/main/webapp/META-INF/autoconf/config.properties
#	web/src/main/webapp/META-INF/autoconf/databases.yml
#	web/src/main/webapp/META-INF/autoconf/logback.xml
#	web/src/main/webapp/WEB-INF/web.xml
#	web/src/main/webapp/index.jsp
... ... @@ -2,15 +2,9 @@
<config>
<group>
<!--yoho-search-autoconfig-->
<property name="yoho.search.service.env.webapphome" defaultValue="/home/test/yoho-search-service/deploy" description="应用根目录"/>
<property name="yoho.search.service.env.serverport" defaultValue="7" description="应用端口"/>
<property name="yoho.search.service.env.webapphome" defaultValue="/home/master/yoho-search-service/deploy" description="应用根目录"/>
<property name="yoho.search.service.env.serverport" defaultValue="0" description="应用端口"/>
<property name="yoho.search.service.env.namespace" defaultValue="search-service" description="应用命名空间"/>
<property name="yoho.env.javahome" defaultValue="/usr/local/java" description="" />
<property name="yoho.env.productmode" defaultValue="TEST" description="" />
<property name="yoho.env.serverhome" defaultValue="/usr/local/tomcat" description="" />
<property name="yoho.env.servertype" defaultValue="tomcat" description="" />
</group>
<script>
<generate template="META-INF/autoconf/bin/env.sh" destfile="bin/env.sh"/>
... ...
... ... @@ -57,7 +57,7 @@ if [ $PRODUCTION_MODE = "PRODUCT" ]; then
if [ -n "$str" ]; then
let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`
if [ $memTotal -gt 10000 ];then
JAVA_MEM_OPTS=" -server -Xmx4000M -Xms4000M -Xmn600M -XX:PermSize=200M -XX:MaxPermSize=200M -Xss256K -XX:+DisableExplicitGC -XX:SurvivorRatio=1 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSClassUnloadingEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -Xloggc:$WEB_APP_HOME/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$WEB_APP_HOME/logs/heapdump.hprof "
JAVA_MEM_OPTS=" -server -Xmx2500M -Xms2500M -Xmn400M -XX:PermSize=200M -XX:MaxPermSize=200M -Xss256K -XX:+DisableExplicitGC -XX:SurvivorRatio=1 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSClassUnloadingEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -Xloggc:$WEB_APP_HOME/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$WEB_APP_HOME/logs/heapdump.hprof "
else
JAVA_MEM_OPTS=" -server -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=64m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
fi
... ...
set JAVA_MEM_OPT= -Xms1024m -Xmx1024m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true
set JAVA_HOME=/usr/local/java
set WEB_APP_HOME=/home/dev/yoho-search-service/deploy
set WEB_APP_HOME=/home/test/yoho-search-service/deploy
set CATALINA_HOME=/usr/local/tomcat
set CATALINA_BASE=/home/dev/yoho-search-service/deploy/tomcat_server
set CATALINA_BASE=/home/test/yoho-search/deploy/tomcat_server
rem set JAVA_DEBUG_OPT= -server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8082,server=y,suspend=n
... ...
... ... @@ -6,16 +6,15 @@ BASE_BIN_DIR=`dirname $0`
. $BASE_BIN_DIR/functions.sh
export JAVA_HOME=/usr/local/java
export WEB_APP_HOME=/home/dev/yoho-search-service/deploy
export WEB_APP_HOME=/home/master/yoho-search-service/deploy
export SERVER_PORT=0
export PRODUCTION_MODE="TEST"
export PRODUCTION_MODE="PRODUCT"
export SERVER_HOME=/usr/local/tomcat
export SERVER_TYPE=tomcat
export SERVER_NAMESPACE=yohosearch
export GW_URL=$Gateway_URL
export SERVER_BASE_DIR=" -Dcatalina.base=/home/dev/yoho-search-service/deploy/.tomcat "
export SERVER_BASE_DIR=" -Dcatalina.base=/home/master/yoho-search-service/deploy/.tomcat "
export NAMING_PORT=`expr 9000 + $SERVER_PORT`
export HTTP_SERVER_PORT=`expr 8080 + $SERVER_PORT`
... ...
... ... @@ -19,7 +19,7 @@
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8100" shutdown="SHUTDOWN">
<Server port="8107" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
... ... @@ -88,7 +88,7 @@
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8000" protocol="AJP/1.3" redirectPort="8443" />
<Connector port="8007" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
... ...
package com.yoho.search.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.index.Index;
import com.yoho.search.index.IndexClient;
import com.yoho.search.index.SearchCallback;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.utils.PriceRangeUtils;
/**
* Created by YOHO on 15-11-2.
*/
@Service
public class SearchBaseService {
@Autowired
private IndexService indexService;
/**
* 执行检索
*
* @param indexName
* @param searchParam
* @return SearchResult 返回检索结果
*/
public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
SearchResult searchResult = null;
Index firstIndex = indexService.getIndex(indexName);
if (firstIndex != null) {
searchResult = indexService.execute(new SearchCallback<SearchResult>() {
@Override
public SearchResult execute(IndexClient indexClient) {
return indexClient.search(indexName, searchParam);
}
}, firstIndex);
}
return searchResult;
}
// 构造通用的检索条件
public BoolFilterBuilder buildFilter(BoolFilterBuilder boolFilterBuilder, Map<String, String> paramMap) {
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("filter_")) {
key = entry.getKey();
field = key.substring(7, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.must(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.must(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("not_filter_")) {
key = entry.getKey();
field = key.substring(11, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.mustNot(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.mustNot(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("range_gte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gte(entry.getValue()));
} else if (entry.getKey().startsWith("range_lte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lte(entry.getValue()));
} else if (entry.getKey().startsWith("range_gt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gt(entry.getValue()));
} else if (entry.getKey().startsWith("range_lt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lt(entry.getValue()));
}
}
return boolFilterBuilder;
}
public List<AbstractAggregationBuilder> buildAggregations(Map<String, String> paramMap) {
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("agg_")) {
key = entry.getKey();
field = key.substring(4, key.length());
if ("goods_price".equals(field)) {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(10000).order(Terms.Order.term(true)));
} else {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(1000));
}
}
}
return list;
}
public List<Map<String, Object>> buildFilterResponseMap(MultiBucketsAggregation aggregation, String fieldName) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator();
while (itSizeAgg.hasNext()) {
MultiBucketsAggregation.Bucket lt = itSizeAgg.next();
map = new HashMap<String, Object>();
map.put(fieldName, lt.getKey());
list.add(map);
}
return list;
}
public Map<String, Object> getPriceResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> priceMap = new LinkedHashMap<String, Object>();
if (aggregation.getBuckets().isEmpty())
return priceMap;
Iterator<? extends MultiBucketsAggregation.Bucket> itPriceAgg = aggregation.getBuckets().iterator();
int size = aggregation.getBuckets().size();
float[] prePrice = new float[size];
int i = 0;
while (itPriceAgg.hasNext()) {
prePrice[i] = Float.parseFloat(itPriceAgg.next().getKey());
i++;
}
float maxPrice = prePrice[i - 1];
List<Integer> intervals = PriceRangeUtils.getPriceInterval(prePrice, maxPrice);
size = intervals.size();
int j = 0;
for (j = 0; j < size - 1; j++) {
if (j > 0) {
priceMap.put((intervals.get(j) + 1) + "," + intervals.get(j + 1), "¥" + (intervals.get(j) + 1) + "-" + intervals.get(j + 1));
} else {
priceMap.put(intervals.get(j) + "," + intervals.get(j + 1), "¥" + intervals.get(j) + "-" + intervals.get(j + 1));
}
}
priceMap.put((intervals.get(j) + 1) + ",99999", "¥" + intervals.get(j) + "以上");
return priceMap;
}
public Map<String, Object> getGenderResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> genderMap = new LinkedHashMap<String, Object>();
Iterator<? extends MultiBucketsAggregation.Bucket> itGenderAgg = aggregation.getBuckets().iterator();
while (itGenderAgg.hasNext()) {
MultiBucketsAggregation.Bucket ltGender = itGenderAgg.next();
String genderId = ltGender.getKey();
if ("1".equals(genderId)) {
genderMap.put("1,3", "BOYS");
} else if ("2".equals(genderId)) {
genderMap.put("2,3", "GIRLS");
} else {
genderMap.put("1,3", "BOYS");
genderMap.put("2,3", "GIRLS");
}
}
return genderMap;
}
}
... ...