Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
9ca05d84
Commit
9ca05d84
authored
Sep 01, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Workaround for DATAES-127: Include total, other and missing count in
TermResult
https://jira.spring.io/browse/DATAES-127
parent
6447f83d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
9 deletions
+158
-9
pom.xml
pom.xml
+1
-1
src/main/java/org/genesys2/server/service/ElasticService.java
...main/java/org/genesys2/server/service/ElasticService.java
+2
-1
src/main/java/org/genesys2/server/service/impl/ElasticsearchSearchServiceImpl.java
...2/server/service/impl/ElasticsearchSearchServiceImpl.java
+3
-5
src/main/java/org/springframework/data/elasticsearch/core/facet/DefaultFacetMapper.java
...ork/data/elasticsearch/core/facet/DefaultFacetMapper.java
+83
-0
src/main/java/org/springframework/data/elasticsearch/core/facet/result/TermResult.java
...work/data/elasticsearch/core/facet/result/TermResult.java
+63
-0
src/test/java/org/genesys2/server/service/impl/ElasticsearchTest.java
...a/org/genesys2/server/service/impl/ElasticsearchTest.java
+6
-2
No files found.
pom.xml
View file @
9ca05d84
...
...
@@ -424,7 +424,7 @@
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-elasticsearch
</artifactId>
<version>
1.0.
2
.RELEASE
</version>
<version>
1.0.
4
.RELEASE
</version>
</dependency>
<dependency>
...
...
src/main/java/org/genesys2/server/service/ElasticService.java
View file @
9ca05d84
...
...
@@ -25,6 +25,7 @@ import org.genesys2.server.service.impl.SearchException;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.elasticsearch.core.facet.result.Term
;
import
org.springframework.data.elasticsearch.core.facet.result.TermResult
;
public
interface
ElasticService
{
...
...
@@ -42,6 +43,6 @@ public interface ElasticService {
Page
<
AccessionDetails
>
filter
(
AppliedFilters
appliedFilters
,
Pageable
pageable
)
throws
SearchException
;
List
<
Term
>
termStatistics
(
AppliedFilters
appliedFilters
,
String
term
,
int
size
)
throws
SearchException
;
TermResult
termStatistics
(
AppliedFilters
appliedFilters
,
String
term
,
int
size
)
throws
SearchException
;
}
src/main/java/org/genesys2/server/service/impl/ElasticsearchSearchServiceImpl.java
View file @
9ca05d84
...
...
@@ -44,7 +44,6 @@ import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import
org.springframework.data.elasticsearch.core.FacetedPage
;
import
org.springframework.data.elasticsearch.core.facet.FacetRequest
;
import
org.springframework.data.elasticsearch.core.facet.request.TermFacetRequestBuilder
;
import
org.springframework.data.elasticsearch.core.facet.result.Term
;
import
org.springframework.data.elasticsearch.core.facet.result.TermResult
;
import
org.springframework.data.elasticsearch.core.query.IndexQuery
;
import
org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
;
...
...
@@ -114,17 +113,16 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
@Override
public
List
<
Term
>
termStatistics
(
AppliedFilters
appliedFilters
,
String
term
,
int
size
)
throws
SearchException
{
public
TermResult
termStatistics
(
AppliedFilters
appliedFilters
,
String
term
,
int
size
)
throws
SearchException
{
AndFilterBuilder
filterBuilder
=
getFilterBuilder
(
appliedFilters
);
FacetRequest
termFacetRequest
=
new
TermFacetRequestBuilder
(
"f"
).
applyQueryFilter
().
fields
(
term
).
size
(
10
).
build
();
FacetRequest
termFacetRequest
=
new
TermFacetRequestBuilder
(
"f"
).
applyQueryFilter
().
fields
(
term
).
size
(
size
).
build
();
SearchQuery
searchQuery
=
new
NativeSearchQueryBuilder
().
withFilter
(
filterBuilder
).
withFacet
(
termFacetRequest
).
build
();
try
{
FacetedPage
<
AccessionDetails
>
page
=
elasticsearchTemplate
.
queryForPage
(
searchQuery
,
AccessionDetails
.
class
);
TermResult
facet
=
(
TermResult
)
page
.
getFacet
(
"f"
);
return
facet
.
getTerms
();
return
(
TermResult
)
page
.
getFacet
(
"f"
);
}
catch
(
Throwable
e
)
{
throw
new
SearchException
(
e
.
getMessage
(),
e
);
...
...
src/main/java/org/springframework/data/elasticsearch/core/facet/DefaultFacetMapper.java
0 → 100644
View file @
9ca05d84
/*
* Copyright 2014 the original author or authors.
*
* Licensed 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.
*/
package
org.springframework.data.elasticsearch.core.facet
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.elasticsearch.search.facet.Facet
;
import
org.elasticsearch.search.facet.histogram.HistogramFacet
;
import
org.elasticsearch.search.facet.range.RangeFacet
;
import
org.elasticsearch.search.facet.statistical.StatisticalFacet
;
import
org.elasticsearch.search.facet.terms.TermsFacet
;
import
org.springframework.data.elasticsearch.core.facet.result.*
;
/**
* @author Artur Konczak
* @author Petar Tahchiev
* @author Matija Obreza
*/
public
class
DefaultFacetMapper
{
public
static
FacetResult
parse
(
Facet
facet
)
{
if
(
facet
instanceof
TermsFacet
)
{
return
parseTerm
((
TermsFacet
)
facet
);
}
if
(
facet
instanceof
RangeFacet
)
{
return
parseRange
((
RangeFacet
)
facet
);
}
if
(
facet
instanceof
StatisticalFacet
)
{
return
parseStatistical
((
StatisticalFacet
)
facet
);
}
if
(
facet
instanceof
HistogramFacet
)
{
return
parseHistogram
((
HistogramFacet
)
facet
);
}
return
null
;
}
private
static
FacetResult
parseTerm
(
TermsFacet
facet
)
{
List
<
Term
>
entries
=
new
ArrayList
<
Term
>();
for
(
TermsFacet
.
Entry
entry
:
facet
.
getEntries
())
{
entries
.
add
(
new
Term
(
entry
.
getTerm
().
toString
(),
entry
.
getCount
()));
}
// https://jira.spring.io/browse/DATAES-127 Include total, other and missing count in TermResult
return
new
TermResult
(
facet
.
getName
(),
entries
,
facet
.
getTotalCount
(),
facet
.
getOtherCount
(),
facet
.
getMissingCount
());
}
private
static
FacetResult
parseRange
(
RangeFacet
facet
)
{
List
<
Range
>
entries
=
new
ArrayList
<
Range
>();
for
(
RangeFacet
.
Entry
entry
:
facet
.
getEntries
())
{
entries
.
add
(
new
Range
(
entry
.
getFrom
()
==
Double
.
NEGATIVE_INFINITY
?
null
:
entry
.
getFrom
(),
entry
.
getTo
()
==
Double
.
POSITIVE_INFINITY
?
null
:
entry
.
getTo
(),
entry
.
getCount
(),
entry
.
getTotal
(),
entry
.
getTotalCount
(),
entry
.
getMin
(),
entry
.
getMax
()));
}
return
new
RangeResult
(
facet
.
getName
(),
entries
);
}
private
static
FacetResult
parseStatistical
(
StatisticalFacet
facet
)
{
return
new
StatisticalResult
(
facet
.
getName
(),
facet
.
getCount
(),
facet
.
getMax
(),
facet
.
getMin
(),
facet
.
getMean
(),
facet
.
getStdDeviation
(),
facet
.
getSumOfSquares
(),
facet
.
getTotal
(),
facet
.
getVariance
());
}
private
static
FacetResult
parseHistogram
(
HistogramFacet
facet
)
{
List
<
IntervalUnit
>
entries
=
new
ArrayList
<
IntervalUnit
>();
for
(
HistogramFacet
.
Entry
entry
:
facet
.
getEntries
())
{
entries
.
add
(
new
IntervalUnit
(
entry
.
getKey
(),
entry
.
getCount
(),
entry
.
getTotalCount
(),
entry
.
getTotal
(),
entry
.
getMean
(),
entry
.
getMin
(),
entry
.
getMax
()));
}
return
new
HistogramResult
(
facet
.
getName
(),
entries
);
}
}
src/main/java/org/springframework/data/elasticsearch/core/facet/result/TermResult.java
0 → 100644
View file @
9ca05d84
/*
* Copyright 2014 the original author or authors.
*
* Licensed 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.
*/
package
org.springframework.data.elasticsearch.core.facet.result
;
import
java.util.List
;
import
org.springframework.data.elasticsearch.core.facet.AbstractFacetResult
;
import
org.springframework.data.elasticsearch.core.facet.FacetType
;
/**
* Basic term facet result
*
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Artur Konczak
* @author Jonathan Yan
* @author Matija Obreza
*/
public
class
TermResult
extends
AbstractFacetResult
{
private
List
<
Term
>
terms
;
private
long
totalCount
;
private
long
otherCount
;
private
long
missingCount
;
// https://jira.spring.io/browse/DATAES-127 Include total, other and missing count in TermResult
public
TermResult
(
String
name
,
List
<
Term
>
terms
,
long
totalCount
,
long
otherCount
,
long
missingCount
)
{
super
(
name
,
FacetType
.
term
);
this
.
terms
=
terms
;
this
.
totalCount
=
totalCount
;
this
.
otherCount
=
otherCount
;
this
.
missingCount
=
missingCount
;
}
public
List
<
Term
>
getTerms
()
{
return
terms
;
}
public
long
getOtherCount
()
{
return
otherCount
;
}
public
long
getMissingCount
()
{
return
missingCount
;
}
public
long
getTotalCount
()
{
return
totalCount
;
}
}
src/test/java/org/genesys2/server/service/impl/ElasticsearchTest.java
View file @
9ca05d84
...
...
@@ -62,6 +62,7 @@ import org.springframework.context.annotation.Import;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.elasticsearch.core.facet.result.Term
;
import
org.springframework.data.elasticsearch.core.facet.result.TermResult
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
...
...
@@ -330,10 +331,13 @@ public class ElasticsearchTest {
.
addFilterValue
(
new
FilterHandler
.
LiteralValueFilter
(
40
)));
LOG
.
info
(
filters
);
List
<
Term
>
terms
=
elasticService
.
termStatistics
(
filters
,
FilterConstants
.
STORAGE
,
10
);
for
(
Term
t
:
term
s
)
{
TermResult
termResult
=
elasticService
.
termStatistics
(
filters
,
FilterConstants
.
STORAGE
,
3
);
for
(
Term
t
:
term
Result
.
getTerms
()
)
{
LOG
.
info
(
t
.
getTerm
()
+
" = "
+
t
.
getCount
());
}
LOG
.
info
(
"Other="
+
termResult
.
getOtherCount
());
LOG
.
info
(
"Missing="
+
termResult
.
getMissingCount
());
LOG
.
info
(
"Total="
+
termResult
.
getTotalCount
());
}
@Test
...
...
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