Commits

Scott Farquhar committed aa05af8

Refactored tests, and started testing the OneDimensionalHitCollector

Comments (0)

Files changed (3)

src/test/java/com/atlassian/lucene/stats/AbstractHitCollectorTestCase.java

 package com.atlassian.lucene.stats;
 
+import com.atlassian.lucene.stats.util.NullStatsMapper;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 
 public abstract class AbstractHitCollectorTestCase
 {
-    protected void index(Document doc, String fieldName, String fieldValue)
+    protected void index(Document doc, String... fieldNameValues)
     {
-        doc.add(new Field(fieldName, fieldValue, Field.Store.YES, Field.Index.UN_TOKENIZED));
+        if ((fieldNameValues.length & 1) != 0)
+        {
+           throw new IllegalArgumentException("need to supply both a field name and value");
+        }
+
+        for (int i = 0; i < fieldNameValues.length; i+= 2) {
+            String fieldName = fieldNameValues[i];
+            String fieldValue = fieldNameValues[i+1];
+            doc.add(new Field(fieldName, fieldValue, Field.Store.YES, Field.Index.UN_TOKENIZED));
+        }
+
     }
 
     protected IndexReader writeToRAM(Collection docs) throws IOException
 
         return IndexReader.open(ramDirectory);
     }
+
+    protected static class MockStatsMapper extends NullStatsMapper
+    {
+        private final String documentConstant;
+
+        MockStatsMapper(String documentConstant)
+        {
+            this.documentConstant = documentConstant;
+        }
+
+        public String getDocumentConstant()
+        {
+            return documentConstant;
+        }
+
+    }
+
 }

src/test/java/com/atlassian/lucene/stats/TestOneObjectTermHitCollector.java

 import org.apache.lucene.search.Searcher;
 
 import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 public class TestOneObjectTermHitCollector extends AbstractHitCollectorTestCase
 {
     private static final String FIELD = "field";
     private Map result = new HashMap();
-    private OneDimensionalObjectHitCollector hitCollector;
 
     private final Document doc = new Document();
     private final Document doc2 = new Document();
      * @throws java.io.IOException if unable to index to RAM
      */
     @Test
-    public void testOneDimensionalTermHitCollectorHitCount() throws IOException
+    public void testOneDimensionalTermHitCollector() throws IOException
     {
-//        index(doc, FIELD, "1");
-//        index(doc, "project", "10000");
-//        index(doc, "issuetype", "1");
-//        index(doc2, FIELD, "22");
-//        index(doc2, "project", "10000");
-//        index(doc2, "issuetype", "1");
-//        index(doc3, FIELD, "333");
-//        index(doc3, "project", "10000");
-//        index(doc3, "issuetype", "1");
-//
-//        List docsList = EasyList.build();
-//        collectStats(docsList);
-//        assertEquals(0, hitCollector.getHitCount());
-//        assertEquals(0, hitCollector.getIrrelevantCount());
-//
-//        docsList = EasyList.build(doc);
-//        collectStats(docsList);
-//        assertEquals(1, hitCollector.getHitCount());
-//        assertEquals(0, hitCollector.getIrrelevantCount());
-//
-//        docsList = EasyList.build(doc, doc2);
-//        collectStats(docsList);
-//        assertEquals(2, hitCollector.getHitCount());
-//        assertEquals(0, hitCollector.getIrrelevantCount());
-//
-//        docsList = EasyList.build(doc, doc2, doc3);
-//        collectStats(docsList);
-//        assertEquals(3, hitCollector.getHitCount());
-//        assertEquals(0, hitCollector.getIrrelevantCount());
-//
-//        docsList = EasyList.build(doc, doc, doc2, doc3, doc, doc3);
-//        collectStats(docsList);
-//        assertEquals(6, hitCollector.getHitCount());
-//        assertEquals(0, hitCollector.getIrrelevantCount());
+        index(doc, FIELD, "1", "project", "10000", "issuetype", "1");
+        index(doc2, FIELD, "22", "project", "10000", "issuetype", "1");
+        index(doc3, FIELD, "333", "project", "10000", "issuetype", "1");
+
+        collectStats(FIELD, doc, doc2, doc3);
+        assertEquals(3, result.size());
+        assertEquals(1, result.get("1"));
+        assertEquals(1, result.get("22"));
+        assertEquals(1, result.get("333"));
+        assertEquals(null, result.get("nothing"));
     }
 
 
 
-    private void collectStats(Collection docs) throws IOException
+    private void collectStats(String field, Document... docs) throws IOException
     {
-//        final IndexReader reader = writeToRAM(docs);
-//
-//        hitCollector = new OneDimensionalObjectHitCollector(FIELD, result, reader, new DefaultReaderCache());
-//
-//        Searcher searcher = new IndexSearcher(reader);
-//        Query query = new MatchAllDocsQuery();
-//        searcher.search(query, hitCollector);
+        final IndexReader reader = writeToRAM(Arrays.asList(docs));
+
+        OneDimensionalObjectHitCollector hitCollector = new OneDimensionalObjectHitCollector(new MockStatsMapper(field), result, reader, new DefaultReaderCache());
+
+        Searcher searcher = new IndexSearcher(reader);
+        Query query = new MatchAllDocsQuery();
+        searcher.search(query, hitCollector);
     }
 
 

src/test/java/com/atlassian/lucene/stats/TestTwoDimensionalTermHitCollector.java

         searcher.search(query, hitCollector);
     }
 
-    private static class MockStatsMapper extends NullStatsMapper
-    {
-        private final String documentConstant;
-
-        MockStatsMapper(String documentConstant)
-        {
-            this.documentConstant = documentConstant;
-        }
-
-        public String getDocumentConstant()
-        {
-            return documentConstant;
-        }
-
-    }
 }