Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
issue [pds-api-54]: wildcard searching (#15)
Browse files Browse the repository at this point in the history
* rework of grammar to QueryBuilder(s)

Updated the pom to use the correct version of ANTLR.

Updated ElasticSearchRegistrySearchRequestBuilder to make log output clearer for isolating current problems.

Reworked Antlr4SearchListener to get the wildcard request right. Gave it state and a stack which it processes more or less uniformly. Groups are the same as the parent such that if there are no () there are no sub boolean query groups. Then added the groups which add the current stack level onto the group and then shift up one when the groups ends. The and/or expressions similarly handle the conjunction in use the same way. However their stack levels need be the same. This allows (x) to be processed the same as (x and y and (w or u or v)) without and special checking or branching.

Antlr4SearchListenerTest was added to verify that the stack works correctly with respect to tranforming the grammar to a set of QueryBuilder(s). The only one being tested currently is the wildcard but many more should be added.

* tiny cleanup

* step forward on testing

Fix erroneous stack handling in Antlr4SearchListener.

Fix up the second test to show that the group does work.

* test updates

Tested the bulk of the grammar but need to do nested groups and find a way to verify the and/or statements are correctly stacked.

* update unit testing

Completed the testing with nested conditionals and a not group. Also added negative checks that should result in bad parsing. They are handled by forcing ANTLR to bail when there is a problem rather than doing the best it can.

* removed clutter

* update error handling and testing

Added catch block to change any parsing error into an HTTP 422 (unprocessable entity). Searching on the web indicated that this error is the most appropriate in that that the syntax is sufficient to pass all URL tests and get routed to the proper processing unit (the lexer) but it cannot understand it semantically (from the standpoint of the URL).

Changed the testing to JUnit test.

* updated POM to latest lexer

* make errors uniform and add logging

* fix not group

* verification tool for acceptance criteria

* make URL more readable because requests helps

* fix details

Fixing "a eq b" required updating the api-search-query-lexer that had some fallout here. Maining that ctx.FIELD() now requires a parameter for which of them is being requested.

The quoting option of a eq "b" should not carry quotes into search request.

* change http error code

* FIELD conversion as required by elasticsearch backend

* add requested comment

Co-authored-by: Al Niessner <[email protected]>
  • Loading branch information
al-niessner and Al Niessner authored May 6, 2021
1 parent 9dfe33d commit fa60dc8
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 252 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@
<dependency>
<groupId>gov.nasa.pds</groupId>
<artifactId>api-search-query-lexer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.tunnelvisionlabs</groupId>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7</version>
<version>4.9.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import javax.servlet.http.HttpServletRequest;

import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequest;
Expand Down Expand Up @@ -210,7 +211,10 @@ protected ResponseEntity<Products> getProductsResponseEntity(String q, int start
log.error("Couldn't serialize response for content type " + accept, e);
return new ResponseEntity<Products>(HttpStatus.INTERNAL_SERVER_ERROR);
}

catch (ParseCancellationException pce) {
log.error("Could not parse the query string: " + q);
return new ResponseEntity<Products>(HttpStatus.BAD_REQUEST);
}
}
else return new ResponseEntity<Products>(HttpStatus.NOT_IMPLEMENTED);
}
Expand Down
Loading

0 comments on commit fa60dc8

Please sign in to comment.