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
8a0c08f7
Commit
8a0c08f7
authored
Apr 03, 2015
by
Shwetha GS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rest API for fulll text search
parent
84a28168
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
7 deletions
+73
-7
MetadataServiceClient.java
...ava/org/apache/hadoop/metadata/MetadataServiceClient.java
+16
-1
MetadataDiscoveryResource.java
...oop/metadata/web/resources/MetadataDiscoveryResource.java
+47
-6
MetadataDiscoveryJerseyResourceIT.java
...data/web/resources/MetadataDiscoveryJerseyResourceIT.java
+10
-0
No files found.
client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java
View file @
8a0c08f7
...
...
@@ -73,7 +73,8 @@ public class MetadataServiceClient {
//Search operations
SEARCH
(
"api/metadata/discovery/search"
,
HttpMethod
.
GET
),
SEARCH_DSL
(
"api/metadata/discovery/search/dsl"
,
HttpMethod
.
GET
),
SEARCH_GREMLIN
(
"api/metadata/discovery/search/gremlin"
,
HttpMethod
.
GET
);
SEARCH_GREMLIN
(
"api/metadata/discovery/search/gremlin"
,
HttpMethod
.
GET
),
SEARCH_FULL_TEXT
(
"api/metadata/discovery/search/fulltext"
,
HttpMethod
.
GET
);
private
final
String
method
;
private
final
String
path
;
...
...
@@ -157,6 +158,8 @@ public class MetadataServiceClient {
"g.V.has(\"typeName\",\"%s\").and(_().has(\"%s.%s\", T.eq, \"%s\")).toList()"
,
typeName
,
typeName
,
attributeName
,
attributeValue
);
return
searchByGremlin
(
gremlinQuery
);
// String dslQuery = String.format("%s where %s = \"%s\"", typeName, attributeName, attributeValue);
// return searchByDSL(dslQuery);
}
/**
...
...
@@ -183,6 +186,18 @@ public class MetadataServiceClient {
return
callAPIWithResource
(
API
.
SEARCH_GREMLIN
,
resource
);
}
/**
* Search given full text search
* @param query Query
* @return result json object
* @throws MetadataServiceException
*/
public
JSONObject
searchByFullText
(
String
query
)
throws
MetadataServiceException
{
WebResource
resource
=
getResource
(
API
.
SEARCH_FULL_TEXT
);
resource
=
resource
.
queryParam
(
"query"
,
query
);
return
callAPIWithResource
(
API
.
SEARCH_FULL_TEXT
,
resource
);
}
public
String
getRequestId
(
JSONObject
json
)
throws
MetadataServiceException
{
try
{
return
json
.
getString
(
REQUEST_ID
);
...
...
webapp/src/main/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryResource.java
View file @
8a0c08f7
...
...
@@ -92,16 +92,24 @@ public class MetadataDiscoveryResource {
}
catch
(
Throwable
throwable
)
{
LOG
.
error
(
"Unable to get entity list for query {} using dsl"
,
query
,
throwable
);
// todo: fall back to full text search
response
.
put
(
"queryType"
,
"full-text"
);
response
.
put
(
MetadataServiceClient
.
RESULTS
,
new
JSONObject
());
try
{
//fall back to full-text
final
String
jsonResult
=
discoveryService
.
searchByFullText
(
query
);
response
.
put
(
"queryType"
,
"full-text"
);
response
.
put
(
MetadataServiceClient
.
RESULTS
,
new
JSONObject
(
jsonResult
));
}
catch
(
DiscoveryException
e
)
{
LOG
.
error
(
"Unable to get entity list for query {}"
,
query
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
}
catch
(
JSONException
e
)
{
LOG
.
error
(
"Unable to get entity list for query {}"
,
query
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
}
}
return
Response
.
ok
(
response
).
build
();
}
catch
(
JSONException
e
)
{
LOG
.
error
(
"Unable to get entity list for query {}"
,
query
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
}
}
...
...
@@ -177,4 +185,36 @@ public class MetadataDiscoveryResource {
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
}
}
}
/**
* Search using full text search.
*
* @param query search query.
* @return JSON representing the type and results.
*/
@GET
@Path
(
"search/fulltext"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
searchUsingFullText
(
@QueryParam
(
"query"
)
String
query
)
{
Preconditions
.
checkNotNull
(
query
,
"query cannot be null"
);
try
{
final
String
jsonResult
=
discoveryService
.
searchByFullText
(
query
);
JSONObject
response
=
new
JSONObject
();
response
.
put
(
MetadataServiceClient
.
REQUEST_ID
,
Servlets
.
getRequestId
());
response
.
put
(
"query"
,
query
);
response
.
put
(
"queryType"
,
"full-text"
);
response
.
put
(
MetadataServiceClient
.
RESULTS
,
new
JSONObject
(
jsonResult
));
return
Response
.
ok
(
response
).
build
();
}
catch
(
DiscoveryException
e
)
{
LOG
.
error
(
"Unable to get entity list for query {}"
,
query
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
}
catch
(
JSONException
e
)
{
LOG
.
error
(
"Unable to get entity list for query {}"
,
query
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
}
}
}
\ No newline at end of file
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryJerseyResourceIT.java
View file @
8a0c08f7
...
...
@@ -147,6 +147,16 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
Assert
.
assertEquals
(
response
.
getString
(
"queryType"
),
"dsl"
);
}
@Test
(
enabled
=
false
)
public
void
testSearchUsingFullText
()
throws
Exception
{
String
query
=
"foo bar"
;
JSONObject
response
=
serviceClient
.
searchByFullText
(
query
);
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
Assert
.
assertEquals
(
response
.
getString
(
"query"
),
query
);
Assert
.
assertEquals
(
response
.
getString
(
"queryType"
),
"full-text"
);
}
private
void
createTypes
()
throws
Exception
{
HierarchicalTypeDefinition
<
ClassType
>
dslTestTypeDefinition
=
TypesUtil
.
createClassTypeDef
(
"dsl_test_type"
,
...
...
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