Skip to content

Commit

Permalink
Use shorter parameter names in the geocoder
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesj committed Jan 22, 2015
1 parent f6cb209 commit 265916f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/main/java/org/opentripplanner/common/LuceneIndex.java
Expand Up @@ -152,20 +152,20 @@ public void run() {
/** Fetch results for the geocoder using the OTP graph for stops, clusters and street names /** Fetch results for the geocoder using the OTP graph for stops, clusters and street names
* *
* @param queryString * @param queryString
* @param autoComplete Whether we should use the query string to do a prefix match * @param autocomplete Whether we should use the query string to do a prefix match
* @param showStops Search for stops, either for name or stop code * @param stops Search for stops, either by name or stop code
* @param showClusters Search for clusters by their name * @param clusters Search for clusters by their name
* @param showCorners Search for street corners using at least one of the street names * @param corners Search for street corners using at least one of the street names
* @return list of results in in the format expected by GeocoderBuiltin.js in the OTP Leaflet client * @return list of results in in the format expected by GeocoderBuiltin.js in the OTP Leaflet client
*/ */
public List<LuceneResult> query (String queryString, boolean autoComplete, public List<LuceneResult> query (String queryString, boolean autocomplete,
boolean showStops, boolean showClusters, boolean showCorners) { boolean stops, boolean clusters, boolean corners) {
/* Turn the query string into a Lucene query.*/ /* Turn the query string into a Lucene query.*/
BooleanQuery query = new BooleanQuery(); BooleanQuery query = new BooleanQuery();
BooleanQuery termQuery = new BooleanQuery(); BooleanQuery termQuery = new BooleanQuery();
for (String term : queryString.split(" ")) { for (String term : queryString.split(" ")) {
/* PrefixQuery matches all strings that start with the query string */ /* PrefixQuery matches all strings that start with the query string */
if (autoComplete) { if (autocomplete) {
termQuery.add(new PrefixQuery(new Term("name", term)), BooleanClause.Occur.SHOULD); termQuery.add(new PrefixQuery(new Term("name", term)), BooleanClause.Occur.SHOULD);
/* FuzzyQuery matches with all string stat are maximum 2 edits away from the query sring */ /* FuzzyQuery matches with all string stat are maximum 2 edits away from the query sring */
} else { } else {
Expand All @@ -177,15 +177,15 @@ public List<LuceneResult> query (String queryString, boolean autoComplete,
} }


query.add(termQuery, BooleanClause.Occur.MUST); query.add(termQuery, BooleanClause.Occur.MUST);
if (showStops || showClusters || showCorners) { if (stops || clusters || corners) {
BooleanQuery typeQuery = new BooleanQuery(); BooleanQuery typeQuery = new BooleanQuery();
if (showStops) { if (stops) {
typeQuery.add(new TermQuery(new Term("category", Category.STOP.name())), BooleanClause.Occur.SHOULD); typeQuery.add(new TermQuery(new Term("category", Category.STOP.name())), BooleanClause.Occur.SHOULD);
} }
if (showClusters) { if (clusters) {
typeQuery.add(new TermQuery(new Term("category", Category.CLUSTER.name())), BooleanClause.Occur.SHOULD); typeQuery.add(new TermQuery(new Term("category", Category.CLUSTER.name())), BooleanClause.Occur.SHOULD);
} }
if (showCorners) { if (corners) {
typeQuery.add(new TermQuery(new Term("category", Category.CORNER.name())), BooleanClause.Occur.SHOULD); typeQuery.add(new TermQuery(new Term("category", Category.CORNER.name())), BooleanClause.Occur.SHOULD);
} }
query.add(typeQuery, BooleanClause.Occur.MUST); query.add(typeQuery, BooleanClause.Occur.MUST);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/opentripplanner/index/GeocoderResource.java
Expand Up @@ -41,20 +41,20 @@ public GeocoderResource (@Context OTPServer otpServer, @PathParam("routerId") St
* Geocode using data using the OTP graph for stops, clusters and street names * Geocode using data using the OTP graph for stops, clusters and street names
* *
* @param query The query string we want to geocode * @param query The query string we want to geocode
* @param autoComplete Whether we should use the query string to do a prefix match * @param autocomplete Whether we should use the query string to do a prefix match
* @param showStops Search for stops, either for name or stop code * @param stops Search for stops, either by name or stop code
* @param showClusters Search for clusters by their name * @param clusters Search for clusters by their name
* @param showCorners Search for street corners using at least one of the street names * @param corners Search for street corners using at least one of the street names
* @return list of results in in the format expected by GeocoderBuiltin.js in the OTP Leaflet client * @return list of results in in the format expected by GeocoderBuiltin.js in the OTP Leaflet client
*/ */
@GET @GET
public Response textSearch (@QueryParam("query") String query, public Response textSearch (@QueryParam("query") String query,
@QueryParam("autoComplete") @DefaultValue("false") boolean autoComplete, @QueryParam("autocomplete") @DefaultValue("false") boolean autocomplete,
@QueryParam("showStops") @DefaultValue("true") boolean showStops, @QueryParam("stops") @DefaultValue("true") boolean stops,
@QueryParam("showClusters") @DefaultValue("false") boolean showClusters, @QueryParam("clusters") @DefaultValue("false") boolean clusters,
@QueryParam("showCorners") @DefaultValue("true") boolean showCorners @QueryParam("corners") @DefaultValue("true") boolean corners
) { ) {
return Response.status(Response.Status.OK).entity(index.query(query, autoComplete, showStops, showClusters, showCorners)).build(); return Response.status(Response.Status.OK).entity(index.query(query, autocomplete, stops, clusters, corners)).build();
} }


} }

0 comments on commit 265916f

Please sign in to comment.