Skip to content

Commit

Permalink
Fix spatial search not working with shapefile sometimes (geonetwork#2516
Browse files Browse the repository at this point in the history
)

* Spatial search not working when using ShapefileDataStore after a while. Disable usage of fix index.

* Remove spatialindex folder created on startup which is never used. Spatial index is created on index folder next to Lucene one.
  • Loading branch information
fxprunayre authored and josegar74 committed Mar 14, 2018
1 parent d2b7fdd commit 0e3973c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class GeonetworkDataDirectory {
private Path webappDir;
private Path systemDataDir;
private Path luceneDir;
private Path spatialIndexPath;
private Path configDir;
private Path thesauriDir;
private Path schemaPluginsDir;
Expand Down Expand Up @@ -292,8 +291,6 @@ private Path setDataDirectory(JeevesServlet jeevesServlet, String webappName,
// Set subfolder data directory
luceneDir = setDir(jeevesServlet, webappName, handlerConfig, luceneDir, ".lucene" + KEY_SUFFIX,
Geonet.Config.LUCENE_DIR, "index");
spatialIndexPath = setDir(jeevesServlet, "", handlerConfig, spatialIndexPath, "spatial" + KEY_SUFFIX,
null, "spatialindex");

configDir = setDir(jeevesServlet, webappName, handlerConfig, configDir, ".config" + KEY_SUFFIX,
Geonet.Config.CONFIG_DIR, "config");
Expand Down Expand Up @@ -531,24 +528,6 @@ public void setLuceneDir(Path luceneDir) {
this.luceneDir = luceneDir;
}

/**
* Get the directory to store the metadata spatial index. If the spatial index is to be stored
* locally this is the directory to use.
*
* @return the directory to store the metadata spatial index
*/
public Path getSpatialIndexPath() {
return spatialIndexPath;
}

/**
* Set the directory to store the metadata spatial index. If the spatial index is to be stored
* locally this is the directory to use.
*/
public void setSpatialIndexPath(Path spatialIndexPath) {
this.spatialIndexPath = spatialIndexPath;
}

/**
* Return the directory containing the configuration file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void testInit() throws Exception {
dataDirectory.setSystemDataDir(null);
dataDirectory.setConfigDir(null);
dataDirectory.setLuceneDir(null);
dataDirectory.setSpatialIndexPath(null);
dataDirectory.setMetadataDataDir(null);
dataDirectory.setMetadataRevisionDir(null);
dataDirectory.setResourcesDir(null);
Expand All @@ -81,7 +80,6 @@ private void assertSystemDirSubFolders(Path expectedDataDir) {
final Path expectedConfigDir = expectedDataDir.resolve("config");
assertEquals(expectedConfigDir, dataDirectory.getConfigDir());
assertEquals(expectedDataDir.resolve("index"), dataDirectory.getLuceneDir());
assertEquals(expectedDataDir.resolve("spatialindex"), dataDirectory.getSpatialIndexPath());
assertEquals(expectedDataDir.resolve("data").resolve("metadata_data"), dataDirectory.getMetadataDataDir());
assertEquals(expectedDataDir.resolve("data").resolve("metadata_subversion"), dataDirectory.getMetadataRevisionDir());
final Path expectedResourcesDir = expectedDataDir.resolve("data").resolve("resources");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,11 @@ private void loadIndexInfo(ServiceContext context) throws IOException {
final GeonetworkDataDirectory dataDirectory = context.getBean(GeonetworkDataDirectory.class);
Path luceneDir = dataDirectory.getLuceneDir();
indexProperties.put("index.path", luceneDir.toAbsolutePath().normalize().toString());
Path lDir = dataDirectory.getSpatialIndexPath();
if (Files.exists(luceneDir)) {
long size = ApiUtils.sizeOfDirectory(luceneDir);
indexProperties.put("index.size", "" + size); // lucene + Shapefile
// if exist
}

if (Files.exists(lDir)) {
long size = ApiUtils.sizeOfDirectory(lDir);
indexProperties.put("index.size.lucene", "" + size);
}
indexProperties.put("index.lucene.config", context.getBean(LuceneConfig.class).toString());
}

Expand Down Expand Up @@ -239,6 +233,6 @@ private void loadVersionInfo(ServiceContext context) {

} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,12 @@ private void loadIndexInfo(ServiceContext context) throws IOException {
final GeonetworkDataDirectory dataDirectory = context.getBean(GeonetworkDataDirectory.class);
Path luceneDir = dataDirectory.getLuceneDir();
indexProperties.put("index.path", luceneDir.toAbsolutePath().normalize().toString());
Path lDir = dataDirectory.getSpatialIndexPath();
if (Files.exists(luceneDir)) {
long size = sizeOfDirectory(luceneDir) / 1024;
indexProperties.put("index.size", "" + size); // lucene + Shapefile
// if exist
}

if (Files.exists(lDir)) {
long size = sizeOfDirectory(lDir) / 1024;
indexProperties.put("index.size.lucene", "" + size);
}
indexProperties.put("index.lucene.config", context.getBean(LuceneConfig.class).toString());
}

Expand Down
4 changes: 4 additions & 0 deletions web/src/main/java/org/fao/geonet/Geonetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ private DataStore createShapefileDatastore(String indexDir) throws Exception {
logger.info("Using shapefile " + file.getAbsolutePath());
}
ShapefileDataStore ids = new ShapefileDataStore(file.toURI().toURL());
// It looks like we're facing this issue
// https://osgeo-org.atlassian.net/browse/GEOT-5830
// And spatial search does not return any results.
ids.setFidIndexed(false);
ids.setNamespaceURI("http://geonetwork.org");
ids.setMemoryMapped(false);
ids.setCharset(Charset.forName(Constants.ENCODING));
Expand Down

0 comments on commit 0e3973c

Please sign in to comment.