Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
suggest-task
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
田川
suggest-task
Commits
c331db5d
Commit
c331db5d
authored
Feb 08, 2022
by
xupeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code
parent
e7fe5fd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
2 deletions
+160
-2
SuggestTask.java
suggest-task/src/main/java/com/secoo/so/suggest/task/SuggestTask.java
+3
-2
StringUtils.java
suggest-task/src/main/java/com/secoo/so/suggest/util/StringUtils.java
+157
-0
No files found.
suggest-task/src/main/java/com/secoo/so/suggest/task/SuggestTask.java
View file @
c331db5d
...
@@ -169,7 +169,7 @@ public class SuggestTask {
...
@@ -169,7 +169,7 @@ public class SuggestTask {
private
static
String
cleanKeyword
(
String
keyword
)
{
private
static
String
cleanKeyword
(
String
keyword
)
{
if
(
keyword
!=
null
)
{
if
(
keyword
!=
null
)
{
String
fixKeyword
=
PinYinUtils
.
convertToSimplifiedChinese
(
keyword
);
String
fixKeyword
=
PinYinUtils
.
convertToSimplifiedChinese
(
keyword
);
fixKeyword
=
StringUtils
.
dbc2Sbc
(
fixKeyword
).
replaceAll
(
"\ufffc|,|,|\\."
,
"
"
);
fixKeyword
=
StringUtils
.
strip
(
StringUtils
.
dbc2Sbc
(
fixKeyword
),
" \ufffc,,.。
"
);
fixKeyword
=
StringUtils
.
cleanMultiBlank
(
fixKeyword
);
fixKeyword
=
StringUtils
.
cleanMultiBlank
(
fixKeyword
);
return
fixKeyword
.
toLowerCase
();
return
fixKeyword
.
toLowerCase
();
}
}
...
@@ -307,8 +307,8 @@ public class SuggestTask {
...
@@ -307,8 +307,8 @@ public class SuggestTask {
* 保存到es
* 保存到es
*/
*/
private
static
void
saveSuggestKeywordToEs
(
List
<
EsSuggestKeywordInfo
>
suggestKeywordInfoList
)
{
private
static
void
saveSuggestKeywordToEs
(
List
<
EsSuggestKeywordInfo
>
suggestKeywordInfoList
)
{
log
.
info
(
"start saveSuggestKeywordToEs"
);
if
(
CollectionUtils
.
isNotEmpty
(
suggestKeywordInfoList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
suggestKeywordInfoList
))
{
String
esUrl
=
ConfigUtil
.
getString
(
"suggestTask.es.url"
);
String
esUrl
=
ConfigUtil
.
getString
(
"suggestTask.es.url"
);
String
esUser
=
ConfigUtil
.
getString
(
"suggestTask.es.user"
);
String
esUser
=
ConfigUtil
.
getString
(
"suggestTask.es.user"
);
String
esPassword
=
ConfigUtil
.
getString
(
"suggestTask.es.password"
);
String
esPassword
=
ConfigUtil
.
getString
(
"suggestTask.es.password"
);
...
@@ -339,6 +339,7 @@ public class SuggestTask {
...
@@ -339,6 +339,7 @@ public class SuggestTask {
}
}
private
static
void
saveSuggestKeywordToFile
(
List
<
EsSuggestKeywordInfo
>
suggestKeywordInfoList
)
{
private
static
void
saveSuggestKeywordToFile
(
List
<
EsSuggestKeywordInfo
>
suggestKeywordInfoList
)
{
log
.
info
(
"start saveSuggestKeywordToFile"
);
if
(
CollectionUtils
.
isNotEmpty
(
suggestKeywordInfoList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
suggestKeywordInfoList
))
{
int
batch
=
2000
;
int
batch
=
2000
;
...
...
suggest-task/src/main/java/com/secoo/so/suggest/util/StringUtils.java
View file @
c331db5d
...
@@ -31,6 +31,13 @@ public abstract class StringUtils {
...
@@ -31,6 +31,13 @@ public abstract class StringUtils {
private
static
final
char
EXTENSION_SEPARATOR
=
'.'
;
private
static
final
char
EXTENSION_SEPARATOR
=
'.'
;
/**
* Represents a failed index search.
*
* @since 2.1
*/
public
static
final
int
INDEX_NOT_FOUND
=
-
1
;
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// General convenience methods for working with Strings
// General convenience methods for working with Strings
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
...
@@ -1199,6 +1206,32 @@ public abstract class StringUtils {
...
@@ -1199,6 +1206,32 @@ public abstract class StringUtils {
return
temp
;
return
temp
;
}
}
// Empty checks
//-----------------------------------------------------------------------
/**
* <p>Checks if a CharSequence is empty ("") or null.</p>
*
* <pre>
* StringUtils.isEmpty(null) = true
* StringUtils.isEmpty("") = true
* StringUtils.isEmpty(" ") = false
* StringUtils.isEmpty("bob") = false
* StringUtils.isEmpty(" bob ") = false
* </pre>
*
* <p>NOTE: This method changed in Lang version 2.0.
* It no longer trims the CharSequence.
* That functionality is available in isBlank().</p>
*
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is empty or null
* @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
*/
public
static
boolean
isEmpty
(
final
CharSequence
cs
)
{
return
cs
==
null
||
cs
.
length
()
==
0
;
}
/**
/**
* @param s
* @param s
* @return 如果<tt>s</tt>为<tt>null</tt>或空白字符串返回<tt>true</tt>
* @return 如果<tt>s</tt>为<tt>null</tt>或空白字符串返回<tt>true</tt>
...
@@ -2101,4 +2134,128 @@ public abstract class StringUtils {
...
@@ -2101,4 +2134,128 @@ public abstract class StringUtils {
return
result
;
return
result
;
}
}
/**
* <p>Strips any of a set of characters from the start and end of a String.
* This is similar to {@link String#trim()} but allows the characters
* to be stripped to be controlled.</p>
*
* <p>A {@code null} input String returns {@code null}.
* An empty string ("") input returns the empty string.</p>
*
* <p>If the stripChars String is {@code null}, whitespace is
* stripped as defined by {@link Character#isWhitespace(char)}.
* Alternatively use {@link #strip(String)}.</p>
*
* <pre>
* StringUtils.strip(null, *) = null
* StringUtils.strip("", *) = ""
* StringUtils.strip("abc", null) = "abc"
* StringUtils.strip(" abc", null) = "abc"
* StringUtils.strip("abc ", null) = "abc"
* StringUtils.strip(" abc ", null) = "abc"
* StringUtils.strip(" abcyx", "xyz") = " abc"
* </pre>
*
* @param str the String to remove characters from, may be null
* @param stripChars the characters to remove, null treated as whitespace
* @return the stripped String, {@code null} if null String input
*/
public
static
String
strip
(
String
str
,
final
String
stripChars
)
{
if
(
isEmpty
(
str
))
{
return
str
;
}
str
=
stripStart
(
str
,
stripChars
);
return
stripEnd
(
str
,
stripChars
);
}
/**
* <p>Strips any of a set of characters from the start of a String.</p>
*
* <p>A {@code null} input String returns {@code null}.
* An empty string ("") input returns the empty string.</p>
*
* <p>If the stripChars String is {@code null}, whitespace is
* stripped as defined by {@link Character#isWhitespace(char)}.</p>
*
* <pre>
* StringUtils.stripStart(null, *) = null
* StringUtils.stripStart("", *) = ""
* StringUtils.stripStart("abc", "") = "abc"
* StringUtils.stripStart("abc", null) = "abc"
* StringUtils.stripStart(" abc", null) = "abc"
* StringUtils.stripStart("abc ", null) = "abc "
* StringUtils.stripStart(" abc ", null) = "abc "
* StringUtils.stripStart("yxabc ", "xyz") = "abc "
* </pre>
*
* @param str the String to remove characters from, may be null
* @param stripChars the characters to remove, null treated as whitespace
* @return the stripped String, {@code null} if null String input
*/
public
static
String
stripStart
(
final
String
str
,
final
String
stripChars
)
{
int
strLen
;
if
(
str
==
null
||
(
strLen
=
str
.
length
())
==
0
)
{
return
str
;
}
int
start
=
0
;
if
(
stripChars
==
null
)
{
while
(
start
!=
strLen
&&
Character
.
isWhitespace
(
str
.
charAt
(
start
)))
{
start
++;
}
}
else
if
(
stripChars
.
isEmpty
())
{
return
str
;
}
else
{
while
(
start
!=
strLen
&&
stripChars
.
indexOf
(
str
.
charAt
(
start
))
!=
INDEX_NOT_FOUND
)
{
start
++;
}
}
return
str
.
substring
(
start
);
}
/**
* <p>Strips any of a set of characters from the end of a String.</p>
*
* <p>A {@code null} input String returns {@code null}.
* An empty string ("") input returns the empty string.</p>
*
* <p>If the stripChars String is {@code null}, whitespace is
* stripped as defined by {@link Character#isWhitespace(char)}.</p>
*
* <pre>
* StringUtils.stripEnd(null, *) = null
* StringUtils.stripEnd("", *) = ""
* StringUtils.stripEnd("abc", "") = "abc"
* StringUtils.stripEnd("abc", null) = "abc"
* StringUtils.stripEnd(" abc", null) = " abc"
* StringUtils.stripEnd("abc ", null) = "abc"
* StringUtils.stripEnd(" abc ", null) = " abc"
* StringUtils.stripEnd(" abcyx", "xyz") = " abc"
* StringUtils.stripEnd("120.00", ".0") = "12"
* </pre>
*
* @param str the String to remove characters from, may be null
* @param stripChars the set of characters to remove, null treated as whitespace
* @return the stripped String, {@code null} if null String input
*/
public
static
String
stripEnd
(
final
String
str
,
final
String
stripChars
)
{
int
end
;
if
(
str
==
null
||
(
end
=
str
.
length
())
==
0
)
{
return
str
;
}
if
(
stripChars
==
null
)
{
while
(
end
!=
0
&&
Character
.
isWhitespace
(
str
.
charAt
(
end
-
1
)))
{
end
--;
}
}
else
if
(
stripChars
.
isEmpty
())
{
return
str
;
}
else
{
while
(
end
!=
0
&&
stripChars
.
indexOf
(
str
.
charAt
(
end
-
1
))
!=
INDEX_NOT_FOUND
)
{
end
--;
}
}
return
str
.
substring
(
0
,
end
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment