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
1edaab12
Commit
1edaab12
authored
Jul 11, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
e29fcaf8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
83 deletions
+0
-83
AbstractSolrApi.java
...main/java/com/egolm/search/schedules/AbstractSolrApi.java
+0
-79
SolrApi.java
src/main/java/com/egolm/search/schedules/SolrApi.java
+0
-4
No files found.
src/main/java/com/egolm/search/schedules/AbstractSolrApi.java
View file @
1edaab12
package
com
.
egolm
.
search
.
schedules
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.solr.client.solrj.SolrQuery
;
import
org.apache.solr.client.solrj.SolrQuery.ORDER
;
import
org.apache.solr.client.solrj.impl.HttpSolrClient
;
import
org.apache.solr.client.solrj.response.FacetField
;
import
org.apache.solr.client.solrj.response.FacetField.Count
;
import
org.apache.solr.client.solrj.response.QueryResponse
;
import
org.apache.solr.common.SolrDocument
;
import
org.apache.solr.common.SolrDocumentList
;
import
org.apache.solr.common.SolrInputDocument
;
import
com.alibaba.fastjson.JSON
;
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
;
...
...
@@ -26,75 +16,6 @@ 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
)
{
page
=
new
Page
(
1L
,
20L
);
}
queryKey
=
queryKey
.
toUpperCase
();
Rjx
result
=
Rjx
.
json
();
SolrQuery
solrQuery
=
new
SolrQuery
(
queryKey
);
if
(
keywords
!=
null
)
{
for
(
String
keyword
:
keywords
)
{
solrQuery
.
addFilterQuery
(
keyword
);
}
}
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
;
solrQuery
.
addSort
(
kv
[
0
],
sc
);
}
}
solrQuery
.
setFacet
(
true
);
solrQuery
.
addFacetField
(
groupNames
);
solrQuery
.
setRows
(
page
.
getLimit
().
intValue
());
solrQuery
.
setStart
(
page
.
getFirstRowNumber
().
intValue
()
-
1
);
try
{
QueryResponse
resp
=
getSolrClient
().
query
(
solrQuery
);
Map
<
String
,
List
<
String
>>
groups
=
new
HashMap
<
String
,
List
<
String
>>();
List
<
FacetField
>
facetFields
=
resp
.
getFacetFields
();
for
(
FacetField
facet
:
facetFields
)
{
String
fieldName
=
facet
.
getName
();
if
(
StringUtil
.
isNotBlank
(
fieldName
))
{
List
<
Count
>
values
=
facet
.
getValues
();
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
Count
count
=
values
.
get
(
i
);
List
<
String
>
list
=
groups
.
get
(
fieldName
);
if
(
list
==
null
)
{
list
=
new
ArrayList
<
String
>();
}
if
(
count
.
getCount
()
>
0
)
{
list
.
add
(
count
.
getName
());
}
else
{
break
;
}
groups
.
put
(
fieldName
,
list
);
}
}
}
SolrDocumentList
docList
=
resp
.
getResults
();
page
.
setTotal
(
docList
.
getNumFound
());
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
SolrDocument
doc
:
docList
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
for
(
String
key
:
doc
.
keySet
())
{
Object
objValue
=
doc
.
get
(
key
);
map
.
put
(
key
,
objValue
);
}
list
.
add
(
map
);
}
result
.
set
(
"datas"
,
list
).
set
(
"page"
,
page
).
set
(
"groups"
,
groups
);
return
result
.
getMap
();
}
catch
(
Exception
e
)
{
throw
new
XRException
(
"SolrQuery:"
+
queryKey
+
","
+
JSON
.
toJSONString
(
keywords
),
e
);
}
}
public
void
update
(
List
<
Map
<
String
,
Object
>>
list
)
{
HttpSolrClient
solrClient
=
getSolrClient
();
try
{
...
...
src/main/java/com/egolm/search/schedules/SolrApi.java
View file @
1edaab12
...
...
@@ -5,15 +5,11 @@ import java.util.Map;
import
org.apache.log4j.Logger
;
import
com.egolm.common.jdbc.Page
;
public
interface
SolrApi
{
Logger
logger
=
Logger
.
getLogger
(
SolrApi
.
class
);
public
Map
<
String
,
Object
>
query
(
Page
page
,
String
queryKey
,
String
[]
keywords
,
String
[]
orders
,
String
...
groupsNames
);
public
void
update
(
List
<
Map
<
String
,
Object
>>
datas
);
public
void
deleteById
(
List
<
String
>
idList
);
...
...
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