[Original] Based on Apache Lucene's MP3 search, a few days of old songs on the machine, tested some twists and turns, after thinking that these MP3 have their own label information, why not use it? The author tries to implement it with Lucene, divided into two parts, MP3Indexer.java is created, MP3Search.jsp is a page search for MP3. Here is the code of MP3Indexer.java. Package mp3indexer; import java.io. *; import java.text. *; import java.util. *;
Import org.apache.lucene.Alysis.cjk. *; import org.apache.lucene.document. *; import org.apache.lucene.index. *;
Public class mp3indexer {public final static string mp3path = "d: // mp3"; // mp3 Sitting in PUBLIC FINAL STATIC STRING INDEXPATH = "C: // MP3Indexer"; // Index Storage Directory Public Static Void Main (String [] AROWS ClassNotFoundException, IOEXCEPTION {Try {IndexWriter Writer = New IndexWriter (IndexPath, New Cjkanalyzer (), true); IndexMP3S (Writer, New File (MP3PATH));
System.out.println ("Optimization ...."); Writer.Optimize (); Writer.Close ();
} catch (exception e) {system.out.println (E.getMessage ());}}
Public Static Void IndexMP3S (IndexWriter Writer, File File "THROWS Exception {IF (file.Indirectory ()) {string [] files = file.list (); for (int i = 0; i FileReader Freader = New FileReader (file); java.io.randomaccessfile r = new randomaccessfile (file, "r"); r.seek (file.Length () - 128); byte [] bt = new byte [127]; R.Read (bt); string labelinfo = new string (BT, "GB2312"); system.out.println (labelinfo); if (labelinfo.startswith ("tag")) {doc.add (Field.Text (" Comment ", labelinfo);} system.out.println (" [processing completion] "); R.Close (); FREADER.CLOSE (); Writer.addDocument (DOC);} // end else if} } // End Class