Note that there are some explanatory texts on larger screens.

plurals
  1. PONo class definition found error occurs while trying to run the lucene app from command line
    primarykey
    data
    text
    <p>I'm a beginner to lucene and I had tried to run a sample app (HelloLucene.java) given in the website <a href="http://www.lucenetutorial.com/lucene-in-5-minutes.html" rel="nofollow noreferrer">http://www.lucenetutorial.com/lucene-in-5-minutes.html</a>. The code was successfully compiled and a class file (HelloLucene.class) was created for the app. </p> <p>But while trying to run the app, following error occurs </p> <ul> <li>could not find or load main class HelloLucene</li> </ul> <p>I had referred with the link <a href="https://stackoverflow.com/questions/9258005/java-program-uses-or-overrides-a-deprecated-api">Java program uses or overrides a deprecated API?</a> and tried the solutions provided, but all in vain. please help me to solve this problem.</p> <p>The command which I used to run the code is</p> <ul> <li>java HelloLucene lucene</li> </ul> <p>code which I tried to run:</p> <pre><code>import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Version; import java.io.IOException; public class HelloLucene { public static void main(String[] args) throws IOException, ParseException { // 0. Specify the analyzer for tokenizing text. // The same analyzer should be used for indexing and searching StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_35); // 1. create the index Directory index = new RAMDirectory(); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, analyzer); IndexWriter w = new IndexWriter(index, config); addDoc(w, "Lucene in Action"); addDoc(w, "Lucene for Dummies"); addDoc(w, "Managing Gigabytes"); addDoc(w, "The Art of Computer Science"); w.close(); // 2. query String querystr = args.length &gt; 0 ? args[0] : "lucene"; // the "title" arg specifies the default field to use // when no field is explicitly specified in the query. Query q = new QueryParser(Version.LUCENE_35, "title", analyzer).parse(querystr); // 3. search int hitsPerPage = 10; IndexReader reader = IndexReader.open(index); IndexSearcher searcher = new IndexSearcher(reader); TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true); searcher.search(q, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; // 4. display results System.out.println("Found " + hits.length + " hits."); for(int i=0;i&lt;hits.length;++i) { int docId = hits[i].doc; Document d = searcher.doc(docId); System.out.println((i + 1) + ". " + d.get("title")); } // searcher can only be closed when there // is no need to access the documents any more. searcher.close(); } private static void addDoc(IndexWriter w, String value) throws IOException { Document doc = new Document(); doc.add(new Field("title", value, Field.Store.YES, Field.Index.ANALYZED)); w.addDocument(doc); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload