use of org.geotoolkit.lucene.DocumentIndexer.DocumentEnvelope in project geotoolkit by Geomatys.
the class LuceneTest method fillTestData.
private static List<DocumentEnvelope> fillTestData() throws Exception {
final List<DocumentEnvelope> docs = new ArrayList<>();
final CoordinateReferenceSystem CRS3395 = CRS.forCode("EPSG:3395");
Document doc = new Document();
doc.add(new StringField("id", "point 1", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addPoint(doc, -10, 10, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "point 1 projected", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
// attention !! reprojeté
addPoint(doc, -1111475.102852225, 1113194.9079327357, CRS3395);
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "point 2", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addPoint(doc, -10, 0, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "point 3", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addPoint(doc, 0, 0, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "point 4", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addPoint(doc, 40, 20, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "point 5", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addPoint(doc, -40, 30, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 1", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, -40, -25, -50, -40, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 2", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, 5, 10, 10, 15, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 2 projected", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
// attention !! reprojeté
addBoundingBox(doc, 556597.4539663679, 1113194.9079327357, 1111475.1028522244, 1678147.5163917788, CRS3395);
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 3", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, 30, 50, 0, 15, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 4", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, -30, -15, 0, 10, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 5", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, 44.792, 51.126, -6.171, -2.28, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "line 1", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addLine(doc, 0, 0, 25, 0, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "line 1 projected", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
// attention !! reprojeté
addLine(doc, 0, 0, 2857692.6111605316, 0, CRS3395);
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "line 2", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addLine(doc, 0, 0, 0, -15, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
return docs;
}
use of org.geotoolkit.lucene.DocumentIndexer.DocumentEnvelope in project geotoolkit by Geomatys.
the class LuceneSearcherEnvelopeOnlyTest method QueryAndSpatialFilterAfterRemoveTest.
/**
* Test the combination of a String query and/or spatial filter.
* @throws java.lang.Exception
*/
@Test
public void QueryAndSpatialFilterAfterRemoveTest() throws Exception {
org.opengis.filter.Filter bboxFilter = FF.bbox(GEOMETRY_PROPERTY, -20, -20, 20, 20, "CRS:84");
SpatialQuery bboxQuery = new SpatialQuery(wrap(bboxFilter));
Set<String> results = searcher.doSearch(bboxQuery);
int nbResults = results.size();
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
// we verify that we obtain the correct results
assertEquals(nbResults, 3);
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
assertTrue(results.contains("box 2 projected"));
/*
* we remove a document
*/
final Analyzer analyzer = new StandardAnalyzer();
DocumentIndexer indexer = new DocumentIndexer(directory, null, analyzer);
indexer.removeDocument("box 2 projected");
indexer.destroy();
searcher.destroy();
searcher = new LuceneIndexSearcher(directory, null, new ClassicAnalyzer(), true);
// we perform a lucene query
results = searcher.doSearch(bboxQuery);
nbResults = results.size();
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
// we verify that we obtain the correct results
assertEquals(nbResults, 2);
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
// re-add the document
final CoordinateReferenceSystem CRS3395 = CRS.forCode("EPSG:3395");
Document doc = new Document();
doc.add(new StringField("id", "box 2 projected", Field.Store.YES));
doc.add(new StringField("docid", 66 + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
NamedEnvelope env = addBoundingBox(doc, 556597.4539663679, 1113194.9079327357, 1111475.1028522244, 1678147.5163917788, CRS3395);
// attention !! reprojeté
envelopes.put("box 2 projected", env);
indexer = new DocumentIndexer(directory, null, analyzer);
indexer.indexDocument(new DocumentEnvelope(doc, env));
indexer.destroy();
searcher.destroy();
searcher = new LuceneIndexSearcher(directory, null, new StandardAnalyzer(), true);
// we perform a lucene query
results = searcher.doSearch(bboxQuery);
nbResults = results.size();
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
// we verify that we obtain the correct results
assertEquals(nbResults, 3);
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
assertTrue(results.contains("box 2 projected"));
}
use of org.geotoolkit.lucene.DocumentIndexer.DocumentEnvelope in project geotoolkit by Geomatys.
the class LuceneEnvelopeOnlyTest method fillTestData.
private static List<DocumentEnvelope> fillTestData() throws Exception {
final List<DocumentEnvelope> docs = new ArrayList<>();
final CoordinateReferenceSystem CRS3395 = CRS.forCode("EPSG:3395");
Document doc = new Document();
doc.add(new StringField("id", "box 1", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, -40, -25, -50, -40, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 2", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, 5, 10, 10, 15, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 2 projected", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
// attention !! reprojeté
addBoundingBox(doc, 556597.4539663679, 1113194.9079327357, 1111475.1028522244, 1678147.5163917788, CRS3395);
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 3", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, 30, 50, 0, 15, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 4", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, -30, -15, 0, 10, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
doc = new Document();
doc.add(new StringField("id", "box 5", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
addBoundingBox(doc, 44.792, 51.126, -6.171, -2.28, CommonCRS.defaultGeographic());
docs.add(new DocumentEnvelope(doc, null));
return docs;
}
use of org.geotoolkit.lucene.DocumentIndexer.DocumentEnvelope in project geotoolkit by Geomatys.
the class LuceneEnvelopeOnlyTest method QueryAndSpatialFilterAfterRemoveTest.
/**
* Test the combination of a String query and/or spatial filter.
*/
@Test
public void QueryAndSpatialFilterAfterRemoveTest() throws Exception {
// we remove a document
final Analyzer analyzer = new StandardAnalyzer();
DocumentIndexer indexer = new DocumentIndexer(directory, null, analyzer);
indexer.removeDocument("box 2 projected");
indexer.destroy();
DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory);
Path firstChild = directoryStream.iterator().next();
directoryStream.close();
IndexReader reader = DirectoryReader.open(LuceneUtils.getAppropriateDirectory(firstChild));
searcher = new IndexSearcher(reader);
/*
* case 1: a normal spatial request BBOX
*/
double[] min1 = { -20, -20 };
double[] max1 = { 20, 20 };
GeneralEnvelope bbox = new GeneralEnvelope(min1, max1);
bbox.setCoordinateReferenceSystem(CommonCRS.defaultGeographic());
org.opengis.filter.Filter bboxFilter = FF.bbox(GEOMETRY_PROPERTY, -20, -20, 20, 20, "CRS:84");
SpatialQuery bboxQuery = new SpatialQuery(wrap(bboxFilter));
BooleanQuery serialQuery = new BooleanQuery.Builder().add(bboxQuery.getQuery(), BooleanClause.Occur.MUST).add(simpleQuery, BooleanClause.Occur.MUST).build();
// we perform a lucene query
TopDocs docs = searcher.search(serialQuery, 15);
TotalHits nbResults = docs.totalHits;
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
List<String> results = new ArrayList<>();
for (int i = 0; i < nbResults.value; i++) {
Document doc = searcher.doc(docs.scoreDocs[i].doc);
String name = doc.get("id");
results.add(name);
LOGGER.log(Level.FINER, "\tid: {0}", name);
}
// we verify that we obtain the correct results
assertEquals(2, nbResults.value);
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
// re-add the document
final CoordinateReferenceSystem CRS3395 = CRS.forCode("EPSG:3395");
Document docu = new Document();
docu.add(new StringField("id", "box 2 projected", Field.Store.YES));
docu.add(new StringField("docid", 66 + "", Field.Store.YES));
docu.add(new StringField("metafile", "doc", Field.Store.YES));
// attention !! reprojeté
addBoundingBox(docu, 556597.4539663679, 1113194.9079327357, 1111475.1028522244, 1678147.5163917788, CRS3395);
indexer = new DocumentIndexer(directory, null, analyzer);
indexer.indexDocument(new DocumentEnvelope(docu, null));
indexer.destroy();
directoryStream = Files.newDirectoryStream(directory);
firstChild = directoryStream.iterator().next();
directoryStream.close();
reader = DirectoryReader.open(LuceneUtils.getAppropriateDirectory(firstChild));
searcher = new IndexSearcher(reader);
// we perform a lucene query
docs = searcher.search(serialQuery, 15);
nbResults = docs.totalHits;
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
results = new ArrayList<>();
for (int i = 0; i < nbResults.value; i++) {
Document doc = searcher.doc(docs.scoreDocs[i].doc);
String name = doc.get("id");
results.add(name);
LOGGER.log(Level.FINER, "\tid: {0}", name);
}
// we verify that we obtain the correct results
assertEquals(3, nbResults.value);
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
assertTrue(results.contains("box 2 projected"));
}
use of org.geotoolkit.lucene.DocumentIndexer.DocumentEnvelope in project geotoolkit by Geomatys.
the class LuceneSearcherEnvelopeOnlyTest method fillTestData.
private static List<DocumentEnvelope> fillTestData() throws Exception {
final List<DocumentEnvelope> docs = new ArrayList<>();
final CoordinateReferenceSystem CRS3395 = CRS.forCode("EPSG:3395");
Document doc = new Document();
doc.add(new StringField("id", "box 1", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
NamedEnvelope env = addBoundingBox(doc, -40, -25, -50, -40, CommonCRS.defaultGeographic());
envelopes.put("box 1", env);
docs.add(new DocumentEnvelope(doc, env));
doc = new Document();
doc.add(new StringField("id", "box 2", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
env = addBoundingBox(doc, 5, 10, 10, 15, CommonCRS.defaultGeographic());
envelopes.put("box 2", env);
docs.add(new DocumentEnvelope(doc, env));
doc = new Document();
doc.add(new StringField("id", "box 2 projected", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
env = addBoundingBox(doc, 556597.4539663679, 1113194.9079327357, 1111475.1028522244, 1678147.5163917788, CRS3395);
// attention !! reprojeté
envelopes.put("box 2 projected", env);
docs.add(new DocumentEnvelope(doc, env));
doc = new Document();
doc.add(new StringField("id", "box 3", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
env = addBoundingBox(doc, 30, 50, 0, 15, CommonCRS.defaultGeographic());
envelopes.put("box 3", env);
docs.add(new DocumentEnvelope(doc, env));
doc = new Document();
doc.add(new StringField("id", "box 4", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
env = addBoundingBox(doc, -30, -15, 0, 10, CommonCRS.defaultGeographic());
envelopes.put("box 4", env);
docs.add(new DocumentEnvelope(doc, env));
doc = new Document();
doc.add(new StringField("id", "box 5", Field.Store.YES));
doc.add(new StringField("docid", docs.size() + "", Field.Store.YES));
doc.add(new StringField("metafile", "doc", Field.Store.YES));
env = addBoundingBox(doc, 44.792, 51.126, -6.171, -2.28, CommonCRS.defaultGeographic());
envelopes.put("box 5", env);
docs.add(new DocumentEnvelope(doc, env));
return docs;
}
Aggregations