Package org.opentripplanner.index

Source Code of org.opentripplanner.index.GeocoderResource

package org.opentripplanner.index;

import org.opentripplanner.common.LuceneIndex;
import org.opentripplanner.routing.graph.GraphIndex;
import org.opentripplanner.standalone.OTPServer;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
* OTP simple built-in geocoder.
* Client geocoder modules usually read XML, but GeocoderBuiltin reads JSON.
*/
@Path("/routers/{routerId}/geocode")
@Produces(MediaType.APPLICATION_JSON)
public class GeocoderResource {

    private final LuceneIndex index;

    public GeocoderResource (@Context OTPServer otpServer, @PathParam("routerId") String routerId) {
        GraphIndex graphIndex = otpServer.graphService.getGraph(routerId).index;
        synchronized (graphIndex) {
            if (graphIndex.luceneIndex == null) {
                // Synchronously lazy-initialize the Lucene index
                graphIndex.luceneIndex = new LuceneIndex(graphIndex, false);
            }
            index = graphIndex.luceneIndex;
        }
    }

    @GET
    public Response textSearch (@QueryParam("query") String query) {
        return Response.status(Response.Status.OK).entity(index.query(query)).build();
    }

}
TOP

Related Classes of org.opentripplanner.index.GeocoderResource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.