[mb-commits] r12190 - in search_server/branches/ngs/index/src: main/java/org/musicbrainz/search/index test/java/org/musicbrainz/search/index
root at musicbrainz.org
root at musicbrainz.org
Fri Oct 9 14:51:53 UTC 2009
Author: ijabz
Date: 2009-10-09 14:51:53 +0000 (Fri, 09 Oct 2009)
New Revision: 12190
Modified:
search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationIndex.java
search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationType.java
search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AbstractIndexTest.java
search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AnnotationIndexTest.java
Log:
Basic Support for building annotation index from NGS db
Modified: search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationIndex.java
===================================================================
--- search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationIndex.java 2009-10-09 10:15:29 UTC (rev 12189)
+++ search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationIndex.java 2009-10-09 14:51:53 UTC (rev 12190)
@@ -10,8 +10,6 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
-import org.musicbrainz.search.analysis.StandardUnaccentAnalyzer;
public class AnnotationIndex extends Index {
@@ -37,38 +35,135 @@
public void indexData(IndexWriter indexWriter, int min, int max)
throws SQLException, IOException {
- for(AnnotationType type : AnnotationType.values()) {
- indexDataByType(indexWriter, min, max, type);
+ indexArtistData(indexWriter,min,max);
+ indexLabelData(indexWriter,min,max);
+ indexRecordingData(indexWriter,min,max);
+ indexReleaseData(indexWriter,min,max);
+ indexReleaseGroupData(indexWriter,min,max);
+ }
+
+ protected void indexArtistData(IndexWriter indexWriter, int min, int max)
+ throws SQLException, IOException {
+ PreparedStatement st = dbConnection.prepareStatement(
+
+ "select at.gid,a.text,an.name " +
+ "from annotation a " +
+ "inner join artist_annotation aa on a.id=aa.annotation " +
+ "inner join (select distinct aa2.artist as id,max(created) as created_date from annotation a2 " +
+ " inner join artist_annotation aa2 on a2.id=aa2.annotation group by aa2.artist) AS last_ann " +
+ "on aa.artist=last_ann.id " +
+ "and a.created=last_ann.created_date " +
+ "inner join artist at on aa.artist=at.id " +
+ "inner join artist_name an on at.name=an.id " +
+ "where a.id between ? and ? " );
+ st.setInt(1, min);
+ st.setInt(2, max);
+ ResultSet rs = st.executeQuery();
+ while (rs.next()) {
+ indexWriter.addDocument(documentFromResultSet(rs,AnnotationType.ARTIST));
}
- }
+ st.close();
+ }
- protected void indexDataByType(IndexWriter indexWriter, int min, int max, AnnotationType type)
+ protected void indexLabelData(IndexWriter indexWriter, int min, int max)
throws SQLException, IOException {
- String entityTable = type.getName().equals("release") ? "album" : type.getName();
+ PreparedStatement st = dbConnection.prepareStatement(
- PreparedStatement st = dbConnection.prepareStatement(
- "SELECT ? as type, e.gid, e.name, ann.text " +
- "FROM annotation ann " +
- "JOIN (SELECT type, rowid, max(moderation) as last_moderation FROM annotation GROUP BY type, rowid) as last_ann " +
- " ON ann.rowid = last_ann.rowid AND ann.type = last_ann.type AND ann.moderation = last_ann.last_moderation " +
- "JOIN " + entityTable + " as e ON (ann.rowid = e.id) " +
- "WHERE ann.type = ? AND ann.id BETWEEN ? AND ?");
- st.setString(1, type.getName());
- st.setInt(2, type.getDbId());
- st.setInt(3, min);
- st.setInt(4, max);
+ "select r.gid,a.text,rn.name " +
+ "from annotation a " +
+ "inner join label_annotation ra on a.id=ra.annotation " +
+ "inner join (select distinct ra2.label as id,max(created) as created_date from annotation a2 " +
+ " inner join label_annotation ra2 on a2.id=ra2.annotation group by ra2.label) AS last_ann " +
+ "on ra.label=last_ann.id " +
+ "and a.created=last_ann.created_date " +
+ "inner join label r on ra.label=r.id " +
+ "inner join label_name rn on r.name=rn.id " +
+ "where a.id between ? and ? " );
+ st.setInt(1, min);
+ st.setInt(2, max);
ResultSet rs = st.executeQuery();
while (rs.next()) {
- indexWriter.addDocument(documentFromResultSet(rs));
+ indexWriter.addDocument(documentFromResultSet(rs,AnnotationType.LABEL));
}
st.close();
- }
+ }
- public Document documentFromResultSet(ResultSet rs) throws SQLException {
+ protected void indexRecordingData(IndexWriter indexWriter, int min, int max)
+ throws SQLException, IOException {
+ PreparedStatement st = dbConnection.prepareStatement(
+
+ "select r.gid,a.text,rn.name " +
+ "from annotation a " +
+ "inner join recording_annotation ra on a.id=ra.annotation " +
+ "inner join (select distinct ra2.recording as id,max(created) as created_date from annotation a2 " +
+ " inner join recording_annotation ra2 on a2.id=ra2.annotation group by ra2.recording) AS last_ann " +
+ "on ra.recording=last_ann.id " +
+ "and a.created=last_ann.created_date " +
+ "inner join recording r on ra.recording=r.id " +
+ "inner join track_name rn on r.name=rn.id " +
+ "where a.id between ? and ? " );
+ st.setInt(1, min);
+ st.setInt(2, max);
+ ResultSet rs = st.executeQuery();
+ while (rs.next()) {
+ System.out.println("adding record");
+ indexWriter.addDocument(documentFromResultSet(rs,AnnotationType.TRACK));
+ }
+ st.close();
+ }
+
+
+ protected void indexReleaseData(IndexWriter indexWriter, int min, int max)
+ throws SQLException, IOException {
+ PreparedStatement st = dbConnection.prepareStatement(
+
+ "select r.gid,a.text,rn.name " +
+ "from annotation a " +
+ "inner join release_annotation ra on a.id=ra.annotation " +
+ "inner join (select distinct ra2.release as id,max(created) as created_date from annotation a2 " +
+ " inner join release_annotation ra2 on a2.id=ra2.annotation group by ra2.release) AS last_ann " +
+ "on ra.release=last_ann.id " +
+ "and a.created=last_ann.created_date " +
+ "inner join release r on ra.release=r.id " +
+ "inner join release_name rn on r.name=rn.id " +
+ "where a.id between ? and ? " );
+ st.setInt(1, min);
+ st.setInt(2, max);
+ ResultSet rs = st.executeQuery();
+ while (rs.next()) {
+ indexWriter.addDocument(documentFromResultSet(rs,AnnotationType.RELEASE));
+ }
+ st.close();
+ }
+
+ protected void indexReleaseGroupData(IndexWriter indexWriter, int min, int max)
+ throws SQLException, IOException {
+ PreparedStatement st = dbConnection.prepareStatement(
+
+ "select r.gid,a.text,rn.name " +
+ "from annotation a " +
+ "inner join release_group_annotation ra on a.id=ra.annotation " +
+ "inner join (select ra2.release_group as id,max(created) as created_date from annotation a2 " +
+ " inner join release_group_annotation ra2 on a2.id=ra2.annotation group by ra2.release_group) AS last_ann " +
+ "on ra.release_group=last_ann.id " +
+ "and a.created=last_ann.created_date " +
+ "inner join release_group r on ra.release_group=r.id " +
+ "inner join release_name rn on r.name=rn.id " +
+ "where a.id between ? and ? " );
+ st.setInt(1, min);
+ st.setInt(2, max);
+ ResultSet rs = st.executeQuery();
+ while (rs.next()) {
+ indexWriter.addDocument(documentFromResultSet(rs,AnnotationType.RELEASE_GROUP));
+ }
+ st.close();
+ }
+
+ public Document documentFromResultSet(ResultSet rs,AnnotationType type) throws SQLException {
Document doc = new Document();
addFieldToDocument(doc, AnnotationIndexField.MBID, rs.getString("gid"));
addFieldToDocument(doc, AnnotationIndexField.NAME, rs.getString("name"));
- addFieldToDocument(doc, AnnotationIndexField.TYPE, rs.getString("type"));
+ addFieldToDocument(doc, AnnotationIndexField.TYPE, type.getName());
addFieldToDocument(doc, AnnotationIndexField.TEXT, rs.getString("text"));
return doc;
Modified: search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationType.java
===================================================================
--- search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationType.java 2009-10-09 10:15:29 UTC (rev 12189)
+++ search_server/branches/ngs/index/src/main/java/org/musicbrainz/search/index/AnnotationType.java 2009-10-09 14:51:53 UTC (rev 12190)
@@ -24,7 +24,10 @@
ARTIST(1, "artist"),
RELEASE(2, "release"),
LABEL(3, "label"),
- TRACK(4, "track"),;
+ TRACK(4, "track"), //TODO need track for V1 but maybe recording for V2
+ RELEASE_GROUP(5,"releasegroup"),
+ WORK(6,"work"),
+ ;
private Integer dbId;
private String name;
Modified: search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AbstractIndexTest.java
===================================================================
--- search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AbstractIndexTest.java 2009-10-09 10:15:29 UTC (rev 12189)
+++ search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AbstractIndexTest.java 2009-10-09 14:51:53 UTC (rev 12190)
@@ -61,6 +61,12 @@
stmt.addBatch("DROP TABLE recording");
stmt.addBatch("DROP TABLE annotation");
+ stmt.addBatch("DROP TABLE artist_annotation");
+ stmt.addBatch("DROP TABLE label_annotation");
+ stmt.addBatch("DROP TABLE recording_annotation");
+ stmt.addBatch("DROP TABLE release_annotation");
+ stmt.addBatch("DROP TABLE release_group_annotation");
+ stmt.addBatch("DROP TABLE work_annotation");
stmt.executeBatch();
stmt.close();
@@ -360,19 +366,60 @@
}
protected void setupAnnotationTables(Statement stmt) throws Exception {
- stmt.addBatch("CREATE TABLE annotation" +
+ stmt.addBatch(
+ "CREATE TABLE annotation" +
"(" +
- " id serial NOT NULL," +
- " moderator integer NOT NULL," +
- " type smallint NOT NULL," +
- " rowid integer NOT NULL," +
- " text varchar(1000)," +
- " changelog character varying(255)," +
+ " id serial NOT NULL, " +
+ " editor integer NOT NULL," +
+ " text text," +
+ " changelog character varying(255), " +
" created timestamp," +
- " moderation integer NOT NULL DEFAULT 0," +
- " modpending integer NOT NULL DEFAULT 0" +
+ " CONSTRAINT annotation_pkey PRIMARY KEY (id))" );
+
+
+ stmt.addBatch("CREATE TABLE artist_annotation" +
+ "(" +
+ " artist integer NOT NULL," +
+ " annotation integer NOT NULL," +
+ " CONSTRAINT artist_annotation_pkey PRIMARY KEY (artist, annotation)" +
")");
+
+ stmt.addBatch("CREATE TABLE label_annotation" +
+ "(" +
+ " label integer NOT NULL," +
+ " annotation integer NOT NULL," +
+ " CONSTRAINT label_annotation_pkey PRIMARY KEY (label, annotation)" +
+ ")");
+
+ stmt.addBatch("CREATE TABLE recording_annotation" +
+ "(" +
+ " recording integer NOT NULL," +
+ " annotation integer NOT NULL," +
+ " CONSTRAINT recording_annotation_pkey PRIMARY KEY (recording, annotation)" +
+ ")");
+ stmt.addBatch("CREATE TABLE release_annotation" +
+ "(" +
+ " release integer NOT NULL," +
+ " annotation integer NOT NULL," +
+ " CONSTRAINT release_annotation_pkey PRIMARY KEY (release, annotation)" +
+ ")");
+
+ stmt.addBatch("CREATE TABLE release_group_annotation" +
+ "(" +
+ " release_group integer NOT NULL," +
+ " annotation integer NOT NULL," +
+ " CONSTRAINT release_group_annotation_pkey PRIMARY KEY (release_group, annotation)" +
+ ")");
+
+ stmt.addBatch("CREATE TABLE work_annotation" +
+ "(" +
+ " work integer NOT NULL," +
+ " annotation integer NOT NULL," +
+ " CONSTRAINT work_annotation_pkey PRIMARY KEY (work, annotation)" +
+ ")");
+
+
}
Modified: search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AnnotationIndexTest.java
===================================================================
--- search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AnnotationIndexTest.java 2009-10-09 10:15:29 UTC (rev 12189)
+++ search_server/branches/ngs/index/src/test/java/org/musicbrainz/search/index/AnnotationIndexTest.java 2009-10-09 14:51:53 UTC (rev 12190)
@@ -39,31 +39,127 @@
Statement stmt = conn.createStatement();
+ stmt.addBatch("INSERT INTO release_name(id,name, refcount)VALUES (1, 'Crocodiles', 0)");
+ stmt.addBatch("INSERT INTO release_name(id,name, refcount)VALUES (2, 'Crocodiles (bonus disc)', 0)");
+ stmt.addBatch("INSERT INTO release(id, gid, name, artist_credit, release_group, status, packaging,country, " +
+ "language, script, date_year, date_month, date_day,barcode, comment, editpending) " +
+ " VALUES (491240,'c3b8dbc9-c1ff-4743-9015-8d762819134e', 2, 1,491240,1,1,1,1, 1, 1, 1, 1, null, null, 1)");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (1, 1, 'release annotation', 'change',now())");
+ stmt.addBatch("INSERT INTO release_annotation(release, annotation) VALUES (491240, 1)");
- stmt.addBatch("INSERT INTO annotation(" +
- " id, moderator, type, rowid, text, changelog, created, moderation,modpending)" +
- " VALUES (1, 51298, 2, 66, 'Formed in Oxford, UK.', 'test',null, 176097, 0)");
- /* stmt.addBatch("INSERT INTO album(" +
- " id, artist, name, gid, modpending, page, language," +
- " script, modpending_lang, quality, modpending_qual, release_group)" +
- " VALUES (66, 16153, 'Crocodiles (bonus disc)', 'c3b8dbc9-c1ff-4743-9015-8d762819134e', 0, 154669573, 120, " +
- " 28, null, -1, 0, 491240)");
- */
+ stmt.executeBatch();
+ stmt.close();
+ conn.close();
+ }
+ /**
+ * @throws Exception
+ */
+ private void addAnnotationTwo() throws Exception {
+ Connection conn = createConnection();
+ conn.setAutoCommit(true);
+
+ Statement stmt = conn.createStatement();
+
+ stmt.addBatch("INSERT INTO release_name(id,name, refcount)VALUES (1, 'Crocodiles', 0)");
+ stmt.addBatch("INSERT INTO release_name(id,name, refcount)VALUES (2, 'Crocodiles (bonus disc)', 0)");
+ stmt.addBatch("INSERT INTO release_group( id, gid,name,artist_credit,type,comment,editpending)" +
+ " VALUES (491240, 'efd2ace2-b3b9-305f-8a53-9803595c0e37', 1, 1, 2, null, 0)");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (1, 1, 'release group annotation', 'change',now())");
+ stmt.addBatch("INSERT INTO release_group_annotation(release_group, annotation) VALUES (491240, 1)");
+
+
stmt.executeBatch();
stmt.close();
conn.close();
}
+ /**
+ * @throws Exception
+ */
+ private void addAnnotationThree() throws Exception {
+ Connection conn = createConnection();
+ conn.setAutoCommit(true);
+
+ Statement stmt = conn.createStatement();
+
+ stmt.addBatch("INSERT INTO artist_type(id,name)VALUES (1, 'Person');");
+ stmt.addBatch("INSERT INTO artist_type(id,name)VALUES (2, 'Group');");
+ stmt.addBatch("INSERT INTO artist_name(id,name,refcount) values (1,'Farming Incident',1)");
+ stmt.addBatch("INSERT INTO artist(id,name, gid, sortname,comment, begindate_year,begindate_month,enddate_year,type,editpending)" +
+ " VALUES (521316,1, '4302e264-1cf0-4d1f-aca7-2a6f89e34b36',1,null, 1999,4, null, 2, 0)");
+
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (1, 1, 'artist annotation', 'change',now())");
+ stmt.addBatch("INSERT INTO artist_annotation(artist, annotation) VALUES (521316, 1)");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (2, 1, 'artist annotation newer', 'change',now()+1)");
+ stmt.addBatch("INSERT INTO artist_annotation(artist, annotation) VALUES (521316, 2)");
+
+
+ stmt.executeBatch();
+ stmt.close();
+ conn.close();
+ }
+
+ /**
+ * @throws Exception
+ */
+ private void addAnnotationFour() throws Exception {
+ Connection conn = createConnection();
+ conn.setAutoCommit(true);
+
+ Statement stmt = conn.createStatement();
+
+ stmt.addBatch("INSERT INTO label_name (id, name) VALUES (1, '4AD')");
+ stmt.addBatch("INSERT INTO label_name (id, name) VALUES (2, '4AD US')");
+ stmt.addBatch("INSERT INTO label_type (id, name) VALUES (4, 'Original Production')");
+
+ stmt.addBatch("INSERT INTO label(id, gid, name, sortname, type, labelcode, country, comment, " +
+ " begindate_year, begindate_month, begindate_day, enddate_year, enddate_month, enddate_day) " +
+ "VALUES (1, 'a539bb1e-f2e1-4b45-9db8-8053841e7503', 1, 1, 4, 5807, null, null, " +
+ " 1979, null, null, null, null, null)");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (1, 1, 'label annotation', 'change',now())");
+ stmt.addBatch("INSERT INTO label_annotation(label, annotation) VALUES (1, 1)");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (2, 1, 'label annotation newer', 'change',now() + 1)");
+ stmt.addBatch("INSERT INTO label_annotation(label, annotation) VALUES (1, 2)");
+
+
+ stmt.executeBatch();
+ stmt.close();
+ conn.close();
+ }
+
+ /**
+ * @throws Exception
+ */
+ private void addAnnotationFive() throws Exception {
+ Connection conn = createConnection();
+ conn.setAutoCommit(true);
+
+ Statement stmt = conn.createStatement();
+
+
+ stmt.addBatch("INSERT INTO recording(id, gid, name, artist_credit, length, comment, editpending)"
+ + "VALUES (1, '2f250ed2-6285-40f1-aa2a-14f1c05e9765', 1,1,33000, null,1)");
+ stmt.addBatch("INSERT INTO track_name(id, name, refcount)VALUES (1, 'Do It Clean', 1) ");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (1, 1, 'track annotation', 'change',now())");
+ stmt.addBatch("INSERT INTO recording_annotation(recording, annotation) VALUES (1, 1)");
+ stmt.addBatch("INSERT INTO annotation(id, editor, text, changelog,created) VALUES (2, 1, 'track annotation newer', 'change',now() + 1)");
+ stmt.addBatch("INSERT INTO recording_annotation(recording, annotation) VALUES (1, 2)");
+
+ stmt.executeBatch();
+ stmt.close();
+ conn.close();
+ }
+
/**
- * Basic test of all fields
+ * Basic test for Release Annotation
*
* @throws Exception
*/
- /*
- public void testIndexAnnotationFields() throws Exception {
+
+ public void testReleaseIndexAnnotationFields() throws Exception {
addAnnotationOne();
RAMDirectory ramDir = new RAMDirectory();
createIndex(ramDir);
@@ -77,15 +173,129 @@
assertEquals(1, doc.getFields(AnnotationIndexField.NAME.getName()).length);
assertEquals("Crocodiles (bonus disc)", doc.getField(AnnotationIndexField.NAME.getName()).stringValue());
assertEquals(1, doc.getFields(AnnotationIndexField.TEXT.getName()).length);
- assertEquals("Formed in Oxford, UK.", doc.getField(AnnotationIndexField.TEXT.getName()).stringValue());
+ assertEquals("release annotation", doc.getField(AnnotationIndexField.TEXT.getName()).stringValue());
assertEquals(1, doc.getFields(AnnotationIndexField.TYPE.getName()).length);
assertEquals("release", doc.getField(AnnotationIndexField.TYPE.getName()).stringValue());
}
ir.close();
}
- */
-
+
+
+
+ /**
+ * Basic test for Release Group Annotation
+ *
+ * @throws Exception
+ */
+
+ public void testReleaseGroupIndexAnnotationFields() throws Exception {
+ addAnnotationTwo();
+ RAMDirectory ramDir = new RAMDirectory();
+ createIndex(ramDir);
+
+ IndexReader ir = IndexReader.open(ramDir, true);
+ assertEquals(1, ir.numDocs());
+ {
+ Document doc = ir.document(0);
+ assertEquals(1, doc.getFields(AnnotationIndexField.MBID.getName()).length);
+ assertEquals("efd2ace2-b3b9-305f-8a53-9803595c0e37", doc.getField(AnnotationIndexField.MBID.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.NAME.getName()).length);
+ assertEquals("Crocodiles", doc.getField(AnnotationIndexField.NAME.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TEXT.getName()).length);
+ assertEquals("release group annotation", doc.getField(AnnotationIndexField.TEXT.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TYPE.getName()).length);
+ assertEquals("releasegroup", doc.getField(AnnotationIndexField.TYPE.getName()).stringValue());
+
+ }
+ ir.close();
+ }
+
+ /**
+ * Basic test for Artist Annotation
+ *
+ * @throws Exception
+ */
+
+ public void testArtistIndexAnnotationFields() throws Exception {
+ addAnnotationThree();
+ RAMDirectory ramDir = new RAMDirectory();
+ createIndex(ramDir);
+
+ IndexReader ir = IndexReader.open(ramDir, true);
+ assertEquals(1, ir.numDocs());
+ {
+ Document doc = ir.document(0);
+ assertEquals(1, doc.getFields(AnnotationIndexField.MBID.getName()).length);
+ assertEquals("4302e264-1cf0-4d1f-aca7-2a6f89e34b36", doc.getField(AnnotationIndexField.MBID.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.NAME.getName()).length);
+ assertEquals("Farming Incident", doc.getField(AnnotationIndexField.NAME.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TEXT.getName()).length);
+ assertEquals("artist annotation newer", doc.getField(AnnotationIndexField.TEXT.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TYPE.getName()).length);
+ assertEquals("artist", doc.getField(AnnotationIndexField.TYPE.getName()).stringValue());
+
+ }
+ ir.close();
+ }
+
+ /**
+ * Basic test for Label Annotation
+ *
+ * @throws Exception
+ */
+
+ public void testLabelIndexAnnotationFields() throws Exception {
+ addAnnotationFour();
+ RAMDirectory ramDir = new RAMDirectory();
+ createIndex(ramDir);
+
+ IndexReader ir = IndexReader.open(ramDir, true);
+ assertEquals(1, ir.numDocs());
+ {
+ Document doc = ir.document(0);
+ assertEquals(1, doc.getFields(AnnotationIndexField.MBID.getName()).length);
+ assertEquals("a539bb1e-f2e1-4b45-9db8-8053841e7503", doc.getField(AnnotationIndexField.MBID.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.NAME.getName()).length);
+ assertEquals("4AD", doc.getField(AnnotationIndexField.NAME.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TEXT.getName()).length);
+ assertEquals("label annotation newer", doc.getField(AnnotationIndexField.TEXT.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TYPE.getName()).length);
+ assertEquals("label", doc.getField(AnnotationIndexField.TYPE.getName()).stringValue());
+
+ }
+ ir.close();
+ }
+
+ /**
+ * Basic test for Recording Annotation
+ *
+ * @throws Exception
+ */
+
+ public void testRecordingIndexAnnotationFields() throws Exception {
+ addAnnotationFive();
+ RAMDirectory ramDir = new RAMDirectory();
+ createIndex(ramDir);
+
+ IndexReader ir = IndexReader.open(ramDir, true);
+ System.out.println("NumDocs:"+ir.numDocs());
+ //assertEquals(1, ir.numDocs());
+ {
+ Document doc = ir.document(0);
+ assertEquals(1, doc.getFields(AnnotationIndexField.MBID.getName()).length);
+ assertEquals("2f250ed2-6285-40f1-aa2a-14f1c05e9765", doc.getField(AnnotationIndexField.MBID.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.NAME.getName()).length);
+ assertEquals("Do It Clean", doc.getField(AnnotationIndexField.NAME.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TEXT.getName()).length);
+ assertEquals("track annotation newer", doc.getField(AnnotationIndexField.TEXT.getName()).stringValue());
+ assertEquals(1, doc.getFields(AnnotationIndexField.TYPE.getName()).length);
+ assertEquals("track", doc.getField(AnnotationIndexField.TYPE.getName()).stringValue());
+
+ }
+ ir.close();
+ }
+
public void testGetTypeByDbId () throws Exception {
assertNull(AnnotationType.getByDbId(0));
assertEquals(AnnotationType.ARTIST,AnnotationType.getByDbId(1));
More information about the MusicBrainz-commits
mailing list