初始项目
This commit is contained in:
25
mallplus-search/.gitignore
vendored
Normal file
25
mallplus-search/.gitignore
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/build/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
BIN
mallplus-search/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
mallplus-search/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
1
mallplus-search/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
1
mallplus-search/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1 @@
|
||||
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
|
||||
225
mallplus-search/mvnw
vendored
Normal file
225
mallplus-search/mvnw
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Maven2 Start Up Batch script
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# JAVA_HOME - location of a JDK home dir
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# M2_HOME - location of maven2's installed home dir
|
||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
# e.g. to debug Maven itself, use
|
||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||
|
||||
if [ -f /etc/mavenrc ] ; then
|
||||
. /etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.mavenrc" ] ; then
|
||||
. "$HOME/.mavenrc"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false;
|
||||
darwin=false;
|
||||
mingw=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true ;;
|
||||
MINGW*) mingw=true;;
|
||||
Darwin*) darwin=true
|
||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if [ -x "/usr/libexec/java_home" ]; then
|
||||
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||
else
|
||||
export JAVA_HOME="/Library/Java/Home"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
if [ -r /etc/gentoo-release ] ; then
|
||||
JAVA_HOME=`java-config --jre-home`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$M2_HOME" ] ; then
|
||||
## resolve links - $0 may be a link to maven's home
|
||||
PRG="$0"
|
||||
|
||||
# need this for relative symlinks
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG="`dirname "$PRG"`/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
saveddir=`pwd`
|
||||
|
||||
M2_HOME=`dirname "$PRG"`/..
|
||||
|
||||
# make it fully qualified
|
||||
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||
|
||||
cd "$saveddir"
|
||||
# echo Using m2 at $M2_HOME
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# For Migwn, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||
# TODO classpath?
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
javaExecutable="`which javac`"
|
||||
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||
# readlink(1) is not available as standard on Solaris 10.
|
||||
readLink=`which readlink`
|
||||
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||
if $darwin ; then
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||
else
|
||||
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||
fi
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||
JAVA_HOME="$javaHome"
|
||||
export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$JAVACMD" ] ; then
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
else
|
||||
JAVACMD="`which java`"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||
echo " We cannot execute $JAVACMD" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
echo "Warning: JAVA_HOME environment variable is not set."
|
||||
fi
|
||||
|
||||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Path not specified to find_maven_basedir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
basedir="$1"
|
||||
wdir="$1"
|
||||
while [ "$wdir" != '/' ] ; do
|
||||
if [ -d "$wdir"/.mvn ] ; then
|
||||
basedir=$wdir
|
||||
break
|
||||
fi
|
||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||
if [ -d "${wdir}" ]; then
|
||||
wdir=`cd "$wdir/.."; pwd`
|
||||
fi
|
||||
# end of workaround
|
||||
done
|
||||
echo "${basedir}"
|
||||
}
|
||||
|
||||
# concatenates all lines of a file
|
||||
concat_lines() {
|
||||
if [ -f "$1" ]; then
|
||||
echo "$(tr -s '\n' ' ' < "$1")"
|
||||
fi
|
||||
}
|
||||
|
||||
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||
if [ -z "$BASE_DIR" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||
echo $MAVEN_PROJECTBASEDIR
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||
fi
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
143
mallplus-search/mvnw.cmd
vendored
Normal file
143
mallplus-search/mvnw.cmd
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Maven2 Start Up Batch script
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM M2_HOME - location of maven2's installed home dir
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||
|
||||
exit /B %ERROR_CODE%
|
||||
109
mallplus-search/pom.xml
Normal file
109
mallplus-search/pom.xml
Normal file
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.zscat.mallplus</groupId>
|
||||
<artifactId>mallplus-search</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>mallplus-search</name>
|
||||
<description>mallplus-search project for mall</description>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<skipTests>true</skipTests>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>aliyun</id>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aliyun_thirdparty</id>
|
||||
<url>http://maven.aliyun.com/nexus/content/repositories/thirdparty/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<url>http://repo.spring.io/libs-snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>aliyun</id>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<url>http://repo.spring.io/libs-snapshot</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zscat.mallplus</groupId>
|
||||
<artifactId>mallplus-mbg</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>com.spotify</groupId>-->
|
||||
<!--<artifactId>docker-maven-plugin</artifactId>-->
|
||||
<!--<version>1.1.0</version>-->
|
||||
<!--<executions>-->
|
||||
<!--<execution>-->
|
||||
<!--<id>build-image</id>-->
|
||||
<!--<phase>package</phase>-->
|
||||
<!--<goals>-->
|
||||
<!--<goal>build</goal>-->
|
||||
<!--</goals>-->
|
||||
<!--</execution>-->
|
||||
<!--</executions>-->
|
||||
<!--<configuration>-->
|
||||
<!--<imageName>mall/${project.artifactId}:${project.version}</imageName>-->
|
||||
<!--<dockerHost>http://192.168.3.101:2375</dockerHost>-->
|
||||
<!--<baseImage>java:8</baseImage>-->
|
||||
<!--<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>-->
|
||||
<!--<resources>-->
|
||||
<!--<resource>-->
|
||||
<!--<targetPath>/</targetPath>-->
|
||||
<!--<directory>${project.build.directory}</directory>-->
|
||||
<!--<include>${project.build.finalName}.jar</include>-->
|
||||
<!--</resource>-->
|
||||
<!--</resources>-->
|
||||
<!--</configuration>-->
|
||||
<!--</plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.zscat.mallplus;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MallSearchApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MallSearchApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.zscat.mallplus.search.config;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* MyBatis配置类
|
||||
* Created by mallplus on 2019/4/8.
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan({"com.zscat.mallplus.search.mapper", "com.zscat.mallplus.search.dao"})
|
||||
public class MyBatisConfig {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.zscat.mallplus.search.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* Swagger2API文档的配置
|
||||
* Created by mallplus on 2018/4/26.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.zscat.mallplus.search.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("mall搜索系统")
|
||||
.description("mall搜索模块")
|
||||
.contact("mallplus")
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.zscat.mallplus.search.controller;
|
||||
|
||||
|
||||
import com.zscat.mallplus.search.domain.EsProduct;
|
||||
import com.zscat.mallplus.search.domain.EsProductRelatedInfo;
|
||||
import com.zscat.mallplus.search.service.EsProductService;
|
||||
import com.zscat.mallplus.utils.CommonResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索商品管理Controller
|
||||
* Created by mallplus on 2018/6/19.
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "EsProductController", description = "搜索商品管理")
|
||||
@RequestMapping("/esProduct")
|
||||
public class EsProductController {
|
||||
@Autowired
|
||||
private EsProductService esProductService;
|
||||
|
||||
@ApiOperation(value = "导入所有数据库中商品到ES")
|
||||
@RequestMapping(value = "/importAll", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object importAllList() {
|
||||
int count = esProductService.importAll();
|
||||
return new CommonResult().success(count);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id删除商品")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object delete(@PathVariable Long id) {
|
||||
esProductService.delete(id);
|
||||
return new CommonResult().success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id批量删除商品")
|
||||
@RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object delete(@RequestParam("ids") List<Long> ids) {
|
||||
esProductService.delete(ids);
|
||||
return new CommonResult().success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据id创建商品")
|
||||
@RequestMapping(value = "/create/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object create(@PathVariable Long id) {
|
||||
EsProduct esProduct = esProductService.create(id);
|
||||
if (esProduct != null) {
|
||||
return new CommonResult().success(esProduct);
|
||||
} else {
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "简单搜索")
|
||||
@RequestMapping(value = "/search/simple", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object search(@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
|
||||
Page<EsProduct> esProductPage = esProductService.search(keyword, pageNum, pageSize);
|
||||
return new CommonResult().success(esProductPage);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "综合搜索、筛选、排序")
|
||||
@ApiImplicitParam(name = "sort", value = "排序字段:0->按相关度;1->按新品;2->按销量;3->价格从低到高;4->价格从高到低",
|
||||
defaultValue = "0", allowableValues = "0,1,2,3,4", paramType = "query", dataType = "integer")
|
||||
@RequestMapping(value = "/search", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object search(@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Long brandId,
|
||||
@RequestParam(required = false) Long productCategoryId,
|
||||
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false, defaultValue = "0") Integer sort) {
|
||||
Page<EsProduct> esProductPage = esProductService.search(keyword, brandId, productCategoryId, pageNum, pageSize, sort);
|
||||
return new CommonResult().success(esProductPage);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据商品id推荐商品")
|
||||
@RequestMapping(value = "/recommend/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object recommend(@PathVariable Long id,
|
||||
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
|
||||
Page<EsProduct> esProductPage = esProductService.recommend(id, pageNum, pageSize);
|
||||
return new CommonResult().success(esProductPage);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取搜索的相关品牌、分类及筛选属性")
|
||||
@RequestMapping(value = "/search/relate", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object searchRelatedInfo(@RequestParam(required = false) String keyword) {
|
||||
EsProductRelatedInfo productRelatedInfo = esProductService.searchRelatedInfo(keyword);
|
||||
return new CommonResult().success(productRelatedInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.zscat.mallplus.search.dao;
|
||||
|
||||
import com.zscat.mallplus.search.domain.EsProduct;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索系统中的商品管理自定义Dao
|
||||
* Created by mallplus on 2018/6/19.
|
||||
*/
|
||||
public interface EsProductDao {
|
||||
List<EsProduct> getAllEsProductList(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.zscat.mallplus.search.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索中的商品信息
|
||||
* Created by mallplus on 2018/6/19.
|
||||
*/
|
||||
@Document(indexName = "pms", type = "product", shards = 1, replicas = 0)
|
||||
public class EsProduct implements Serializable {
|
||||
private static final long serialVersionUID = -1L;
|
||||
@Id
|
||||
private Long id;
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String productSn;
|
||||
private Long brandId;
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String brandName;
|
||||
private Long productCategoryId;
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String productCategoryName;
|
||||
private String pic;
|
||||
@Field(analyzer = "ik_max_word", type = FieldType.Text)
|
||||
private String name;
|
||||
@Field(analyzer = "ik_max_word", type = FieldType.Text)
|
||||
private String subTitle;
|
||||
@Field(analyzer = "ik_max_word", type = FieldType.Text)
|
||||
private String keywords;
|
||||
private BigDecimal price;
|
||||
private Integer sale;
|
||||
private Integer newStatus;
|
||||
private Integer recommandStatus;
|
||||
private Integer stock;
|
||||
private Integer promotionType;
|
||||
private Integer sort;
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<EsProductAttributeValue> attrValueList;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getProductSn() {
|
||||
return productSn;
|
||||
}
|
||||
|
||||
public void setProductSn(String productSn) {
|
||||
this.productSn = productSn;
|
||||
}
|
||||
|
||||
public Long getBrandId() {
|
||||
return brandId;
|
||||
}
|
||||
|
||||
public void setBrandId(Long brandId) {
|
||||
this.brandId = brandId;
|
||||
}
|
||||
|
||||
public String getBrandName() {
|
||||
return brandName;
|
||||
}
|
||||
|
||||
public void setBrandName(String brandName) {
|
||||
this.brandName = brandName;
|
||||
}
|
||||
|
||||
public Long getProductCategoryId() {
|
||||
return productCategoryId;
|
||||
}
|
||||
|
||||
public void setProductCategoryId(Long productCategoryId) {
|
||||
this.productCategoryId = productCategoryId;
|
||||
}
|
||||
|
||||
public String getProductCategoryName() {
|
||||
return productCategoryName;
|
||||
}
|
||||
|
||||
public void setProductCategoryName(String productCategoryName) {
|
||||
this.productCategoryName = productCategoryName;
|
||||
}
|
||||
|
||||
public String getPic() {
|
||||
return pic;
|
||||
}
|
||||
|
||||
public void setPic(String pic) {
|
||||
this.pic = pic;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSubTitle() {
|
||||
return subTitle;
|
||||
}
|
||||
|
||||
public void setSubTitle(String subTitle) {
|
||||
this.subTitle = subTitle;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Integer getSale() {
|
||||
return sale;
|
||||
}
|
||||
|
||||
public void setSale(Integer sale) {
|
||||
this.sale = sale;
|
||||
}
|
||||
|
||||
public Integer getNewStatus() {
|
||||
return newStatus;
|
||||
}
|
||||
|
||||
public void setNewStatus(Integer newStatus) {
|
||||
this.newStatus = newStatus;
|
||||
}
|
||||
|
||||
public Integer getRecommandStatus() {
|
||||
return recommandStatus;
|
||||
}
|
||||
|
||||
public void setRecommandStatus(Integer recommandStatus) {
|
||||
this.recommandStatus = recommandStatus;
|
||||
}
|
||||
|
||||
public Integer getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public void setStock(Integer stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
public Integer getPromotionType() {
|
||||
return promotionType;
|
||||
}
|
||||
|
||||
public void setPromotionType(Integer promotionType) {
|
||||
this.promotionType = promotionType;
|
||||
}
|
||||
|
||||
public Integer getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public List<EsProductAttributeValue> getAttrValueList() {
|
||||
return attrValueList;
|
||||
}
|
||||
|
||||
public void setAttrValueList(List<EsProductAttributeValue> attrValueList) {
|
||||
this.attrValueList = attrValueList;
|
||||
}
|
||||
|
||||
public String getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public void setKeywords(String keywords) {
|
||||
this.keywords = keywords;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.zscat.mallplus.search.domain;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 搜索中的商品属性信息
|
||||
* Created by mallplus on 2018/6/27.
|
||||
*/
|
||||
public class EsProductAttributeValue implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Long id;
|
||||
private Long productAttributeId;
|
||||
//属性值
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String value;
|
||||
//属性参数:0->规格;1->参数
|
||||
private Integer type;
|
||||
//属性名称
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getProductAttributeId() {
|
||||
return productAttributeId;
|
||||
}
|
||||
|
||||
public void setProductAttributeId(Long productAttributeId) {
|
||||
this.productAttributeId = productAttributeId;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.zscat.mallplus.search.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索相关商品品牌名称,分类名称及属性
|
||||
* Created by mallplus on 2018/6/27.
|
||||
*/
|
||||
public class EsProductRelatedInfo {
|
||||
private List<String> brandNames;
|
||||
private List<String> productCategoryNames;
|
||||
private List<ProductAttr> productAttrs;
|
||||
|
||||
public List<String> getBrandNames() {
|
||||
return brandNames;
|
||||
}
|
||||
|
||||
public void setBrandNames(List<String> brandNames) {
|
||||
this.brandNames = brandNames;
|
||||
}
|
||||
|
||||
public List<String> getProductCategoryNames() {
|
||||
return productCategoryNames;
|
||||
}
|
||||
|
||||
public void setProductCategoryNames(List<String> productCategoryNames) {
|
||||
this.productCategoryNames = productCategoryNames;
|
||||
}
|
||||
|
||||
public List<ProductAttr> getProductAttrs() {
|
||||
return productAttrs;
|
||||
}
|
||||
|
||||
public void setProductAttrs(List<ProductAttr> productAttrs) {
|
||||
this.productAttrs = productAttrs;
|
||||
}
|
||||
|
||||
public static class ProductAttr {
|
||||
private Long attrId;
|
||||
private String attrName;
|
||||
private List<String> attrValues;
|
||||
|
||||
public Long getAttrId() {
|
||||
return attrId;
|
||||
}
|
||||
|
||||
public void setAttrId(Long attrId) {
|
||||
this.attrId = attrId;
|
||||
}
|
||||
|
||||
public List<String> getAttrValues() {
|
||||
return attrValues;
|
||||
}
|
||||
|
||||
public void setAttrValues(List<String> attrValues) {
|
||||
this.attrValues = attrValues;
|
||||
}
|
||||
|
||||
public String getAttrName() {
|
||||
return attrName;
|
||||
}
|
||||
|
||||
public void setAttrName(String attrName) {
|
||||
this.attrName = attrName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zscat.mallplus.search.repository;
|
||||
|
||||
import com.zscat.mallplus.search.domain.EsProduct;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* 商品ES操作类
|
||||
* Created by mallplus on 2018/6/19.
|
||||
*/
|
||||
public interface EsProductRepository extends ElasticsearchRepository<EsProduct, Long> {
|
||||
/**
|
||||
* 搜索查询
|
||||
*
|
||||
* @param name 商品名称
|
||||
* @param subTitle 商品标题
|
||||
* @param keywords 商品关键字
|
||||
* @param page 分页信息
|
||||
* @return
|
||||
*/
|
||||
Page<EsProduct> findByNameOrSubTitleOrKeywords(String name, String subTitle, String keywords, Pageable page);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.zscat.mallplus.search.service;
|
||||
|
||||
import com.zscat.mallplus.search.domain.EsProduct;
|
||||
import com.zscat.mallplus.search.domain.EsProductRelatedInfo;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品搜索管理Service
|
||||
* Created by mallplus on 2018/6/19.
|
||||
*/
|
||||
public interface EsProductService {
|
||||
/**
|
||||
* 从数据库中导入所有商品到ES
|
||||
*/
|
||||
int importAll();
|
||||
|
||||
/**
|
||||
* 根据id删除商品
|
||||
*/
|
||||
void delete(Long id);
|
||||
|
||||
/**
|
||||
* 根据id创建商品
|
||||
*/
|
||||
EsProduct create(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除商品
|
||||
*/
|
||||
void delete(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据关键字搜索名称或者副标题
|
||||
*/
|
||||
Page<EsProduct> search(String keyword, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 根据关键字搜索名称或者副标题复合查询
|
||||
*/
|
||||
Page<EsProduct> search(String keyword, Long brandId, Long productCategoryId, Integer pageNum, Integer pageSize, Integer sort);
|
||||
|
||||
/**
|
||||
* 根据商品id推荐相关商品
|
||||
*/
|
||||
Page<EsProduct> recommend(Long id, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 获取搜索词相关品牌、分类、属性
|
||||
*/
|
||||
EsProductRelatedInfo searchRelatedInfo(String keyword);
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
package com.zscat.mallplus.search.service.impl;
|
||||
|
||||
import com.zscat.mallplus.search.dao.EsProductDao;
|
||||
import com.zscat.mallplus.search.domain.EsProduct;
|
||||
import com.zscat.mallplus.search.domain.EsProductRelatedInfo;
|
||||
import com.zscat.mallplus.search.repository.EsProductRepository;
|
||||
import com.zscat.mallplus.search.service.EsProductService;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
|
||||
import org.elasticsearch.search.aggregations.bucket.nested.InternalNested;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 商品搜索管理Service实现类
|
||||
* Created by mallplus on 2018/6/19.
|
||||
*/
|
||||
@Service
|
||||
public class EsProductServiceImpl implements EsProductService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EsProductServiceImpl.class);
|
||||
@Autowired
|
||||
private EsProductDao productDao;
|
||||
@Autowired
|
||||
private EsProductRepository productRepository;
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Override
|
||||
public int importAll() {
|
||||
List<EsProduct> esProductList = productDao.getAllEsProductList(null);
|
||||
Iterable<EsProduct> esProductIterable = productRepository.saveAll(esProductList);
|
||||
Iterator<EsProduct> iterator = esProductIterable.iterator();
|
||||
int result = 0;
|
||||
while (iterator.hasNext()) {
|
||||
result++;
|
||||
iterator.next();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
productRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EsProduct create(Long id) {
|
||||
EsProduct result = null;
|
||||
List<EsProduct> esProductList = productDao.getAllEsProductList(id);
|
||||
if (esProductList.size() > 0) {
|
||||
EsProduct esProduct = esProductList.get(0);
|
||||
result = productRepository.save(esProduct);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(List<Long> ids) {
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
List<EsProduct> esProductList = new ArrayList<EsProduct>();
|
||||
for (Long id : ids) {
|
||||
EsProduct esProduct = new EsProduct();
|
||||
esProduct.setId(id);
|
||||
esProductList.add(esProduct);
|
||||
}
|
||||
productRepository.deleteAll(esProductList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EsProduct> search(String keyword, Integer pageNum, Integer pageSize) {
|
||||
Pageable pageable = PageRequest.of(pageNum, pageSize);
|
||||
return productRepository.findByNameOrSubTitleOrKeywords(keyword, keyword, keyword, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EsProduct> search(String keyword, Long brandId, Long productCategoryId, Integer pageNum, Integer pageSize, Integer sort) {
|
||||
Pageable pageable = PageRequest.of(pageNum, pageSize);
|
||||
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
|
||||
//分页
|
||||
nativeSearchQueryBuilder.withPageable(pageable);
|
||||
//过滤
|
||||
if (brandId != null || productCategoryId != null) {
|
||||
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
||||
if (brandId != null) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery("brandId", brandId));
|
||||
}
|
||||
if (productCategoryId != null) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery("productCategoryId", productCategoryId));
|
||||
}
|
||||
nativeSearchQueryBuilder.withFilter(boolQueryBuilder);
|
||||
}
|
||||
//搜索
|
||||
if (StringUtils.isEmpty(keyword)) {
|
||||
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
|
||||
} else {
|
||||
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("name", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(10)));
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("subTitle", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(5)));
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(2)));
|
||||
FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
|
||||
filterFunctionBuilders.toArray(builders);
|
||||
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
|
||||
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
|
||||
.setMinScore(2);
|
||||
nativeSearchQueryBuilder.withQuery(functionScoreQueryBuilder);
|
||||
}
|
||||
//排序
|
||||
if (sort == 1) {
|
||||
//按新品从新到旧
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("id").order(SortOrder.DESC));
|
||||
} else if (sort == 2) {
|
||||
//按销量从高到低
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("sale").order(SortOrder.DESC));
|
||||
} else if (sort == 3) {
|
||||
//按价格从低到高
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.ASC));
|
||||
} else if (sort == 4) {
|
||||
//按价格从高到低
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.DESC));
|
||||
} else {
|
||||
//按相关度
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC));
|
||||
}
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC));
|
||||
NativeSearchQuery searchQuery = nativeSearchQueryBuilder.build();
|
||||
LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
|
||||
return productRepository.search(searchQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EsProduct> recommend(Long id, Integer pageNum, Integer pageSize) {
|
||||
Pageable pageable = PageRequest.of(pageNum, pageSize);
|
||||
List<EsProduct> esProductList = productDao.getAllEsProductList(id);
|
||||
if (esProductList.size() > 0) {
|
||||
EsProduct esProduct = esProductList.get(0);
|
||||
String keyword = esProduct.getName();
|
||||
Long brandId = esProduct.getBrandId();
|
||||
Long productCategoryId = esProduct.getProductCategoryId();
|
||||
//根据商品标题、品牌、分类进行搜索
|
||||
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("name", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(8)));
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("subTitle", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(2)));
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(2)));
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("brandId", brandId),
|
||||
ScoreFunctionBuilders.weightFactorFunction(10)));
|
||||
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("productCategoryId", productCategoryId),
|
||||
ScoreFunctionBuilders.weightFactorFunction(6)));
|
||||
FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
|
||||
filterFunctionBuilders.toArray(builders);
|
||||
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
|
||||
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
|
||||
.setMinScore(2);
|
||||
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
|
||||
builder.withQuery(functionScoreQueryBuilder);
|
||||
builder.withPageable(pageable);
|
||||
NativeSearchQuery searchQuery = builder.build();
|
||||
LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
|
||||
return productRepository.search(searchQuery);
|
||||
}
|
||||
return new PageImpl<>(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EsProductRelatedInfo searchRelatedInfo(String keyword) {
|
||||
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
|
||||
//搜索条件
|
||||
if (StringUtils.isEmpty(keyword)) {
|
||||
builder.withQuery(QueryBuilders.matchAllQuery());
|
||||
} else {
|
||||
builder.withQuery(QueryBuilders.multiMatchQuery(keyword, "name", "subTitle", "keywords"));
|
||||
}
|
||||
//聚合搜索品牌名称
|
||||
builder.addAggregation(AggregationBuilders.terms("brandNames").field("brandName"));
|
||||
//集合搜索分类名称
|
||||
builder.addAggregation(AggregationBuilders.terms("productCategoryNames").field("productCategoryName"));
|
||||
//聚合搜索商品属性,去除type=1的属性
|
||||
AbstractAggregationBuilder aggregationBuilder = AggregationBuilders.nested("allAttrValues", "attrValueList")
|
||||
.subAggregation(AggregationBuilders.filter("productAttrs", QueryBuilders.termQuery("attrValueList.type", 1))
|
||||
.subAggregation(AggregationBuilders.terms("attrIds")
|
||||
.field("attrValueList.productAttributeId")
|
||||
.subAggregation(AggregationBuilders.terms("attrValues")
|
||||
.field("attrValueList.value"))
|
||||
.subAggregation(AggregationBuilders.terms("attrNames")
|
||||
.field("attrValueList.name"))));
|
||||
builder.addAggregation(aggregationBuilder);
|
||||
NativeSearchQuery searchQuery = builder.build();
|
||||
return elasticsearchTemplate.query(searchQuery, response -> {
|
||||
LOGGER.info("DSL:{}", searchQuery.getQuery().toString());
|
||||
return convertProductRelatedInfo(response);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将返回结果转换为对象
|
||||
*/
|
||||
private EsProductRelatedInfo convertProductRelatedInfo(SearchResponse response) {
|
||||
EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
|
||||
Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap();
|
||||
//设置品牌
|
||||
Aggregation brandNames = aggregationMap.get("brandNames");
|
||||
List<String> brandNameList = new ArrayList<>();
|
||||
for (int i = 0; i < ((Terms) brandNames).getBuckets().size(); i++) {
|
||||
brandNameList.add(((Terms) brandNames).getBuckets().get(i).getKeyAsString());
|
||||
}
|
||||
productRelatedInfo.setBrandNames(brandNameList);
|
||||
//设置分类
|
||||
Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
|
||||
List<String> productCategoryNameList = new ArrayList<>();
|
||||
for (int i = 0; i < ((Terms) productCategoryNames).getBuckets().size(); i++) {
|
||||
productCategoryNameList.add(((Terms) productCategoryNames).getBuckets().get(i).getKeyAsString());
|
||||
}
|
||||
productRelatedInfo.setProductCategoryNames(productCategoryNameList);
|
||||
//设置参数
|
||||
Aggregation productAttrs = aggregationMap.get("allAttrValues");
|
||||
List<LongTerms.Bucket> attrIds = ((LongTerms) ((InternalFilter) ((InternalNested) productAttrs).getProperty("productAttrs")).getProperty("attrIds")).getBuckets();
|
||||
List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
|
||||
for (Terms.Bucket attrId : attrIds) {
|
||||
EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
|
||||
attr.setAttrId((Long) attrId.getKey());
|
||||
List<String> attrValueList = new ArrayList<>();
|
||||
List<StringTerms.Bucket> attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
|
||||
List<StringTerms.Bucket> attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
|
||||
for (Terms.Bucket attrValue : attrValues) {
|
||||
attrValueList.add(attrValue.getKeyAsString());
|
||||
}
|
||||
attr.setAttrValues(attrValueList);
|
||||
if (!CollectionUtils.isEmpty(attrNames)) {
|
||||
String attrName = attrNames.get(0).getKeyAsString();
|
||||
attr.setAttrName(attrName);
|
||||
}
|
||||
attrList.add(attr);
|
||||
}
|
||||
productRelatedInfo.setProductAttrs(attrList);
|
||||
return productRelatedInfo;
|
||||
}
|
||||
}
|
||||
19
mallplus-search/src/main/resources/application-dev.yml
Normal file
19
mallplus-search/src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/mallplus1?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
druid:
|
||||
initial-size: 5 #连接池初始化大小
|
||||
min-idle: 10 #最小空闲连接数
|
||||
max-active: 20 #最大连接数
|
||||
web-stat-filter:
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据
|
||||
stat-view-servlet: #访问监控网页的登录用户名和密码
|
||||
login-username: druid
|
||||
login-password: druid
|
||||
data:
|
||||
elasticsearch:
|
||||
repositories:
|
||||
enabled: true
|
||||
cluster-nodes: 127.0.0.1:9300
|
||||
19
mallplus-search/src/main/resources/application-prod.yml
Normal file
19
mallplus-search/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/mallplus1?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
druid:
|
||||
initial-size: 5 #连接池初始化大小
|
||||
min-idle: 10 #最小空闲连接数
|
||||
max-active: 20 #最大连接数
|
||||
web-stat-filter:
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据
|
||||
stat-view-servlet: #访问监控网页的登录用户名和密码
|
||||
login-username: druid
|
||||
login-password: druid
|
||||
data:
|
||||
elasticsearch:
|
||||
repositories:
|
||||
enabled: true
|
||||
cluster-nodes: 127.0.0.1:9300
|
||||
29
mallplus-search/src/main/resources/application.yml
Normal file
29
mallplus-search/src/main/resources/application.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev #默认为开发环境
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
cache-enabled: false
|
||||
map-underscore-to-camel-case: true
|
||||
global-config:
|
||||
db-config:
|
||||
column-underline: true
|
||||
db-type: mysql
|
||||
field-strategy: not_empty
|
||||
id-type: id_worker
|
||||
logic-delete-value: 0
|
||||
logic-not-delete-value: 1
|
||||
refresh: true
|
||||
mapper-locations: classpath:dao/*.xml
|
||||
typeAliasesPackage: com.zscat.mallplus.*.domain
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
com.mallplus: debug
|
||||
|
||||
|
||||
|
||||
47
mallplus-search/src/main/resources/dao/EsProductDao.xml
Normal file
47
mallplus-search/src/main/resources/dao/EsProductDao.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zscat.mallplus.search.dao.EsProductDao">
|
||||
<resultMap id="esProductListMap" type="com.zscat.mallplus.search.domain.EsProduct" autoMapping="true">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<collection property="attrValueList" columnPrefix="attr_"
|
||||
ofType="com.zscat.mallplus.search.domain.EsProductAttributeValue">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="product_attribute_id" property="productAttributeId" jdbcType="BIGINT"/>
|
||||
<result column="value" property="value" jdbcType="VARCHAR"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="name" property="name"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="getAllEsProductList" resultMap="esProductListMap">
|
||||
select
|
||||
p.id id,
|
||||
p.product_sn productSn,
|
||||
p.brand_id brandId,
|
||||
p.brand_name brandName,
|
||||
p.product_category_id productCategoryId,
|
||||
p.product_category_name productCategoryName,
|
||||
p.pic pic,
|
||||
p.name name,
|
||||
p.sub_title subTitle,
|
||||
p.price price,
|
||||
p.sale sale,
|
||||
p.new_status newStatus,
|
||||
p.recommand_status recommandStatus,
|
||||
p.stock stock,
|
||||
p.promotion_type promotionType,
|
||||
p.keywords keywords,
|
||||
p.sort sort,
|
||||
pav.id attr_id,
|
||||
pav.value attr_value,
|
||||
pav.product_attribute_id attr_product_attribute_id,
|
||||
pa.type attr_type,
|
||||
pa.name attr_name
|
||||
from pms_product p
|
||||
left join pms_product_attribute_value pav on p.id = pav.product_id
|
||||
left join pms_product_attribute pa on pav.product_attribute_id= pa.id
|
||||
where delete_status = 0 and publish_status = 1
|
||||
<if test="id!=null">
|
||||
and p.id=#{id}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.zscat.mallplus.search;
|
||||
|
||||
import com.zscat.mallplus.search.dao.EsProductDao;
|
||||
import com.zscat.mallplus.search.domain.EsProduct;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class MallSearchApplicationTests {
|
||||
@Autowired
|
||||
private EsProductDao productDao;
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllEsProductList() {
|
||||
List<EsProduct> esProductList = productDao.getAllEsProductList(null);
|
||||
System.out.print(esProductList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEsProductMapping() {
|
||||
elasticsearchTemplate.putMapping(EsProduct.class);
|
||||
Map mapping = elasticsearchTemplate.getMapping(EsProduct.class);
|
||||
System.out.println(mapping);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user