У меня есть другой проект, полнотекстовый поиск тоже, но я получил ошибки во время выполнения. Ниже показаны ошибки:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.lucene.document.Field.<init>(Ljava/lang/String;Ljava/lang/String;Lorg/apache/lucene/index/IndexableFieldType;)V
at org.apache.jena.query.text.TextIndexLucene.doc(TextIndexLucene.java:347)
at org.apache.jena.query.text.TextIndexLucene.addDocument(TextIndexLucene.java:308)
at org.apache.jena.query.text.TextIndexLucene.addEntity(TextIndexLucene.java:300)
at org.apache.jena.query.text.TextDocProducerTriples.change(TextDocProducerTriples.java:71)
at org.apache.jena.sparql.core.DatasetGraphMonitor.record(DatasetGraphMonitor.java:194)
at org.apache.jena.sparql.core.DatasetGraphMonitor.add$(DatasetGraphMonitor.java:114)
at org.apache.jena.sparql.core.DatasetGraphMonitor.add(DatasetGraphMonitor.java:108)
at org.apache.jena.sparql.core.GraphView.performAdd(GraphView.java:149)
at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:184)
at org.apache.jena.riot.system.StreamRDFLib$ParserOutputGraph.triple(StreamRDFLib.java:181)
at org.apache.jena.riot.lang.LangTurtle.emit(LangTurtle.java:57)
at org.apache.jena.riot.lang.LangTurtleBase.emitTriple(LangTurtleBase.java:486)
at org.apache.jena.riot.lang.LangTurtleBase.objectList(LangTurtleBase.java:352)
at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectItem(LangTurtleBase.java:288)
at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectList(LangTurtleBase.java:269)
at org.apache.jena.riot.lang.LangTurtleBase.triples(LangTurtleBase.java:250)
at org.apache.jena.riot.lang.LangTurtleBase.triplesSameSubject(LangTurtleBase.java:191)
at org.apache.jena.riot.lang.LangTurtle.oneTopLevelElement(LangTurtle.java:46)
at org.apache.jena.riot.lang.LangTurtleBase.runParser(LangTurtleBase.java:91)
at org.apache.jena.riot.lang.LangBase.parse(LangBase.java:41)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:191)
at org.apache.jena.riot.RDFParser.read(RDFParser.java:352)
at org.apache.jena.riot.RDFParser.parseURI(RDFParser.java:321)
at org.apache.jena.riot.RDFParser.parse(RDFParser.java:295)
at org.apache.jena.riot.RDFParserBuilder.parse(RDFParserBuilder.java:506)
at org.apache.jena.riot.RDFDataMgr.parseFromURI(RDFDataMgr.java:890)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:221)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:102)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:93)
at main.Search.loadData(Search.java:103)
at main.Search.main(Search.java:50)
Я пытаюсь включить org.apache.lucene.document.Field
в мою Lucene Lib, но она не работает. Я думаю, что это может быть проблема в loadData
в моих кодах. Полные коды ниже:
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.");
}}
Могу я получить совет? Спасибо