r13753 - in search_server/trunk: index/src/main/java/org/musicbrainz/search/index index/src/test/java/org/musicbrainz/search/index servlet/src/main/java/org/musicbrainz/search/servlet servlet/src/test/java/org/musicbrainz/search/servlet

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

r13753 - in search_server/trunk: index/src/main/java/org/musicbrainz/search/index index/src/test/java/org/musicbrainz/search/index servlet/src/main/java/org/musicbrainz/search/servlet servlet/src/test/java/org/musicbrainz/search/servlet

root-9
Author: ijabz
Date: 2014-05-13 08:25:17 +0000 (Tue, 13 May 2014)
New Revision: 13753

Modified:
   search_server/trunk/index/src/main/java/org/musicbrainz/search/index/InstrumentIndex.java
   search_server/trunk/index/src/test/java/org/musicbrainz/search/index/InstrumentIndexTest.java
   search_server/trunk/servlet/src/main/java/org/musicbrainz/search/servlet/InstrumentDismaxSearch.java
   search_server/trunk/servlet/src/test/java/org/musicbrainz/search/servlet/FindInstrumentTest.java
Log:
SEARCH-358:Added support for Instrument descripton.
Also added missing Instrument comment and Xml tests

Modified: search_server/trunk/index/src/main/java/org/musicbrainz/search/index/InstrumentIndex.java
===================================================================
--- search_server/trunk/index/src/main/java/org/musicbrainz/search/index/InstrumentIndex.java 2014-05-13 08:21:52 UTC (rev 13752)
+++ search_server/trunk/index/src/main/java/org/musicbrainz/search/index/InstrumentIndex.java 2014-05-13 08:25:17 UTC (rev 13753)
@@ -96,7 +96,8 @@
         addPreparedStatement("INSTRUMENTS",
                 "SELECT instrument.id, instrument.gid, instrument.name as name," +
                 "  instrument_type.name as type, " +
-                "  instrument.comment  " +
+                "  instrument.comment,  " +
+                "  instrument.description " +
                 " FROM instrument " +
                 "  LEFT JOIN instrument_type ON instrument.type = instrument_type.id " +
                 " WHERE instrument.id BETWEEN ? AND ?");
@@ -199,6 +200,12 @@
             instrument.setDisambiguation(comment);
         }
 
+        String description = rs.getString("description");
+        doc.addFieldOrNoValue(InstrumentIndexField.DESCRIPTION, description);
+        if (!Strings.isNullOrEmpty(description)) {
+            instrument.setDescription(description);
+        }
+
         if (aliases.containsKey(instrumentId)) {
             AliasList aliasList = of.createAliasList();
             for (Alias nextAlias : aliases.get(instrumentId)) {

Modified: search_server/trunk/index/src/test/java/org/musicbrainz/search/index/InstrumentIndexTest.java
===================================================================
--- search_server/trunk/index/src/test/java/org/musicbrainz/search/index/InstrumentIndexTest.java 2014-05-13 08:21:52 UTC (rev 13752)
+++ search_server/trunk/index/src/test/java/org/musicbrainz/search/index/InstrumentIndexTest.java 2014-05-13 08:25:17 UTC (rev 13753)
@@ -32,7 +32,7 @@
     private void addInstrumentOne() throws Exception {
 
         Statement stmt = conn.createStatement();
-        stmt.addBatch("INSERT INTO instrument (comment, id, gid,name,type, description) VALUES ('comment',1, 'aa95182f-df0a-3ad6-8bfb-4b63482cd276', 'Trumpet',1,'Brass instruument')");
+        stmt.addBatch("INSERT INTO instrument (comment, id, gid,name,type, description) VALUES ('comment',1, 'aa95182f-df0a-3ad6-8bfb-4b63482cd276', 'Trumpet',1,'Brass instrument')");
         stmt.addBatch("INSERT INTO instrument_type(id, name) VALUES (1, 'Brass')");
         stmt.addBatch("INSERT INTO instrument_alias (id, name, sort_name, instrument, primary_for_locale, locale, type ) VALUES (3,  'tromba','tromba sort', 1, true, 'it',1)");
 
@@ -108,6 +108,22 @@
     }
 
     @Test
+    public void testIndexInstrumentDescription() throws Exception {
+
+        addInstrumentOne();
+        RAMDirectory ramDir = new RAMDirectory();
+        createIndex(ramDir);
+
+        IndexReader ir = DirectoryReader.open(ramDir);
+        assertEquals(2, ir.numDocs());
+        {
+            checkTerm(ir, InstrumentIndexField.DESCRIPTION, "brass");
+            checkTermX(ir, InstrumentIndexField.DESCRIPTION, "instrument", 1);
+        }
+        ir.close();
+    }
+
+    @Test
     public void testStoredIndexInstrument() throws Exception {
 
         addInstrumentOne();
@@ -122,7 +138,7 @@
             Instrument instrument = (Instrument) MMDSerializer.unserialize(doc.get(InstrumentIndexField.INSTRUMENT_STORE.getName()), Instrument.class);
             assertEquals("aa95182f-df0a-3ad6-8bfb-4b63482cd276", instrument.getId());
             assertEquals("Trumpet", instrument.getName());
-
+            assertEquals("Brass instrument", instrument.getDescription());
             assertEquals("comment",instrument.getDisambiguation());
             assertEquals("Brass", instrument.getType());
             assertEquals("tromba",instrument.getAliasList().getAlias().get(0).getContent());

Modified: search_server/trunk/servlet/src/main/java/org/musicbrainz/search/servlet/InstrumentDismaxSearch.java
===================================================================
--- search_server/trunk/servlet/src/main/java/org/musicbrainz/search/servlet/InstrumentDismaxSearch.java 2014-05-13 08:21:52 UTC (rev 13752)
+++ search_server/trunk/servlet/src/main/java/org/musicbrainz/search/servlet/InstrumentDismaxSearch.java 2014-05-13 08:25:17 UTC (rev 13753)
@@ -40,6 +40,7 @@
   protected DismaxSearcher initDismaxSearcher() {
     Map<String, DismaxAlias.AliasField> fieldBoosts = new HashMap<String, DismaxAlias.AliasField>(3);
     fieldBoosts.put(InstrumentIndexField.INSTRUMENT.getName(), new DismaxAlias.AliasField(true, 1.3f));
+    fieldBoosts.put(InstrumentIndexField.DESCRIPTION.getName(), new DismaxAlias.AliasField(true, 0.9f));
     fieldBoosts.put(InstrumentIndexField.ALIAS.getName(), new DismaxAlias.AliasField(true, 0.9f));
     DismaxAlias dismaxAlias = new DismaxAlias();
     dismaxAlias.setFields(fieldBoosts);

Modified: search_server/trunk/servlet/src/test/java/org/musicbrainz/search/servlet/FindInstrumentTest.java
===================================================================
--- search_server/trunk/servlet/src/test/java/org/musicbrainz/search/servlet/FindInstrumentTest.java 2014-05-13 08:21:52 UTC (rev 13752)
+++ search_server/trunk/servlet/src/test/java/org/musicbrainz/search/servlet/FindInstrumentTest.java 2014-05-13 08:25:17 UTC (rev 13753)
@@ -47,6 +47,12 @@
             doc.addField(InstrumentIndexField.INSTRUMENT, "Trombone");
             instrument.setName("Trombone");
 
+            doc.addField(InstrumentIndexField.DESCRIPTION, "Brassy");
+            instrument.setDescription("Brassy");
+
+            doc.addField(InstrumentIndexField.COMMENT, "series 2 was best");
+            instrument.setDisambiguation("series 2 was best");
+
             doc.addField(InstrumentIndexField.ALIAS, "Tromba");
             AliasList aliasList = of.createAliasList();
             Alias alias = of.createAlias();
@@ -99,6 +105,26 @@
 
 
     @Test
+    public void testFindInstrumentByDesciption() throws Exception {
+        Results res = ss.search("description:\"Brassy\"", 0, 10);
+        assertEquals(1, res.getTotalHits());
+        Result result = res.results.get(0);
+        MbDocument doc = result.getDoc();
+        assertEquals("ff571ff4-04cb-4b9c-8a1c-354c330f863c", doc.get(InstrumentIndexField.INSTRUMENT_ID));
+        assertEquals("Trombone", doc.get(InstrumentIndexField.INSTRUMENT));
+    }
+
+    @Test
+    public void testFindInstrumentByComment() throws Exception {
+        Results res = ss.search("comment:\"series 2 was best\"", 0, 10);
+        assertEquals(1, res.getTotalHits());
+        Result result = res.results.get(0);
+        MbDocument doc = result.getDoc();
+        assertEquals("ff571ff4-04cb-4b9c-8a1c-354c330f863c", doc.get(InstrumentIndexField.INSTRUMENT_ID));
+        assertEquals("Trombone", doc.get(InstrumentIndexField.INSTRUMENT));
+    }
+
+    @Test
     public void testFindInstrumentByDismax1() throws Exception {
         Results res = sd.search("Trombone", 0, 10);
         assertEquals(1, res.getTotalHits());
@@ -158,6 +184,8 @@
         assertTrue(output.contains("\"offset\":0,"));
         assertTrue(output.contains("\"type\":\"Brass\""));
         assertTrue(output.contains("name\":\"Trombone\""));
+        assertTrue(output.contains("\"description\":\"Brassy\""));
+        assertTrue(output.contains("\"disambiguation\":\"series 2 was best\""));
     }
 
     /**
@@ -180,9 +208,11 @@
         assertTrue(output.contains("\"instruments\""));
         assertTrue(output.contains("\"type\":\"Brass\""));
         assertTrue(output.contains("name\":\"Trombone\""));
+        assertTrue(output.contains("\"description\":\"Brassy\""));
         assertTrue(output.contains("\"aliases\":[{\"name\":\"Tromba\",\"locale\":null,\"type\":null,\"primary\":null,\"begin-date\":null,\"end-date\":null}]"));
         assertTrue(output.contains("\"count\":1"));
         assertTrue(output.contains("\"offset\":0,"));
+        assertTrue(output.contains("\"disambiguation\":\"series 2 was best\""));
 
     }
 
@@ -204,4 +234,53 @@
         assertTrue(output.contains("\"offset\" : 0"));
 
     }
+
+    /**
+     * @throws Exception exception
+     */
+    @Test
+    public void testOutputXmlIdent() throws Exception {
+
+        Results res = ss.search("instrument:\"Trombone\"", 0, 10);
+        org.musicbrainz.search.servlet.mmd2.ResultsWriter writer = ss.getMmd2Writer();
+        StringWriter sw = new StringWriter();
+        PrintWriter pr = new PrintWriter(sw);
+        writer.write(pr, res, SearchServerServlet.RESPONSE_XML, true);
+        pr.close();
+
+        String output = sw.toString();
+        System.out.println("Xml Ident is" + output);
+        assertTrue(output.contains("<instrument id=\"ff571ff4-04cb-4b9c-8a1c-354c330f863c\" type=\"Brass\" ext:score=\"100\">"));
+        assertTrue(output.contains("<instrument-list count=\"1\" offset=\"0\">"));
+        assertTrue(output.contains("<name>Trombone</name>"));
+        assertTrue(output.contains("<description>Brassy</description>"));
+        assertTrue(output.contains("<disambiguation>series 2 was best</disambiguation>"));
+        assertTrue(output.contains("<alias>Tromba</alias>"));
+
+
+    }
+
+    /**
+     * @throws Exception exception
+     */
+    @Test
+    public void testOutputXml() throws Exception {
+
+        Results res = ss.search("instrument:\"Trombone\"", 0, 10);
+        org.musicbrainz.search.servlet.mmd2.ResultsWriter writer = ss.getMmd2Writer();
+        StringWriter sw = new StringWriter();
+        PrintWriter pr = new PrintWriter(sw);
+        writer.write(pr, res, SearchServerServlet.RESPONSE_XML);
+        pr.close();
+
+        String output = sw.toString();
+        System.out.println("Xml Ident is" + output);
+        assertTrue(output.contains("<instrument id=\"ff571ff4-04cb-4b9c-8a1c-354c330f863c\" type=\"Brass\" ext:score=\"100\">"));
+        assertTrue(output.contains("<instrument-list count=\"1\" offset=\"0\">"));
+        assertTrue(output.contains("<name>Trombone</name>"));
+        assertTrue(output.contains("<description>Brassy</description>"));
+        assertTrue(output.contains("<disambiguation>series 2 was best</disambiguation>"));
+        assertTrue(output.contains("<alias>Tromba</alias>"));
+
+    }
 }
\ No newline at end of file


_______________________________________________
MusicBrainz-commits mailing list
[hidden email]
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-commits
Loading...