에 나는 오드 지역에 생성 된 Lucene
인덱스에서 인덱스에 약간의 지리 공간 데이터를 시도하고, 그리고 Lucene's LatLonPoint
클래스 쿼리 메소드 (같은 newDistanceQuery
또는 newPolygonQuery
방법) 이러한 datas에 쿼리를 실행합니다. 응용 프로그램을 실행하면 한 번 올바른 결과를 반환하지만 내가 두 번째로 코드를 실행할 때 다음과 같은 예외가 얻을 :아파치 루씬 LatLonPoint 쿼리 오드
org.apache.lucene.index.IndexNotFoundException:
no segments* file found in [email protected] lockFactory=
[email protected]: files: []
은 클래스입니다 :
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");
}
}
클라이언트. 자바
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;
}
}
이 내가 응용 프로그램을 시작하는 방법입니다
- 실행 서버 클래스
- 실행 세 가지 방법과 클라이언트 클래스 (초기 실행. 잘 작동하고 올바른 결과를 반환합니다.
indexFiles
메서드를 호출하지 않고 Client 클래스를 실행합니다. (두 번째 실행. 여기에서 예외가 발생합니다.)
코드가 처음으로 정상적으로 실행되고 두 번째 실행시 예외가 throw되는 이유는 무엇입니까?