に私はのGeode領域上に作成されたLucene
インデックスにインデックスにいくつかの地理空間データをしようとしています、とLucene's LatLonPoint
クラス・クエリ・メソッド(のようなnewDistanceQuery
またはnewPolygonQuery
方法)でこれらの件のデータにクエリを実行します。アプリケーションを実行すると、一度正しい結果を返しますが、私は二度目のコードを実行すると、私は次の例外を取得:はApache LuceneのLatLonPointクエリのGeode
Server.java
public class Server {
final static Logger _logger = LoggerFactory.getLogger(Server.class);
public static void main(String[] args) throws InterruptedException {
startServer();
}
/** Start a Geode Cache Server with a locator */
public static void startServer() throws InterruptedException {
ServerLauncher serverLauncher = new ServerLauncher.Builder()
.setMemberName("server1")
.setServerPort(40404)
.set("start-locator", "127.0.0.1[10334]")
.set("jmx-manager", "true")
.set("jmx-manager-start", "true")
.build();
ServerLauncher.ServerState state = serverLauncher.start();
_logger.info(state.toString());
Cache cache = new CacheFactory().create();
createLuceneIndex(cache);
cache.createRegionFactory(RegionShortcut.PARTITION).create("locationsRegion");
}
/** Create a Lucene Index with given cache */
public static void createLuceneIndex(Cache cache) throws InterruptedException {
LuceneService luceneService = LuceneServiceProvider.get(cache);
luceneService.createIndexFactory()
.addField("NAME")
.addField("LOCATION")
.addField("COORDINATES")
.create("locationsIndex", "locationsRegion");
}
}
クライアント:ここ
org.apache.lucene.index.IndexNotFoundException:
no segments* file found in [email protected] lockFactory=
[email protected]: files: []
は、クラスです。 Javaの
public class Client {
private static ClientCache cache;
private static Region<Integer, Document> region;
public static void main(String[] args) throws LuceneQueryException, InterruptedException, IOException {
init();
indexFiles();
search();
}
/** Initialize the client cache and region */
private static void init() {
cache = new ClientCacheFactory()
.addPoolLocator("localhost", 10334)
.create();
if (cache != null) {
region = cache.<Integer, Document>createClientRegionFactory(
ClientRegionShortcut.CACHING_PROXY).create("locationsRegion");
} else {
throw new NullPointerException("Client cache is null");
}
}
/** Add documents to the Lucene index */
private static void indexFiles() {
// Dummy data
List<Document> locations = Arrays.asList(
DocumentBuilder.newSampleDocument("Exastax", 40.984929, 29.133506),
DocumentBuilder.newSampleDocument("Galata Tower", 41.025826, 28.974378),
DocumentBuilder.newSampleDocument("St. Peter and St. Paul Church", 41.024757, 28.972950));
// Standart IndexWriter initialization.
Analyzer analyzer = new StandardAnalyzer();
// Create a directory from geode region
Directory directory = RawLucene.returnRegionDirectory(cache, region, "locationsIndex");
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
IndexWriter indexWriter;
try {
indexWriter = new IndexWriter(directory, indexWriterConfig);
indexWriter.addDocuments(locations);
indexWriter.commit();
indexWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/** Search in the Lucene index */
private static void search() {
try {
DirectoryReader reader = DirectoryReader.open(RawLucene.returnRegionDirectory(cache, region, "locationsIndex"));
IndexSearcher indexSearcher = new IndexSearcher(reader);
Query query = LatLonPoint.newDistanceQuery("COORDINATES", 41.024873, 28.974346, 500);
ScoreDoc[] scoreDocs = indexSearcher.search(query, 10).scoreDocs;
for (int i = 0; i < scoreDocs.length; i++) {
Document doc = indexSearcher.doc(scoreDocs[i].doc);
System.out.println(doc.get("NAME") + " --- " + doc.get("LOCATION"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
RawLucene.java
public class RawLucene {
public static Directory returnRegionDirectory(ClientCache cache, Region region, String indexName) {
return new RegionDirectory(region,new FileSystemStats(cache.getDistributedSystem(), indexName));
}
}
DocumentBuilder.java
public class DocumentBuilder {
public static Document newSampleDocument(String name, Double lat, Double lon) {
Document document = new Document();
document.add(new StoredField("NAME", name));
document.add(new StoredField("LOCATION", lat + " " + lon));
document.add(new LatLonPoint("COORDINATES", lat, lon));
return document;
}
}
は、これは私がアプリを起動する方法です:
- 実行サーバ・クラス
- は、すべての3つのメソッド(最初の実行でクライアントクラスを実行します。正常に動作し、正しい結果を返します)
indexFiles
メソッドを呼び出さずにClientクラスを実行します。 (2回目、これは例外が発生するところです)
なぜコードは初めて正常に実行され、2回目の実行で例外がスローされるのですか?