Я работаю с Йеной и Люсеном для полнотекстового поиска. У меня проблема во время сеанса. Полная ошибка показывает:
Exception in thread "main" org.apache.jena.query.text.TextIndexException: openIndexWriter
at org.apache.jena.query.text.TextIndexLucene.openIndexWriter(TextIndexLucene.java:198)
at org.apache.jena.query.text.TextIndexLucene.<init>(TextIndexLucene.java:181)
at org.apache.jena.query.text.TextDatasetFactory.createLuceneIndex(TextDatasetFactory.java:109)
at org.apache.jena.query.text.TextDatasetFactory.createLucene(TextDatasetFactory.java:136)
at main.Search.createIndexedDataset(Search.java:95)
at main.Search.main(Search.java:53)
Caused by: org.apache.lucene.index.IndexFormatTooNewException: Format version is not supported
(resource BufferedChecksumIndexInput(SimpleFSIndexInput(path="C:\Users\Ulfa Amalia\eclipse
workspace\FullTextSearch\luceneindex\segments_1"))): 9 (needs to be between 4 and 6)
at org.apache.lucene.codecs.CodecUtil.checkHeaderNoMagic(CodecUtil.java:216)
at org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:302)
at org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:286)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:938)
at org.apache.jena.query.text.TextIndexLucene.openIndexWriter(TextIndexLucene.java:188)
... 5 more
Исходя из первой строки, я подумал, что это может быть отсутствие Jena-Text . Но после того, как я его добавил, ничего не изменилось (все равно ошибка) или, может быть, в TextDatasetFactory проблема (?), Я все еще не уверен в этом. Мои полные коды указаны ниже:
public class Search {
static String URI = "http://www.tutorialacademy.com/jenatext#";
static {LogCtl.setLog4j();
BasicConfigurator.configure();}
static Logger log = LoggerFactory.getLogger("Search");
public static void main(String ... argv)
{
TextQuery.init();
Dataset ds = createIndexedDataset("tdb", "luceneindex", "hasLongText");
loadData(ds, "res/data2.ttl");
queryData(ds);
}
public static Dataset createIndexedDataset(String tdbPath, String lucenePath, String indexedProperty)
{
Dataset graphDS = null;
if(tdbPath == null)
{
System.out.println("Construct an in-memory dataset");
graphDS = DatasetFactory.createMem();
}else
{
System.out.println("Construct a persistant TDB based dataset to: " + tdbPath);
graphDS = DatasetFactory.create();
}
//define the index mapping
EntityDefinition entDef = new EntityDefinition ("uri", "text", ResourceFactory.createProperty(URI, indexedProperty));
Directory luceneDir = null;
// check for in memory or file based (persistant) index
if (lucenePath == null)
{
System.out.println("Construct an in-memory lucene index");
luceneDir = new RAMDirectory();
}else
{
try
{
System.out.println("Construct a persistant lucene index to: " + lucenePath);
luceneDir = new SimpleFSDirectory(Paths.get(lucenePath));
}
catch (IOException e)
{
e.printStackTrace();
}
}
//create new indexed dataset: insert operations are automatically indexed with lucene
Dataset ds = TextDatasetFactory.createLucene(graphDS, luceneDir, new TextIndexConfig(entDef));
return ds;
}
public static void loadData(Dataset dataset, String file)
{
System.out.println("Load data...");
long startTime = System.currentTimeMillis();
dataset.begin(ReadWrite.WRITE);
try
{
Model m = dataset.getDefaultModel();
RDFDataMgr.read(m, file);
dataset.commit();
}
finally
{
dataset.end();
}
long finishTime = System.currentTimeMillis();
long time = finishTime - startTime;
System.out.println("Loading finished after "+ time+ " ms");
}
public static void queryData(Dataset dataset)
{
System.out.println("Query data...");
String prefix = "PREFIX ta: <" + URI + ">"+
"PREFIX text: <http://jena.apache.org/text#>";
String query = "SELECT * WHERE" +
"{ ?s text:query (ta:hasLongText 'g?eat')."+
" ?s ta.hasLongText ?text . "+
"}";
long startTime = System.currentTimeMillis();
dataset.begin(ReadWrite.READ);
try
{
Query q = QueryFactory.create(prefix + query);
QueryExecution qexec = QueryExecutionFactory.create(q,dataset);
QueryExecUtils.executeQuery(q, qexec);
}
finally
{
dataset.end();
}
long finishTime = System.currentTimeMillis();
long time = finishTime- startTime;
System.out.println("Query finished after " + time +" ms.");
}}
пожалуйста, сообщите мне. спасибо.