Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
search
Project
Project
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
曲欣亮
search
Commits
d9001c21
Commit
d9001c21
authored
Jul 11, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
42ebb51a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
38 deletions
+42
-38
pom.xml
pom.xml
+5
-0
AbstractSolrApi.java
...main/java/com/egolm/search/schedules/AbstractSolrApi.java
+37
-38
No files found.
pom.xml
View file @
d9001c21
...
...
@@ -79,6 +79,11 @@
<groupId>
org.apache.solr
</groupId>
<artifactId>
solr-solrj
</artifactId>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
28.0-jre
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/com/egolm/search/schedules/AbstractSolrApi.java
View file @
d9001c21
...
...
@@ -20,29 +20,33 @@ import com.egolm.common.StringUtil;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.common.jdbc.Page
;
import
com.egolm.search.config.XRException
;
import
com.google.common.collect.Lists
;
public
abstract
class
AbstractSolrApi
implements
SolrApi
{
public
abstract
HttpSolrClient
getSolrClient
();
@Override
public
Map
<
String
,
Object
>
query
(
Page
page
,
String
queryKey
,
String
[]
keywords
,
String
[]
orders
,
String
...
groupNames
)
{
logger
.
info
(
"收到商品检索请求:"
+
Rjx
.
json
().
set
(
"page"
,
page
).
set
(
"queryKey"
,
queryKey
).
set
(
"keywords"
,
keywords
).
set
(
"orders"
,
orders
).
set
(
"groupNames"
,
groupNames
).
toString
());
if
(
page
==
null
)
{
public
Map
<
String
,
Object
>
query
(
Page
page
,
String
queryKey
,
String
[]
keywords
,
String
[]
orders
,
String
...
groupNames
)
{
logger
.
info
(
"收到商品检索请求:"
+
Rjx
.
json
().
set
(
"page"
,
page
).
set
(
"queryKey"
,
queryKey
).
set
(
"keywords"
,
keywords
)
.
set
(
"orders"
,
orders
).
set
(
"groupNames"
,
groupNames
).
toString
());
if
(
page
==
null
)
{
page
=
new
Page
(
1L
,
20L
);
}
queryKey
=
queryKey
.
toUpperCase
();
Rjx
result
=
Rjx
.
json
();
SolrQuery
solrQuery
=
new
SolrQuery
(
queryKey
);
if
(
keywords
!=
null
)
{
for
(
String
keyword
:
keywords
)
{
if
(
keywords
!=
null
)
{
for
(
String
keyword
:
keywords
)
{
solrQuery
.
addFilterQuery
(
keyword
);
}
}
if
(
orders
!=
null
)
{
for
(
String
order
:
orders
)
{
if
(
orders
!=
null
)
{
for
(
String
order
:
orders
)
{
String
[]
kv
=
order
.
split
(
":"
,
2
);
ORDER
sc
=
kv
[
1
]
==
null
||
kv
[
1
].
trim
().
length
()
==
0
||
kv
[
1
].
equalsIgnoreCase
(
"asc"
)
?
ORDER
.
asc
:
ORDER
.
desc
;
ORDER
sc
=
kv
[
1
]
==
null
||
kv
[
1
].
trim
().
length
()
==
0
||
kv
[
1
].
equalsIgnoreCase
(
"asc"
)
?
ORDER
.
asc
:
ORDER
.
desc
;
solrQuery
.
addSort
(
kv
[
0
],
sc
);
}
}
...
...
@@ -56,15 +60,15 @@ public abstract class AbstractSolrApi implements SolrApi {
List
<
FacetField
>
facetFields
=
resp
.
getFacetFields
();
for
(
FacetField
facet
:
facetFields
)
{
String
fieldName
=
facet
.
getName
();
if
(
StringUtil
.
isNotBlank
(
fieldName
))
{
if
(
StringUtil
.
isNotBlank
(
fieldName
))
{
List
<
Count
>
values
=
facet
.
getValues
();
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Count
count
=
values
.
get
(
i
);
List
<
String
>
list
=
groups
.
get
(
fieldName
);
if
(
list
==
null
)
{
if
(
list
==
null
)
{
list
=
new
ArrayList
<
String
>();
}
if
(
count
.
getCount
()
>
0
)
{
if
(
count
.
getCount
()
>
0
)
{
list
.
add
(
count
.
getName
());
}
else
{
break
;
...
...
@@ -76,9 +80,9 @@ public abstract class AbstractSolrApi implements SolrApi {
SolrDocumentList
docList
=
resp
.
getResults
();
page
.
setTotal
(
docList
.
getNumFound
());
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
SolrDocument
doc
:
docList
)
{
for
(
SolrDocument
doc
:
docList
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
for
(
String
key
:
doc
.
keySet
())
{
for
(
String
key
:
doc
.
keySet
())
{
Object
objValue
=
doc
.
get
(
key
);
map
.
put
(
key
,
objValue
);
}
...
...
@@ -92,27 +96,22 @@ public abstract class AbstractSolrApi implements SolrApi {
}
public
void
update
(
List
<
Map
<
String
,
Object
>>
list
)
{
HttpSolrClient
solrClient
=
getSolrClient
();
try
{
List
<
SolrInputDocument
>
docs
=
new
ArrayList
<
SolrInputDocument
>();
for
(
Map
<
String
,
Object
>
map
:
list
)
{
for
(
Map
<
String
,
Object
>
map
:
list
)
{
SolrInputDocument
solrInputDocument
=
new
SolrInputDocument
();
for
(
String
key
:
map
.
keySet
())
{
if
(
key
!=
null
&&
key
.
trim
().
length
()
>
0
)
{
for
(
String
key
:
map
.
keySet
())
{
if
(
key
!=
null
&&
key
.
trim
().
length
()
>
0
)
{
solrInputDocument
.
addField
(
key
,
StringUtil
.
toString
(
map
.
get
(
key
)));
}
}
docs
.
add
(
solrInputDocument
);
}
int
size
=
1000
;
List
<
SolrInputDocument
>
tmp
=
new
ArrayList
<
SolrInputDocument
>();
HttpSolrClient
solrClient
=
getSolrClient
();
try
{
for
(
int
docIndex
=
0
;
docIndex
<
docs
.
size
();
docIndex
++)
{
tmp
.
add
(
docs
.
get
(
docIndex
));
if
((
docIndex
%
size
==
0
||
docIndex
==
docs
.
size
()
-
1
)
&&
docIndex
>
0
)
{
List
<
List
<
SolrInputDocument
>>
doclist
=
Lists
.
partition
(
docs
,
1000
);
for
(
List
<
SolrInputDocument
>
tmp
:
doclist
)
{
solrClient
.
add
(
tmp
);
tmp
=
new
ArrayList
<
SolrInputDocument
>();
}
}
solrClient
.
commit
();
}
catch
(
Exception
e
)
{
...
...
@@ -129,7 +128,7 @@ public abstract class AbstractSolrApi implements SolrApi {
public
void
deleteById
(
List
<
String
>
documentIds
)
{
HttpSolrClient
solrClient
=
getSolrClient
();
try
{
if
(
documentIds
!=
null
&&
documentIds
.
size
()
>
0
)
{
if
(
documentIds
!=
null
&&
documentIds
.
size
()
>
0
)
{
solrClient
.
deleteById
(
documentIds
);
solrClient
.
commit
();
}
...
...
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