You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/12/31 20:12:13 UTC
[07/14] lucenenet git commit: Moving Lucene.Net.Facet tests to their
appropriate place
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs b/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs
new file mode 100644
index 0000000..086e608
--- /dev/null
+++ b/src/Lucene.Net.Tests.Facet/TestMultipleIndexFields.cs
@@ -0,0 +1,300 @@
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace Lucene.Net.Facet
+{
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+ using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer;
+ using MockTokenizer = Lucene.Net.Analysis.MockTokenizer;
+ using Document = Lucene.Net.Documents.Document;
+ using Field = Lucene.Net.Documents.Field;
+ using TextField = Lucene.Net.Documents.TextField;
+ using TaxonomyReader = Lucene.Net.Facet.Taxonomy.TaxonomyReader;
+ using TaxonomyWriter = Lucene.Net.Facet.Taxonomy.TaxonomyWriter;
+ using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader;
+ using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter;
+ using AtomicReader = Lucene.Net.Index.AtomicReader;
+ using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext;
+ using IndexReader = Lucene.Net.Index.IndexReader;
+ using OpenMode = Lucene.Net.Index.IndexWriterConfig.OpenMode_e;
+ using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter;
+ using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+ using MatchAllDocsQuery = Lucene.Net.Search.MatchAllDocsQuery;
+ using Directory = Lucene.Net.Store.Directory;
+ using IOUtils = Lucene.Net.Util.IOUtils;
+
+ public class TestMultipleIndexFields : FacetTestCase
+ {
+
+ private static readonly FacetField[] CATEGORIES = new FacetField[] { new FacetField("Author", "Mark Twain"), new FacetField("Author", "Stephen King"), new FacetField("Author", "Kurt Vonnegut"), new FacetField("Band", "Rock & Pop", "The Beatles"), new FacetField("Band", "Punk", "The Ramones"), new FacetField("Band", "Rock & Pop", "U2"), new FacetField("Band", "Rock & Pop", "REM"), new FacetField("Band", "Rock & Pop", "Dave Matthews Band"), new FacetField("Composer", "Bach") };
+
+ private FacetsConfig Config
+ {
+ get
+ {
+ FacetsConfig config = new FacetsConfig();
+ config.SetHierarchical("Band", true);
+ return config;
+ }
+ }
+
+ [Test]
+ public virtual void TestDefault()
+ {
+ Directory indexDir = NewDirectory();
+ Directory taxoDir = NewDirectory();
+
+ // create and open an index writer
+ var iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)));
+ // create and open a taxonomy writer
+ var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
+ var config = Config;
+
+ seedIndex(tw, iw, config);
+
+ IndexReader ir = iw.Reader;
+ tw.Commit();
+
+ // prepare index reader and taxonomy.
+ var tr = new DirectoryTaxonomyReader(taxoDir);
+
+ // prepare searcher to search against
+ IndexSearcher searcher = NewSearcher(ir);
+
+ FacetsCollector sfc = PerformSearch(tr, ir, searcher);
+
+ // Obtain facets results and hand-test them
+ AssertCorrectResults(GetTaxonomyFacetCounts(tr, config, sfc));
+
+ assertOrdinalsExist("$facets", ir);
+
+ IOUtils.Close(tr, ir, iw, tw, indexDir, taxoDir);
+ }
+
+ [Test]
+ public virtual void TestCustom()
+ {
+ Directory indexDir = NewDirectory();
+ Directory taxoDir = NewDirectory();
+
+ // create and open an index writer
+ RandomIndexWriter iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)));
+ // create and open a taxonomy writer
+ var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
+
+ FacetsConfig config = Config;
+ config.SetIndexFieldName("Author", "$author");
+ seedIndex(tw, iw, config);
+
+ IndexReader ir = iw.Reader;
+ tw.Commit();
+
+ // prepare index reader and taxonomy.
+ var tr = new DirectoryTaxonomyReader(taxoDir);
+
+ // prepare searcher to search against
+ IndexSearcher searcher = NewSearcher(ir);
+
+ FacetsCollector sfc = PerformSearch(tr, ir, searcher);
+
+ IDictionary<string, Facets> facetsMap = new Dictionary<string, Facets>();
+ facetsMap["Author"] = GetTaxonomyFacetCounts(tr, config, sfc, "$author");
+ Facets facets = new MultiFacets(facetsMap, GetTaxonomyFacetCounts(tr, config, sfc));
+
+ // Obtain facets results and hand-test them
+ AssertCorrectResults(facets);
+
+ assertOrdinalsExist("$facets", ir);
+ assertOrdinalsExist("$author", ir);
+
+ IOUtils.Close(tr, ir, iw, tw, indexDir, taxoDir);
+ }
+
+ [Test]
+ public virtual void TestTwoCustomsSameField()
+ {
+ Directory indexDir = NewDirectory();
+ Directory taxoDir = NewDirectory();
+
+ // create and open an index writer
+ RandomIndexWriter iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)));
+ // create and open a taxonomy writer
+ var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
+
+ FacetsConfig config = Config;
+ config.SetIndexFieldName("Band", "$music");
+ config.SetIndexFieldName("Composer", "$music");
+ seedIndex(tw, iw, config);
+
+ IndexReader ir = iw.Reader;
+ tw.Commit();
+
+ // prepare index reader and taxonomy.
+ var tr = new DirectoryTaxonomyReader(taxoDir);
+
+ // prepare searcher to search against
+ IndexSearcher searcher = NewSearcher(ir);
+
+ FacetsCollector sfc = PerformSearch(tr, ir, searcher);
+
+ IDictionary<string, Facets> facetsMap = new Dictionary<string, Facets>();
+ Facets facets2 = GetTaxonomyFacetCounts(tr, config, sfc, "$music");
+ facetsMap["Band"] = facets2;
+ facetsMap["Composer"] = facets2;
+ Facets facets = new MultiFacets(facetsMap, GetTaxonomyFacetCounts(tr, config, sfc));
+
+ // Obtain facets results and hand-test them
+ AssertCorrectResults(facets);
+
+ assertOrdinalsExist("$facets", ir);
+ assertOrdinalsExist("$music", ir);
+ assertOrdinalsExist("$music", ir);
+
+ IOUtils.Close(tr, ir, iw, tw, indexDir, taxoDir);
+ }
+
+ private void assertOrdinalsExist(string field, IndexReader ir)
+ {
+ foreach (AtomicReaderContext context in ir.Leaves)
+ {
+ AtomicReader r = context.AtomicReader;
+ if (r.GetBinaryDocValues(field) != null)
+ {
+ return; // not all segments must have this DocValues
+ }
+ }
+ Fail("no ordinals found for " + field);
+ }
+
+ [Test]
+ public virtual void TestDifferentFieldsAndText()
+ {
+ Directory indexDir = NewDirectory();
+ Directory taxoDir = NewDirectory();
+
+ // create and open an index writer
+ var iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)));
+ // create and open a taxonomy writer
+ var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
+
+ FacetsConfig config = Config;
+ config.SetIndexFieldName("Band", "$bands");
+ config.SetIndexFieldName("Composer", "$composers");
+ seedIndex(tw, iw, config);
+
+ IndexReader ir = iw.Reader;
+ tw.Commit();
+
+ // prepare index reader and taxonomy.
+ var tr = new DirectoryTaxonomyReader(taxoDir);
+
+ // prepare searcher to search against
+ IndexSearcher searcher = NewSearcher(ir);
+
+ FacetsCollector sfc = PerformSearch(tr, ir, searcher);
+
+ IDictionary<string, Facets> facetsMap = new Dictionary<string, Facets>();
+ facetsMap["Band"] = GetTaxonomyFacetCounts(tr, config, sfc, "$bands");
+ facetsMap["Composer"] = GetTaxonomyFacetCounts(tr, config, sfc, "$composers");
+ Facets facets = new MultiFacets(facetsMap, GetTaxonomyFacetCounts(tr, config, sfc));
+
+ // Obtain facets results and hand-test them
+ AssertCorrectResults(facets);
+ assertOrdinalsExist("$facets", ir);
+ assertOrdinalsExist("$bands", ir);
+ assertOrdinalsExist("$composers", ir);
+
+ IOUtils.Close(tr, ir, iw, tw, indexDir, taxoDir);
+ }
+
+ [Test]
+ public virtual void TestSomeSameSomeDifferent()
+ {
+ Directory indexDir = NewDirectory();
+ Directory taxoDir = NewDirectory();
+
+ // create and open an index writer
+ RandomIndexWriter iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)));
+ // create and open a taxonomy writer
+ TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
+
+ FacetsConfig config = Config;
+ config.SetIndexFieldName("Band", "$music");
+ config.SetIndexFieldName("Composer", "$music");
+ config.SetIndexFieldName("Author", "$literature");
+ seedIndex(tw, iw, config);
+
+ IndexReader ir = iw.Reader;
+ tw.Commit();
+
+ // prepare index reader and taxonomy.
+ var tr = new DirectoryTaxonomyReader(taxoDir);
+
+ // prepare searcher to search against
+ IndexSearcher searcher = NewSearcher(ir);
+
+ FacetsCollector sfc = PerformSearch(tr, ir, searcher);
+
+ IDictionary<string, Facets> facetsMap = new Dictionary<string, Facets>();
+ Facets facets2 = GetTaxonomyFacetCounts(tr, config, sfc, "$music");
+ facetsMap["Band"] = facets2;
+ facetsMap["Composer"] = facets2;
+ facetsMap["Author"] = GetTaxonomyFacetCounts(tr, config, sfc, "$literature");
+ Facets facets = new MultiFacets(facetsMap, GetTaxonomyFacetCounts(tr, config, sfc));
+
+ // Obtain facets results and hand-test them
+ AssertCorrectResults(facets);
+ assertOrdinalsExist("$music", ir);
+ assertOrdinalsExist("$literature", ir);
+
+ IOUtils.Close(tr, ir, iw, tw);
+ IOUtils.Close(indexDir, taxoDir);
+ }
+
+
+ private void AssertCorrectResults(Facets facets)
+ {
+ Assert.AreEqual(5, facets.GetSpecificValue("Band"));
+ Assert.AreEqual("dim=Band path=[] value=5 childCount=2\n Rock & Pop (4)\n Punk (1)\n", facets.GetTopChildren(10, "Band").ToString());
+ Assert.AreEqual("dim=Band path=[Rock & Pop] value=4 childCount=4\n The Beatles (1)\n U2 (1)\n REM (1)\n Dave Matthews Band (1)\n", facets.GetTopChildren(10, "Band", "Rock & Pop").ToString());
+ Assert.AreEqual("dim=Author path=[] value=3 childCount=3\n Mark Twain (1)\n Stephen King (1)\n Kurt Vonnegut (1)\n", facets.GetTopChildren(10, "Author").ToString());
+ }
+
+
+ private static FacetsCollector PerformSearch(TaxonomyReader tr, IndexReader ir, IndexSearcher searcher)
+ {
+ FacetsCollector fc = new FacetsCollector();
+ FacetsCollector.Search(searcher, new MatchAllDocsQuery(), 10, fc);
+ return fc;
+ }
+
+ private static void seedIndex(TaxonomyWriter tw, RandomIndexWriter iw, FacetsConfig config)
+ {
+ foreach (FacetField ff in CATEGORIES)
+ {
+ Document doc = new Document();
+ doc.Add(ff);
+ doc.Add(new TextField("content", "alpha", Field.Store.YES));
+ iw.AddDocument(config.Build(tw, doc));
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
new file mode 100644
index 0000000..afd46e5
--- /dev/null
+++ b/src/Lucene.Net.Tests.Facet/TestRandomSamplingFacetsCollector.cs
@@ -0,0 +1,154 @@
+using System;
+using System.Diagnostics;
+using Lucene.Net.Randomized.Generators;
+using NUnit.Framework;
+
+namespace Lucene.Net.Facet
+{
+
+ using Document = Lucene.Net.Documents.Document;
+ using Store = Lucene.Net.Documents.Field.Store;
+ using StringField = Lucene.Net.Documents.StringField;
+ using MatchingDocs = Lucene.Net.Facet.FacetsCollector.MatchingDocs;
+ using FastTaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.FastTaxonomyFacetCounts;
+ using TaxonomyReader = Lucene.Net.Facet.Taxonomy.TaxonomyReader;
+ using DirectoryTaxonomyReader = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader;
+ using DirectoryTaxonomyWriter = Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter;
+ using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter;
+ using Term = Lucene.Net.Index.Term;
+ using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+ using MultiCollector = Lucene.Net.Search.MultiCollector;
+ using TermQuery = Lucene.Net.Search.TermQuery;
+ using Directory = Lucene.Net.Store.Directory;
+ using IOUtils = Lucene.Net.Util.IOUtils;
+
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ public class TestRandomSamplingFacetsCollector : FacetTestCase
+ {
+
+ [Test]
+ public virtual void TestRandomSampling()
+ {
+ Directory dir = NewDirectory();
+ Directory taxoDir = NewDirectory();
+
+ DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
+ RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
+
+ FacetsConfig config = new FacetsConfig();
+
+ int numDocs = AtLeast(10000);
+ for (int i = 0; i < numDocs; i++)
+ {
+ Document doc = new Document();
+ doc.Add(new StringField("EvenOdd", (i % 2 == 0) ? "even" : "odd", Store.NO));
+ doc.Add(new FacetField("iMod10", Convert.ToString(i % 10)));
+ writer.AddDocument(config.Build(taxoWriter, doc));
+ }
+ Random random = Random();
+
+ // NRT open
+ IndexSearcher searcher = NewSearcher(writer.Reader);
+ var taxoReader = new DirectoryTaxonomyReader(taxoWriter);
+ IOUtils.Close(writer, taxoWriter);
+
+ // Test empty results
+ RandomSamplingFacetsCollector collectRandomZeroResults = new RandomSamplingFacetsCollector(numDocs / 10, random.NextLong());
+
+ // There should be no divisions by zero
+ searcher.Search(new TermQuery(new Term("EvenOdd", "NeverMatches")), collectRandomZeroResults);
+
+ // There should be no divisions by zero and no null result
+ Assert.NotNull(collectRandomZeroResults.GetMatchingDocs);
+
+ // There should be no results at all
+ foreach (MatchingDocs doc in collectRandomZeroResults.GetMatchingDocs)
+ {
+ Assert.AreEqual(0, doc.totalHits);
+ }
+
+ // Now start searching and retrieve results.
+
+ // Use a query to select half of the documents.
+ TermQuery query = new TermQuery(new Term("EvenOdd", "even"));
+
+ // there will be 5 facet values (0, 2, 4, 6 and 8), as only the even (i %
+ // 10) are hits.
+ // there is a REAL small chance that one of the 5 values will be missed when
+ // sampling.
+ // but is that 0.8 (chance not to take a value) ^ 2000 * 5 (any can be
+ // missing) ~ 10^-193
+ // so that is probably not going to happen.
+ int maxNumChildren = 5;
+
+ RandomSamplingFacetsCollector random100Percent = new RandomSamplingFacetsCollector(numDocs, random.NextLong()); // no sampling
+ RandomSamplingFacetsCollector random10Percent = new RandomSamplingFacetsCollector(numDocs / 10, random.NextLong()); // 10 % of total docs, 20% of the hits
+
+ FacetsCollector fc = new FacetsCollector();
+
+ searcher.Search(query, MultiCollector.Wrap(fc, random100Percent, random10Percent));
+
+ FastTaxonomyFacetCounts random10FacetCounts = new FastTaxonomyFacetCounts(taxoReader, config, random10Percent);
+ FastTaxonomyFacetCounts random100FacetCounts = new FastTaxonomyFacetCounts(taxoReader, config, random100Percent);
+ FastTaxonomyFacetCounts exactFacetCounts = new FastTaxonomyFacetCounts(taxoReader, config, fc);
+
+ FacetResult random10Result = random10Percent.AmortizeFacetCounts(random10FacetCounts.GetTopChildren(10, "iMod10"), config, searcher);
+ FacetResult random100Result = random100FacetCounts.GetTopChildren(10, "iMod10");
+ FacetResult exactResult = exactFacetCounts.GetTopChildren(10, "iMod10");
+
+ Assert.AreEqual(random100Result, exactResult);
+
+ // we should have five children, but there is a small chance we have less.
+ // (see above).
+ Assert.True(random10Result.ChildCount <= maxNumChildren);
+ // there should be one child at least.
+ Assert.True(random10Result.ChildCount >= 1);
+
+ // now calculate some statistics to determine if the sampled result is 'ok'.
+ // because random sampling is used, the results will vary each time.
+ int sum = 0;
+ foreach (LabelAndValue lav in random10Result.LabelValues)
+ {
+ sum += (int)lav.value;
+ }
+ float mu = (float)sum / (float)maxNumChildren;
+
+ float variance = 0;
+ foreach (LabelAndValue lav in random10Result.LabelValues)
+ {
+ variance += (float)Math.Pow((mu - (int)lav.value), 2);
+ }
+ variance = variance / maxNumChildren;
+ float sigma = (float)Math.Sqrt(variance);
+
+ // we query only half the documents and have 5 categories. The average
+ // number of docs in a category will thus be the total divided by 5*2
+ float targetMu = numDocs / (5.0f * 2.0f);
+
+ // the average should be in the range and the standard deviation should not
+ // be too great
+ Assert.True(sigma < 200);
+ Assert.True(targetMu - 3 * sigma < mu && mu < targetMu + 3 * sigma);
+
+ IOUtils.Close(searcher.IndexReader, taxoReader, dir, taxoDir);
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests.Facet/app.config
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/app.config b/src/Lucene.Net.Tests.Facet/app.config
new file mode 100644
index 0000000..6feedb0
--- /dev/null
+++ b/src/Lucene.Net.Tests.Facet/app.config
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests.Facet/packages.config
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/packages.config b/src/Lucene.Net.Tests.Facet/packages.config
new file mode 100644
index 0000000..d017a09
--- /dev/null
+++ b/src/Lucene.Net.Tests.Facet/packages.config
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Apache.NMS" version="1.6.0.3083" targetFramework="net451" />
+ <package id="NUnit" version="2.6.4" targetFramework="net451" />
+</packages>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
index cde24c1..da4ef05 100644
--- a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
+++ b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
@@ -157,31 +157,6 @@
<Compile Include="core\Document\TestDateTools.cs" />
<Compile Include="core\Document\TestDocument.cs" />
<Compile Include="core\Document\TestField.cs" />
- <Compile Include="core\Facet\AssertingSubDocsAtOnceCollector.cs" />
- <Compile Include="core\Facet\FacetTestCase.cs" />
- <Compile Include="core\Facet\Range\TestRangeFacetCounts.cs" />
- <Compile Include="core\Facet\SlowRAMDirectory.cs" />
- <Compile Include="core\Facet\SortedSet\TestSortedSetDocValuesFacets.cs" />
- <Compile Include="core\Facet\Taxonomy\Directory\TestAddTaxonomy.cs" />
- <Compile Include="core\Facet\Taxonomy\Directory\TestConcurrentFacetedIndexing.cs" />
- <Compile Include="core\Facet\Taxonomy\Directory\TestDirectoryTaxonomyReader.cs" />
- <Compile Include="core\Facet\Taxonomy\Directory\TestDirectoryTaxonomyWriter.cs" />
- <Compile Include="core\Facet\Taxonomy\TestCachedOrdinalsReader.cs" />
- <Compile Include="core\Facet\Taxonomy\TestFacetLabel.cs" />
- <Compile Include="core\Facet\Taxonomy\TestLRUHashMap.cs" />
- <Compile Include="core\Facet\Taxonomy\TestSearcherTaxonomyManager.cs" />
- <Compile Include="core\Facet\Taxonomy\TestTaxonomyCombined.cs" />
- <Compile Include="core\Facet\Taxonomy\TestTaxonomyFacetAssociations.cs" />
- <Compile Include="core\Facet\Taxonomy\TestTaxonomyFacetCounts.cs" />
- <Compile Include="core\Facet\Taxonomy\TestTaxonomyFacetCounts2.cs" />
- <Compile Include="core\Facet\Taxonomy\TestTaxonomyFacetSumValueSource.cs" />
- <Compile Include="core\Facet\Taxonomy\WriterCache\TestCharBlockArray.cs" />
- <Compile Include="core\Facet\Taxonomy\WriterCache\TestCompactLabelToOrdinal.cs" />
- <Compile Include="core\Facet\TestDrillDownQuery.cs" />
- <Compile Include="core\Facet\TestDrillSideways.cs" />
- <Compile Include="core\Facet\TestFacetsConfig.cs" />
- <Compile Include="core\Facet\TestMultipleIndexFields.cs" />
- <Compile Include="core\Facet\TestRandomSamplingFacetsCollector.cs" />
<Compile Include="core\Index\BinaryTokenStream.cs" />
<Compile Include="core\Index\Test2BBinaryDocValues.cs" />
<Compile Include="core\Index\Test2BDocs.cs" />
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs b/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs
deleted file mode 100644
index c3730df..0000000
--- a/src/Lucene.Net.Tests/core/Facet/AssertingSubDocsAtOnceCollector.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-using System.Collections.Generic;
-using Apache.NMS;
-
-namespace Lucene.Net.Facet
-{
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
- using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext;
- using Collector = Lucene.Net.Search.Collector;
- using ChildScorer = Lucene.Net.Search.Scorer.ChildScorer;
- using Scorer = Lucene.Net.Search.Scorer;
-
- /// <summary>
- /// Verifies in collect() that all child subScorers are on
- /// the collected doc.
- /// </summary>
- internal class AssertingSubDocsAtOnceCollector : Collector
- {
-
- // TODO: allow wrapping another Collector
-
- internal IList<Scorer> allScorers;
-
- public override Scorer Scorer
- {
- set
- {
- // Gathers all scorers, including value and "under":
- allScorers = new List<Scorer>();
- allScorers.Add(value);
- int upto = 0;
- while (upto < allScorers.Count)
- {
- value = allScorers[upto++];
- foreach (ChildScorer sub in value.Children)
- {
- allScorers.Add(sub.Child);
- }
- }
- }
- }
-
- public override void Collect(int docID)
- {
- foreach (Scorer s in allScorers)
- {
- if (docID != s.DocID())
- {
- throw new IllegalStateException("subScorer=" + s + " has docID=" + s.DocID() + " != collected docID=" + docID);
- }
- }
- }
-
- public override AtomicReaderContext NextReader
- {
- set
- {
- }
- }
-
- public override bool AcceptsDocsOutOfOrder()
- {
- return false;
- }
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/68aa9728/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs b/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs
deleted file mode 100644
index 6c2e508..0000000
--- a/src/Lucene.Net.Tests/core/Facet/FacetTestCase.cs
+++ /dev/null
@@ -1,293 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Linq;
-using Lucene.Net.Facet;
-using Lucene.Net.Randomized.Generators;
-using Lucene.Net.Support;
-using NUnit.Framework;
-
-namespace Lucene.Net.Facet
-{
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
- using CachedOrdinalsReader = Lucene.Net.Facet.Taxonomy.CachedOrdinalsReader;
- using DocValuesOrdinalsReader = Lucene.Net.Facet.Taxonomy.DocValuesOrdinalsReader;
- using FastTaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.FastTaxonomyFacetCounts;
- using OrdinalsReader = Lucene.Net.Facet.Taxonomy.OrdinalsReader;
- using TaxonomyFacetCounts = Lucene.Net.Facet.Taxonomy.TaxonomyFacetCounts;
- using TaxonomyReader = Lucene.Net.Facet.Taxonomy.TaxonomyReader;
- using BytesRef = Lucene.Net.Util.BytesRef;
- using SuppressCodecs = Lucene.Net.Util.LuceneTestCase.SuppressCodecs;
- using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
- using TestUtil = Lucene.Net.Util.TestUtil;
-
- [TestFixture]
- public abstract class FacetTestCase : LuceneTestCase
- {
- public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector c)
- {
- return GetTaxonomyFacetCounts(taxoReader, config, c, FacetsConfig.DEFAULT_INDEX_FIELD_NAME);
- }
- public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector c, string indexFieldName)
- {
- Facets facets;
- if (Random().NextBoolean())
- {
- facets = new FastTaxonomyFacetCounts(indexFieldName, taxoReader, config, c);
- }
- else
- {
- OrdinalsReader ordsReader = new DocValuesOrdinalsReader(indexFieldName);
- if (Random().NextBoolean())
- {
- ordsReader = new CachedOrdinalsReader(ordsReader);
- }
- facets = new TaxonomyFacetCounts(ordsReader, taxoReader, config, c);
- }
-
- return facets;
- }
-
- protected internal virtual string[] GetRandomTokens(int count)
- {
- string[] tokens = new string[count];
- for (int i = 0; i < tokens.Length; i++)
- {
- tokens[i] = TestUtil.RandomRealisticUnicodeString(Random(), 1, 10);
- //tokens[i] = TestUtil.RandomSimpleString(Random(), 1, 10);
- }
- return tokens;
- }
-
- protected internal virtual string PickToken(string[] tokens)
- {
- for (int i = 0; i < tokens.Length; i++)
- {
- if (Random().NextBoolean())
- {
- return tokens[i];
- }
- }
-
- // Move long tail onto first token:
- return tokens[0];
- }
-
- protected internal class TestDoc
- {
- public string content;
- public string[] dims;
- public float value;
- }
-
- protected internal virtual IList<TestDoc> GetRandomDocs(string[] tokens, int count, int numDims)
- {
- IList<TestDoc> docs = new List<TestDoc>();
- for (int i = 0; i < count; i++)
- {
- TestDoc doc = new TestDoc();
- docs.Add(doc);
- doc.content = PickToken(tokens);
- doc.dims = new string[numDims];
- for (int j = 0; j < numDims; j++)
- {
- doc.dims[j] = PickToken(tokens);
- if (Random().Next(10) < 3)
- {
- break;
- }
- }
- if (VERBOSE)
- {
- Console.WriteLine(" doc " + i + ": content=" + doc.content);
- for (int j = 0; j < numDims; j++)
- {
- if (doc.dims[j] != null)
- {
- Console.WriteLine(" dim[" + j + "]=" + doc.dims[j]);
- }
- }
- }
- }
-
- return docs;
- }
-
- protected internal virtual void SortTies(IList<FacetResult> results)
- {
- foreach (FacetResult result in results)
- {
- SortTies(result.LabelValues);
- }
- }
-
- protected internal virtual void SortTies(LabelAndValue[] labelValues)
- {
- double lastValue = -1;
- int numInRow = 0;
- int i = 0;
- while (i <= labelValues.Length)
- {
- if (i < labelValues.Length && (double)labelValues[i].value == lastValue)
- {
- numInRow++;
- }
- else
- {
- if (numInRow > 1)
- {
- Array.Sort(labelValues, i - numInRow, i, new ComparatorAnonymousInnerClassHelper(this));
- }
- numInRow = 1;
- if (i < labelValues.Length)
- {
- lastValue = (double)labelValues[i].value;
- }
- }
- i++;
- }
- }
-
- private class ComparatorAnonymousInnerClassHelper : IComparer<LabelAndValue>
- {
- private readonly FacetTestCase outerInstance;
-
- public ComparatorAnonymousInnerClassHelper(FacetTestCase outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
- public virtual int Compare(LabelAndValue a, LabelAndValue b)
- {
- Debug.Assert((double)a.value == (double)b.value);
- return (new BytesRef(a.label)).CompareTo(new BytesRef(b.label));
- }
- }
-
- protected internal virtual void SortLabelValues(IList<LabelAndValue> labelValues)
- {
- var resArray = labelValues.ToArray();
- Array.Sort(resArray,new ComparatorAnonymousInnerClassHelper2(this));
- labelValues = resArray.ToList();
- }
-
- private class ComparatorAnonymousInnerClassHelper2 : IComparer<LabelAndValue>
- {
- private readonly FacetTestCase outerInstance;
-
- public ComparatorAnonymousInnerClassHelper2(FacetTestCase outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
- public virtual int Compare(LabelAndValue a, LabelAndValue b)
- {
- if ((double)a.value > (double)b.value)
- {
- return -1;
- }
- else if ((double)a.value < (double)b.value)
- {
- return 1;
- }
- else
- {
- return (new BytesRef(a.label)).CompareTo(new BytesRef(b.label));
- }
- }
- }
-
- protected internal virtual void SortFacetResults(IList<FacetResult> results)
- {
- var resArray = results.ToArray();
- Array.Sort(resArray, new ComparatorAnonymousInnerClassHelper3(this));
- results = resArray.ToList();
- }
-
- private class ComparatorAnonymousInnerClassHelper3 : IComparer<FacetResult>
- {
- private readonly FacetTestCase outerInstance;
-
- public ComparatorAnonymousInnerClassHelper3(FacetTestCase outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
- public virtual int Compare(FacetResult a, FacetResult b)
- {
- if ((double)a.Value > (double)b.Value)
- {
- return -1;
- }
- else if ((double)b.Value > (double)a.Value)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- }
-
- [Test]
- protected internal virtual void AssertFloatValuesEquals(IList<FacetResult> a, IList<FacetResult> b)
- {
- Assert.AreEqual(a.Count, b.Count);
- float lastValue = float.PositiveInfinity;
- IDictionary<string, FacetResult> aByDim = new Dictionary<string, FacetResult>();
- for (int i = 0; i < a.Count; i++)
- {
- Assert.True((float)a[i].Value <= lastValue);
- lastValue = (float)a[i].Value;
- aByDim[a[i].Dim] = a[i];
- }
- lastValue = float.PositiveInfinity;
- IDictionary<string, FacetResult> bByDim = new Dictionary<string, FacetResult>();
- for (int i = 0; i < b.Count; i++)
- {
- bByDim[b[i].Dim] = b[i];
- Assert.True((float)b[i].Value <= lastValue);
- lastValue = (float)b[i].Value;
- }
- foreach (string dim in aByDim.Keys)
- {
- AssertFloatValuesEquals(aByDim[dim], bByDim[dim]);
- }
- }
-
- [Test]
- protected internal virtual void AssertFloatValuesEquals(FacetResult a, FacetResult b)
- {
- Assert.AreEqual(a.Dim, b.Dim);
- Assert.True(Arrays.Equals(a.Path, b.Path));
- Assert.AreEqual(a.ChildCount, b.ChildCount);
- Assert.AreEqual((float)a.Value, (float)b.Value, (float)a.Value / 1e5);
- Assert.AreEqual(a.LabelValues.Length, b.LabelValues.Length);
- for (int i = 0; i < a.LabelValues.Length; i++)
- {
- Assert.AreEqual(a.LabelValues[i].label, b.LabelValues[i].label);
- Assert.AreEqual((float)a.LabelValues[i].value, (float)b.LabelValues[i].value, (float)a.LabelValues[i].value / 1e5);
- }
- }
- }
-
-}
\ No newline at end of file