    public String getGeoSearchSql(final Object domainKey) {
        final String sql = ""
                    + "SELECT DISTINCT i.class_id , "
                    + "                i.object_id, "
                    + "                s.stringrep "
                    + "FROM            geom g, "
                    + "                cs_attr_object_derived i "
                    + "                LEFT OUTER JOIN cs_stringrepcache s "
                    + "                ON              ( "
                    + "                                                s.class_id =i.class_id "
                    + "                                AND             s.object_id=i.object_id "
                    + "                                ) "
                    + "WHERE           i.attr_class_id = "
                    + "                ( SELECT cs_class.id "
                    + "                FROM    cs_class "
                    + "                WHERE   cs_class.table_name::text = 'GEOM'::text "
                    + "                ) "
                    + "AND             i.attr_object_id = g.id "
                    + "AND i.class_id IN <cidsClassesInStatement> "
                    + "AND geo_field && GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>') "
                    + "AND <intersectsStatement> "
                    + "ORDER BY        1,2,3";
        final String sqlAlt = ""
                    + "\nWITH recursive derived_index(ocid,oid,acid,aid,depth) AS "
                    + "\n( SELECT class_id, "
                    + "\n        object_id, "
                    + "\n        class_id , "
                    + "\n        object_id, "
                    + "\n        0 "
                    + "\nFROM    geosuche2 "
                    + "\nWHERE   class_id IN( WITH recursive derived_child(father,child,depth) AS "
                    + "\n                    ( SELECT father, "
                    + "\n                            father , "
                    + "\n                            0 "
                    + "\n                    FROM    cs_class_hierarchy "
                    + "\n                    WHERE   father IN <cidsClassesInStatement> "
                    + "\n                     "
                    + "\n                    UNION ALL "
                    + "\n                     "
                    + "\n                    SELECT ch.father, "
                    + "\n                           ch.child , "
                    + "\n                           dc.depth+1 "
                    + "\n                    FROM   derived_child dc, "
                    + "\n                           cs_class_hierarchy ch "
                    + "\n                    WHERE  ch.father=dc.child "
                    + "\n                    ) "
                    + "\n             SELECT DISTINCT child "
                    + "\n             FROM            derived_child LIMIT 100 ) "
                    + "\nAND             geo_field && GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>') "
                    + "\nAND             intersects(geo_field,GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>')) "
                    + "\n "
                    + "\nUNION ALL "
                    + "\n "
                    + "\nSELECT aam.class_id      , "
                    + "\n       aam.object_id     , "
                    + "\n       aam.attr_class_id , "
                    + "\n       aam.attr_object_id, "
                    + "\n       di.depth+1 "
                    + "\nFROM   cs_attr_object aam, "
                    + "\n       derived_index di "
                    + "\nWHERE  aam.attr_class_id =di.ocid "
                    + "\nAND    aam.attr_object_id=di.oid "
                    + "\n) "
                    + "\nSELECT DISTINCT ocid, "
                    + "\n                oid , "
                    + "\n                stringrep "
                    + "\nFROM            derived_index "
                    + "\n                LEFT OUTER JOIN cs_stringrepcache "
                    + "\n                ON              ( "
                    + "\n                                                ocid=class_id "
                    + "\n                                AND             oid =object_id "
                    + "\n                                ) "
                    + "\nWHERE           ocid IN <cidsClassesInStatement>  LIMIT 10000000 ";
        final String intersectsStatement;
        if (searchGeometry.getSRID() == 4326) {
            intersectsStatement =
                "intersects(geo_field,GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>'))";
        } else {
            if ((searchGeometry instanceof Polygon) || (searchGeometry instanceof MultiPolygon)) {    
                intersectsStatement =
                    "intersects(st_buffer(geo_field, 0.000001),st_buffer(GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>'), 0.000001))";
            } else {                                                                                  
                intersectsStatement =
                    "intersects(st_buffer(geo_field, 0.000001),GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>'), 0.000001)";
            }
        }
        final String cidsSearchGeometryWKT = searchGeometry.toText();
        final String sridString = Integer.toString(searchGeometry.getSRID());
        final String classesInStatement = getClassesInSnippetsPerDomain().get((String)domainKey);
        if ((cidsSearchGeometryWKT == null) || (cidsSearchGeometryWKT.trim().length() == 0)
                    || (sridString == null)
                    || (sridString.trim().length() == 0)) {
            getLog().error(
                "Search geometry or srid is not given. Can't perform a search without those information.");
            return null;
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("cidsClassesInStatement=" + classesInStatement);
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("cidsSearchGeometryWKT=" + cidsSearchGeometryWKT);
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("cidsSearchGeometrySRID=" + sridString);
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("intersectsStatement=" + intersectsStatement);
        }
        if ((classesInStatement == null) || (classesInStatement.trim().length() == 0)) {
            getLog().warn("There are no search classes defined for domain '" + domainKey
                        + "'. This domain will be skipped.");
            return null;
        }
        return sql.replaceAll("<intersectsStatement>", intersectsStatement)
                    .replaceAll("<cidsClassesInStatement>", classesInStatement)
                    .replaceAll("<cidsSearchGeometryWKT>", cidsSearchGeometryWKT)
                    .replaceAll("<cidsSearchGeometrySRID>", sridString);
    }

    public String getGeoSearchSql(final Object domainKey) {
        final String sql = ""
                    + "SELECT DISTINCT i.class_id , "
                    + "                i.object_id, "
                    + "                s.stringrep "
                    + "FROM            geom g, "
                    + "                cs_attr_object_derived i "
                    + "                LEFT OUTER JOIN cs_stringrepcache s "
                    + "                ON              ( "
                    + "                                                s.class_id =i.class_id "
                    + "                                AND             s.object_id=i.object_id "
                    + "                                ) "
                    + "WHERE           i.attr_class_id = "
                    + "                ( SELECT cs_class.id "
                    + "                FROM    cs_class "
                    + "                WHERE   cs_class.table_name::text = 'GEOM'::text "
                    + "                ) "
                    + "AND             i.attr_object_id = g.id "
                    + "AND i.class_id IN <cidsClassesInStatement> "
                    + "AND geo_field && GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>') "
                    + "AND <intersectsStatement> "
                    + "ORDER BY        1,2,3";
        final String sqlAlt = ""
                    + "\nWITH recursive derived_index(ocid,oid,acid,aid,depth) AS "
                    + "\n( SELECT class_id, "
                    + "\n        object_id, "
                    + "\n        class_id , "
                    + "\n        object_id, "
                    + "\n        0 "
                    + "\nFROM    geosuche2 "
                    + "\nWHERE   class_id IN( WITH recursive derived_child(father,child,depth) AS "
                    + "\n                    ( SELECT father, "
                    + "\n                            father , "
                    + "\n                            0 "
                    + "\n                    FROM    cs_class_hierarchy "
                    + "\n                    WHERE   father IN <cidsClassesInStatement> "
                    + "\n                     "
                    + "\n                    UNION ALL "
                    + "\n                     "
                    + "\n                    SELECT ch.father, "
                    + "\n                           ch.child , "
                    + "\n                           dc.depth+1 "
                    + "\n                    FROM   derived_child dc, "
                    + "\n                           cs_class_hierarchy ch "
                    + "\n                    WHERE  ch.father=dc.child "
                    + "\n                    ) "
                    + "\n             SELECT DISTINCT child "
                    + "\n             FROM            derived_child LIMIT 100 ) "
                    + "\nAND             geo_field && GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>') "
                    + "\nAND             intersects(geo_field,GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>')) "
                    + "\n "
                    + "\nUNION ALL "
                    + "\n "
                    + "\nSELECT aam.class_id      , "
                    + "\n       aam.object_id     , "
                    + "\n       aam.attr_class_id , "
                    + "\n       aam.attr_object_id, "
                    + "\n       di.depth+1 "
                    + "\nFROM   cs_attr_object aam, "
                    + "\n       derived_index di "
                    + "\nWHERE  aam.attr_class_id =di.ocid "
                    + "\nAND    aam.attr_object_id=di.oid "
                    + "\n) "
                    + "\nSELECT DISTINCT ocid, "
                    + "\n                oid , "
                    + "\n                stringrep "
                    + "\nFROM            derived_index "
                    + "\n                LEFT OUTER JOIN cs_stringrepcache "
                    + "\n                ON              ( "
                    + "\n                                                ocid=class_id "
                    + "\n                                AND             oid =object_id "
                    + "\n                                ) "
                    + "\nWHERE           ocid IN <cidsClassesInStatement>  LIMIT 10000000 ";
        final String intersectsStatement;
        if (searchGeometry.getSRID() == 4326) {
            intersectsStatement =
                "intersects(geo_field,GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>'))";
        } else {
            if ((searchGeometry instanceof Polygon) || (searchGeometry instanceof MultiPolygon)) {    
                intersectsStatement =
                    "intersects(st_buffer(geo_field, 0.000001),st_buffer(GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>'), 0.000001))";
            } else {                                                                                  
                intersectsStatement =
                    "intersects(st_buffer(geo_field, 0.000001),GeometryFromText('SRID=<cidsSearchGeometrySRID>;<cidsSearchGeometryWKT>'))";
            }
        }
        final String cidsSearchGeometryWKT = searchGeometry.toText();
        final String sridString = Integer.toString(searchGeometry.getSRID());
        final String classesInStatement = getClassesInSnippetsPerDomain().get((String)domainKey);
        if ((cidsSearchGeometryWKT == null) || (cidsSearchGeometryWKT.trim().length() == 0)
                    || (sridString == null)
                    || (sridString.trim().length() == 0)) {
            getLog().error(
                "Search geometry or srid is not given. Can't perform a search without those information.");
            return null;
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("cidsClassesInStatement=" + classesInStatement);
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("cidsSearchGeometryWKT=" + cidsSearchGeometryWKT);
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("cidsSearchGeometrySRID=" + sridString);
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("intersectsStatement=" + intersectsStatement);
        }
        if ((classesInStatement == null) || (classesInStatement.trim().length() == 0)) {
            getLog().warn("There are no search classes defined for domain '" + domainKey
                        + "'. This domain will be skipped.");
            return null;
        }
        return sql.replaceAll("<intersectsStatement>", intersectsStatement)
                    .replaceAll("<cidsClassesInStatement>", classesInStatement)
                    .replaceAll("<cidsSearchGeometryWKT>", cidsSearchGeometryWKT)
                    .replaceAll("<cidsSearchGeometrySRID>", sridString);
    }
