Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
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
dataplatform
atlas
Commits
e0fb7dc1
Commit
e0fb7dc1
authored
Jul 20, 2017
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1961: Basic search improvement in use of Solr index for attribute filtering (# 4)
parent
3d3be408
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
27 deletions
+57
-27
ClassificationSearchProcessor.java
...apache/atlas/discovery/ClassificationSearchProcessor.java
+18
-7
EntitySearchProcessor.java
...ava/org/apache/atlas/discovery/EntitySearchProcessor.java
+11
-9
FullTextSearchProcessor.java
...a/org/apache/atlas/discovery/FullTextSearchProcessor.java
+19
-2
SearchProcessor.java
...main/java/org/apache/atlas/discovery/SearchProcessor.java
+9
-9
No files found.
repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java
View file @
e0fb7dc1
...
...
@@ -58,7 +58,7 @@ public class ClassificationSearchProcessor extends SearchProcessor {
if
(
useSolrSearch
)
{
StringBuilder
solrQuery
=
new
StringBuilder
();
constructTypeTestQuery
(
solrQuery
,
classificationType
,
typeAndSubTypes
);
constructTypeTestQuery
(
solrQuery
,
typeAndSubTypes
);
constructFilterQuery
(
solrQuery
,
classificationType
,
filterCriteria
,
solrAttributes
);
String
solrQueryString
=
STRAY_AND_PATTERN
.
matcher
(
solrQuery
).
replaceAll
(
")"
);
...
...
@@ -97,14 +97,20 @@ public class ClassificationSearchProcessor extends SearchProcessor {
try
{
final
int
startIdx
=
context
.
getSearchParameters
().
getOffset
();
final
int
limit
=
context
.
getSearchParameters
().
getLimit
();
int
qryOffset
=
nextProcessor
==
null
?
startIdx
:
0
;
final
boolean
activeOnly
=
context
.
getSearchParameters
().
getExcludeDeletedEntities
();
// query to start at 0, even though startIdx can be higher - because few results in earlier retrieval could
// have been dropped: like non-active-entities or duplicate-entities (same entity pointed to by multiple
// classifications in the result)
//
// first 'startIdx' number of entries will be ignored
int
qryOffset
=
0
;
int
resultIdx
=
qryOffset
;
final
Set
<
String
>
processedGuids
=
new
HashSet
<>();
final
List
<
AtlasVertex
>
entityVertices
=
new
ArrayList
<>();
final
List
<
AtlasVertex
>
classificationVertices
=
new
ArrayList
<>();
for
(;
ret
.
size
()
<
limit
;
qryOffset
+=
limit
)
{
entityVertices
.
clear
();
classificationVertices
.
clear
();
...
...
@@ -138,17 +144,22 @@ public class ClassificationSearchProcessor extends SearchProcessor {
for
(
AtlasEdge
edge
:
edges
)
{
AtlasVertex
entityVertex
=
edge
.
getOutVertex
();
if
(
activeOnly
&&
AtlasGraphUtilsV1
.
getState
(
entityVertex
)
!=
AtlasEntity
.
Status
.
ACTIVE
)
{
continue
;
}
String
guid
=
AtlasGraphUtilsV1
.
getIdFromVertex
(
entityVertex
);
if
(!
processedGuids
.
contains
(
guid
))
{
if
(!
context
.
getSearchParameters
().
getExcludeDeletedEntities
()
||
AtlasGraphUtilsV1
.
getState
(
entityVertex
)
==
AtlasEntity
.
Status
.
ACTIVE
)
{
entityVertices
.
add
(
entityVertex
);
if
(
processedGuids
.
contains
(
guid
))
{
continue
;
}
entityVertices
.
add
(
entityVertex
);
processedGuids
.
add
(
guid
);
}
}
}
super
.
filter
(
entityVertices
);
...
...
repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java
View file @
e0fb7dc1
...
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
.
discovery
;
import
org.apache.atlas.model.discovery.SearchParameters.FilterCriteria
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.*
;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
...
...
@@ -60,7 +61,7 @@ public class EntitySearchProcessor extends SearchProcessor {
StringBuilder
solrQuery
=
new
StringBuilder
();
if
(
typeSearchBySolr
)
{
constructTypeTestQuery
(
solrQuery
,
entityType
,
typeAndSubTypes
);
constructTypeTestQuery
(
solrQuery
,
typeAndSubTypes
);
}
if
(
attrSearchBySolr
)
{
...
...
@@ -70,6 +71,10 @@ public class EntitySearchProcessor extends SearchProcessor {
}
if
(
solrQuery
.
length
()
>
0
)
{
if
(
context
.
getSearchParameters
().
getExcludeDeletedEntities
())
{
constructStateTestQuery
(
solrQuery
);
}
String
solrQueryString
=
STRAY_AND_PATTERN
.
matcher
(
solrQuery
).
replaceAll
(
")"
);
solrQueryString
=
STRAY_OR_PATTERN
.
matcher
(
solrQueryString
).
replaceAll
(
")"
);
...
...
@@ -130,7 +135,11 @@ public class EntitySearchProcessor extends SearchProcessor {
try
{
final
int
startIdx
=
context
.
getSearchParameters
().
getOffset
();
final
int
limit
=
context
.
getSearchParameters
().
getLimit
();
int
qryOffset
=
(
nextProcessor
==
null
&&
(
graphQuery
==
null
||
indexQuery
==
null
))
?
startIdx
:
0
;
// when subsequent filtering stages are involved, query should start at 0 even though startIdx can be higher
//
// first 'startIdx' number of entries will be ignored
int
qryOffset
=
(
nextProcessor
!=
null
||
(
graphQuery
!=
null
&&
indexQuery
!=
null
))
?
0
:
startIdx
;
int
resultIdx
=
qryOffset
;
final
List
<
AtlasVertex
>
entityVertices
=
new
ArrayList
<>();
...
...
@@ -154,13 +163,6 @@ public class EntitySearchProcessor extends SearchProcessor {
while
(
idxQueryResult
.
hasNext
())
{
AtlasVertex
vertex
=
idxQueryResult
.
next
().
getVertex
();
// skip non-entity vertices
if
(!
AtlasGraphUtilsV1
.
isEntityVertex
(
vertex
))
{
LOG
.
warn
(
"EntitySearchProcessor.execute(): ignoring non-entity vertex (id={})"
,
vertex
.
getId
());
// might cause duplicate entries in result
continue
;
}
entityVertices
.
add
(
vertex
);
}
...
...
repository/src/main/java/org/apache/atlas/discovery/FullTextSearchProcessor.java
View file @
e0fb7dc1
...
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
.
discovery
;
import
org.apache.atlas.model.discovery.SearchParameters
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graph.GraphHelper
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
...
...
@@ -74,6 +75,10 @@ public class FullTextSearchProcessor extends SearchProcessor {
}
}
if
(
context
.
getSearchParameters
().
getExcludeDeletedEntities
())
{
queryString
.
append
(
AND_STR
).
append
(
"(ACTIVE)"
);
}
queryString
.
append
(
")"
);
indexQuery
=
context
.
getGraph
().
indexQuery
(
Constants
.
FULLTEXT_INDEX
,
queryString
.
toString
());
...
...
@@ -96,7 +101,13 @@ public class FullTextSearchProcessor extends SearchProcessor {
try
{
final
int
startIdx
=
context
.
getSearchParameters
().
getOffset
();
final
int
limit
=
context
.
getSearchParameters
().
getLimit
();
int
qryOffset
=
nextProcessor
==
null
?
startIdx
:
0
;
final
boolean
activeOnly
=
context
.
getSearchParameters
().
getExcludeDeletedEntities
();
// query to start at 0, even though startIdx can be higher - because few results in earlier retrieval could
// have been dropped: like vertices of non-entity or non-active-entity
//
// first 'startIdx' number of entries will be ignored
int
qryOffset
=
0
;
int
resultIdx
=
qryOffset
;
final
List
<
AtlasVertex
>
entityVertices
=
new
ArrayList
<>();
...
...
@@ -121,8 +132,14 @@ public class FullTextSearchProcessor extends SearchProcessor {
// skip non-entity vertices
if
(!
AtlasGraphUtilsV1
.
isEntityVertex
(
vertex
))
{
LOG
.
warn
(
"FullTextSearchProcessor.execute(): ignoring non-entity vertex (id={})"
,
vertex
.
getId
());
// might cause duplicate entries in result
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"FullTextSearchProcessor.execute(): ignoring non-entity vertex (id={})"
,
vertex
.
getId
());
}
continue
;
}
if
(
activeOnly
&&
AtlasGraphUtilsV1
.
getState
(
vertex
)
!=
AtlasEntity
.
Status
.
ACTIVE
)
{
continue
;
}
...
...
repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
View file @
e0fb7dc1
...
...
@@ -181,7 +181,7 @@ public abstract class SearchProcessor {
return
ret
;
}
protected
void
constructTypeTestQuery
(
StringBuilder
solrQuery
,
AtlasStructType
type
,
Set
<
String
>
typeAndAllSubTypes
)
{
protected
void
constructTypeTestQuery
(
StringBuilder
solrQuery
,
Set
<
String
>
typeAndAllSubTypes
)
{
String
typeAndSubtypesString
=
StringUtils
.
join
(
typeAndAllSubTypes
,
SPACE_STRING
);
if
(
CollectionUtils
.
isNotEmpty
(
typeAndAllSubTypes
))
{
...
...
@@ -193,14 +193,6 @@ public abstract class SearchProcessor {
.
append
(
typeAndSubtypesString
)
.
append
(
")"
);
}
if
(
type
instanceof
AtlasEntityType
&&
context
.
getSearchParameters
().
getExcludeDeletedEntities
())
{
if
(
solrQuery
.
length
()
>
0
)
{
solrQuery
.
append
(
AND_STR
);
}
solrQuery
.
append
(
"v.\""
).
append
(
Constants
.
STATE_PROPERTY_KEY
).
append
(
"\":ACTIVE"
);
}
}
protected
void
constructFilterQuery
(
StringBuilder
solrQuery
,
AtlasStructType
type
,
FilterCriteria
filterCriteria
,
Set
<
String
>
solrAttributes
)
{
...
...
@@ -219,6 +211,14 @@ public abstract class SearchProcessor {
}
}
protected
void
constructStateTestQuery
(
StringBuilder
solrQuery
)
{
if
(
solrQuery
.
length
()
>
0
)
{
solrQuery
.
append
(
AND_STR
);
}
solrQuery
.
append
(
"v.\""
).
append
(
Constants
.
STATE_PROPERTY_KEY
).
append
(
"\":ACTIVE"
);
}
private
String
toSolrQuery
(
AtlasStructType
type
,
FilterCriteria
criteria
,
Set
<
String
>
solrAttributes
,
int
level
)
{
return
toSolrQuery
(
type
,
criteria
,
solrAttributes
,
new
StringBuilder
(),
level
);
}
...
...
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