Search code examples
solrgeoservergeotools

Make a solr query from Geotools through geoserver


I come here because I am searching (like the title mentionned) to do a query from geotools (through geoserver) to get feature from a solr index.

To be more precise :

I saw on geoserver user manual that i can do query on solr like this in http :

http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature
&typeName=mySolrLayer
&format="xxx"
&viewparams=q:"mySolrQuery"

The important part on this URL is the viewparams that I want to use directly from geotools.

I have already test this case (this is a part of my code):

url = new URL( 
"http://localhost:8080/geoserver/wfs?request=GetCapabilities&VERSION=1.1.0"; 
);

    Map<String, String> param = new HashMap();
    params.put(WFSDataStoreFactory.URL.key, url);
    param.put("viewparams","q:myquery");
    Hints hints = new Hints();
    hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, viewParams);
    query.setHints(hints);


    ...

    featureSource.getFeatures(query);

But here, it seems to doesn't work, the url send to geoserver is a normal "GET FEATURE" request without the viewparams parameter.

I tried this with geotools-12.2 ; geotools-13.2 and geotools-15-SNAPSHOT but I didn't succeed to pass the query, geoserver send me all the feature in my database and doesn't take "viewparams" as a param.

I need to do it like this because actually the query come from another program and I would easily communicate this query to another part of the project...

If someone can help me ?


Solution

  • There doesn't currently seem to be a way to do this in the GeoTool's WFSDatastore implementations as the GetFeature request is constructed from the URL provided by the getCapabilities document. This is as the standard requires but it may be worth making a feature enhancement request to allow clients to override this string (as QGIS does for example) which would let you specify the additional parameter in your base URL which would then be passed to the server as you need.

    Unfortunately the WFS module lives in Unsupported land at present so unless you have resources to work on this issue yourself and can provide a PR to implement it there is not a great chance of it being implemented.