public AddTaxonomy ( Directory taxoDir, OrdinalMap map ) : void | ||
taxoDir | Directory | |
map | OrdinalMap | |
return | void |
public virtual void TestSimple() { Directory dest = NewDirectory(); var tw1 = new DirectoryTaxonomyWriter(dest); tw1.AddCategory(new FacetLabel("Author", "Mark Twain")); tw1.AddCategory(new FacetLabel("Animals", "Dog")); tw1.AddCategory(new FacetLabel("Author", "Rob Pike")); Directory src = NewDirectory(); var tw2 = new DirectoryTaxonomyWriter(src); tw2.AddCategory(new FacetLabel("Author", "Rob Pike")); tw2.AddCategory(new FacetLabel("Aardvarks", "Bob")); tw2.Dispose(); IOrdinalMap map = randomOrdinalMap(); tw1.AddTaxonomy(src, map); tw1.Dispose(); validate(dest, src, map); IOUtils.Dispose(dest, src); }
private void Dotest(int ncats, int range) { AtomicInteger numCats = new AtomicInteger(ncats); Directory[] dirs = new Directory[2]; for (int i = 0; i < dirs.Length; i++) { dirs[i] = NewDirectory(); var tw = new DirectoryTaxonomyWriter(dirs[i]); ThreadClass[] addThreads = new ThreadClass[4]; for (int j = 0; j < addThreads.Length; j++) { addThreads[j] = new ThreadAnonymousInnerClassHelper(this, range, numCats, tw); } foreach (ThreadClass t in addThreads) { t.Start(); } foreach (ThreadClass t in addThreads) { t.Join(); } tw.Dispose(); } var tw1 = new DirectoryTaxonomyWriter(dirs[0]); IOrdinalMap map = randomOrdinalMap(); tw1.AddTaxonomy(dirs[1], map); tw1.Dispose(); validate(dirs[0], dirs[1], map); IOUtils.Close(dirs); }
public virtual void TestConcurrency() { // tests that addTaxonomy and addCategory work in parallel int numCategories = AtLeast(10000); // build an input taxonomy index Directory src = NewDirectory(); var tw = new DirectoryTaxonomyWriter(src); for (int i = 0; i < numCategories; i++) { tw.AddCategory(new FacetLabel("a", Convert.ToString(i))); } tw.Dispose(); // now add the taxonomy to an empty taxonomy, while adding the categories // again, in parallel -- in the end, no duplicate categories should exist. Directory dest = NewDirectory(); var destTw = new DirectoryTaxonomyWriter(dest); var t = new ThreadAnonymousInnerClassHelper2(this, numCategories, destTw); t.Start(); IOrdinalMap map = new MemoryOrdinalMap(); destTw.AddTaxonomy(src, map); t.Join(); destTw.Dispose(); // now validate var dtr = new DirectoryTaxonomyReader(dest); // +2 to account for the root category + "a" Assert.AreEqual(numCategories + 2, dtr.Count); var categories = new JCG.HashSet <FacetLabel>(); for (int i = 1; i < dtr.Count; i++) { FacetLabel cat = dtr.GetPath(i); Assert.True(categories.Add(cat), "category " + cat + " already existed"); } dtr.Dispose(); IOUtils.Dispose(src, dest); }
public virtual void TestAddToEmpty() { Directory dest = NewDirectory(); Directory src = NewDirectory(); DirectoryTaxonomyWriter srcTW = new DirectoryTaxonomyWriter(src); srcTW.AddCategory(new FacetLabel("Author", "Rob Pike")); srcTW.AddCategory(new FacetLabel("Aardvarks", "Bob")); srcTW.Dispose(); DirectoryTaxonomyWriter destTW = new DirectoryTaxonomyWriter(dest); OrdinalMap map = randomOrdinalMap(); destTW.AddTaxonomy(src, map); destTW.Dispose(); validate(dest, src, map); IOUtils.Close(dest, src); }
public virtual void TestReplaceTaxonomy() { Directory input = NewDirectory(); var taxoWriter = new DirectoryTaxonomyWriter(input); int ordA = taxoWriter.AddCategory(new FacetLabel("a")); taxoWriter.Dispose(); Directory dir = NewDirectory(); taxoWriter = new DirectoryTaxonomyWriter(dir); int ordB = taxoWriter.AddCategory(new FacetLabel("b")); taxoWriter.AddCategory(new FacetLabel("c")); taxoWriter.Commit(); long origEpoch = getEpoch(dir); // replace the taxonomy with the input one taxoWriter.ReplaceTaxonomy(input); // LUCENE-4633: make sure that category "a" is not added again in any case taxoWriter.AddTaxonomy(input, new MemoryOrdinalMap()); Assert.AreEqual(2, taxoWriter.Size, "no categories should have been added"); // root + 'a' Assert.AreEqual(ordA, taxoWriter.AddCategory(new FacetLabel("a")), "category 'a' received new ordinal?"); // add the same category again -- it should not receive the same ordinal ! int newOrdB = taxoWriter.AddCategory(new FacetLabel("b")); Assert.AreNotSame(ordB, newOrdB, "new ordinal cannot be the original ordinal"); Assert.AreEqual(2, newOrdB, "ordinal should have been 2 since only one category was added by replaceTaxonomy"); taxoWriter.Dispose(); long newEpoch = getEpoch(dir); Assert.True(origEpoch < newEpoch, "index epoch should have been updated after replaceTaxonomy"); dir.Dispose(); input.Dispose(); }
public virtual void TestAddToEmpty() { Directory dest = NewDirectory(); Directory src = NewDirectory(); DirectoryTaxonomyWriter srcTW = new DirectoryTaxonomyWriter(src); srcTW.AddCategory(new FacetLabel("Author", "Rob Pike")); srcTW.AddCategory(new FacetLabel("Aardvarks", "Bob")); srcTW.Dispose(); DirectoryTaxonomyWriter destTW = new DirectoryTaxonomyWriter(dest); IOrdinalMap map = randomOrdinalMap(); destTW.AddTaxonomy(src, map); destTW.Dispose(); validate(dest, src, map); IOUtils.Dispose(dest, src); }
private void Dotest(int ncats, int range) { AtomicInt32 numCats = new AtomicInt32(ncats); Directory[] dirs = new Directory[2]; for (int i = 0; i < dirs.Length; i++) { dirs[i] = NewDirectory(); var tw = new DirectoryTaxonomyWriter(dirs[i]); ThreadJob[] addThreads = new ThreadJob[4]; for (int j = 0; j < addThreads.Length; j++) { addThreads[j] = new ThreadAnonymousInnerClassHelper(this, range, numCats, tw); } foreach (ThreadJob t in addThreads) { t.Start(); } foreach (ThreadJob t in addThreads) { t.Join(); } tw.Dispose(); } var tw1 = new DirectoryTaxonomyWriter(dirs[0]); IOrdinalMap map = randomOrdinalMap(); tw1.AddTaxonomy(dirs[1], map); tw1.Dispose(); validate(dirs[0], dirs[1], map); IOUtils.Dispose(dirs); }
public virtual void TestConcurrency() { // tests that addTaxonomy and addCategory work in parallel int numCategories = AtLeast(10000); // build an input taxonomy index Directory src = NewDirectory(); var tw = new DirectoryTaxonomyWriter(src); for (int i = 0; i < numCategories; i++) { tw.AddCategory(new FacetLabel("a", Convert.ToString(i))); } tw.Dispose(); // now add the taxonomy to an empty taxonomy, while adding the categories // again, in parallel -- in the end, no duplicate categories should exist. Directory dest = NewDirectory(); var destTw = new DirectoryTaxonomyWriter(dest); ThreadClass t = new ThreadAnonymousInnerClassHelper2(this, numCategories, destTw); t.Start(); OrdinalMap map = new MemoryOrdinalMap(); destTw.AddTaxonomy(src, map); t.Join(); destTw.Dispose(); // now validate var dtr = new DirectoryTaxonomyReader(dest); // +2 to account for the root category + "a" Assert.AreEqual(numCategories + 2, dtr.Size); var categories = new HashSet<FacetLabel>(); for (int i = 1; i < dtr.Size; i++) { FacetLabel cat = dtr.GetPath(i); Assert.True(categories.Add(cat), "category " + cat + " already existed"); } dtr.Dispose(); IOUtils.Close(src, dest); }
public virtual void TestSimple() { Directory dest = NewDirectory(); var tw1 = new DirectoryTaxonomyWriter(dest); tw1.AddCategory(new FacetLabel("Author", "Mark Twain")); tw1.AddCategory(new FacetLabel("Animals", "Dog")); tw1.AddCategory(new FacetLabel("Author", "Rob Pike")); Directory src = NewDirectory(); var tw2 = new DirectoryTaxonomyWriter(src); tw2.AddCategory(new FacetLabel("Author", "Rob Pike")); tw2.AddCategory(new FacetLabel("Aardvarks", "Bob")); tw2.Dispose(); OrdinalMap map = randomOrdinalMap(); tw1.AddTaxonomy(src, map); tw1.Dispose(); validate(dest, src, map); IOUtils.Close(dest, src); }
public virtual void TestReplaceTaxonomy() { Directory input = NewDirectory(); var taxoWriter = new DirectoryTaxonomyWriter(input); int ordA = taxoWriter.AddCategory(new FacetLabel("a")); taxoWriter.Dispose(); Directory dir = NewDirectory(); taxoWriter = new DirectoryTaxonomyWriter(dir); int ordB = taxoWriter.AddCategory(new FacetLabel("b")); taxoWriter.AddCategory(new FacetLabel("c")); taxoWriter.Commit(); long origEpoch = getEpoch(dir); // replace the taxonomy with the input one taxoWriter.ReplaceTaxonomy(input); // LUCENE-4633: make sure that category "a" is not added again in any case taxoWriter.AddTaxonomy(input, new MemoryOrdinalMap()); Assert.AreEqual(2, taxoWriter.Count, "no categories should have been added"); // root + 'a' Assert.AreEqual(ordA, taxoWriter.AddCategory(new FacetLabel("a")), "category 'a' received new ordinal?"); // add the same category again -- it should not receive the same ordinal ! int newOrdB = taxoWriter.AddCategory(new FacetLabel("b")); Assert.AreNotSame(ordB, newOrdB, "new ordinal cannot be the original ordinal"); Assert.AreEqual(2, newOrdB, "ordinal should have been 2 since only one category was added by replaceTaxonomy"); taxoWriter.Dispose(); long newEpoch = getEpoch(dir); Assert.True(origEpoch < newEpoch, "index epoch should have been updated after replaceTaxonomy"); dir.Dispose(); input.Dispose(); }