lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1130715 - in /incubator/lucene.net/trunk: src/contrib/SimpleFacetedSearch/ src/contrib/SimpleFacetedSearch/Properties/ test/contrib/SimpleFacetedSearch/ test/contrib/SimpleFacetedSearch/Properties/
Date Thu, 02 Jun 2011 18:40:20 GMT
Author: digy
Date: Thu Jun  2 18:40:19 2011
New Revision: 1130715

URL: http://svn.apache.org/viewvc?rev=1130715&view=rev
Log:
[LUCENENET-415] SimpleFacetedSearch

Added:
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Extensions.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FacetName.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FieldValuesBitSets.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Hits.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/HitsPerFacet.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Properties/
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/README.txt
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.cs
    incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.csproj
    incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/
    incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/Properties/
    incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
    incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj
    incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Extensions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Extensions.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Extensions.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Extensions.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,56 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Search
+{
+    public static class Extensions
+    {
+        //CartesianProduct - Lambda
+        public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences)
+        {
+            IEnumerable<IEnumerable<T>> emptyProduct = new IEnumerable<T>[] { Enumerable.Empty<T>() };
+            return sequences.Aggregate(
+                emptyProduct,
+                (accumulator, sequence) =>
+                {
+                    return accumulator.SelectMany(
+                        (accseq => sequence),
+                        (accseq, item) => accseq.Concat(new T[] { item })
+                    );
+                }
+            );
+        }
+
+        //CartesianProduct - LINQ
+        //http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx
+        static IEnumerable<IEnumerable<T>> CartesianProduct2<T>(this IEnumerable<IEnumerable<T>> sequences)
+        {
+            IEnumerable<IEnumerable<T>> emptyProduct = new[] { Enumerable.Empty<T>() };
+            return sequences.Aggregate(
+                emptyProduct,
+                (accumulator, sequence) =>
+                    from accseq in accumulator
+                    from item in sequence
+                    select accseq.Concat(new[] { item }));
+        }
+    }
+}

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FacetName.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FacetName.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FacetName.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FacetName.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,51 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Search
+{
+    public partial class SimpleFacetedSearch
+    {
+        public class FacetName
+        {
+            string[] _Names;
+            internal FacetName(string[] names)
+            {
+                this._Names = names;
+            }
+
+            public string this[int i]
+            {
+                get { return _Names[i]; }
+            }
+
+            public int Length
+            {
+                get { return _Names.Length; }
+            }
+
+            public override string ToString()
+            {
+                return String.Join("/", _Names);
+            }
+        }
+    }
+}

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FieldValuesBitSets.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FieldValuesBitSets.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FieldValuesBitSets.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/FieldValuesBitSets.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,75 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Search
+{
+
+    class FieldValuesBitSets
+    {
+        public string Field = "";
+        public Dictionary<string, OpenBitSetDISI> FieldValueBitSetPair = new Dictionary<string, OpenBitSetDISI>();
+
+        IndexReader _Reader;
+
+        public FieldValuesBitSets(IndexReader reader, string field)
+        {
+            this.Field = field;
+            this._Reader = reader;
+
+            foreach (string val in GetFieldValues(field))
+            {
+                FieldValueBitSetPair.Add(val, GetBitSet(field, val));
+            }
+        }
+
+        List<string> GetFieldValues(string groupByField)
+        {
+            List<string> list = new List<string>();
+            TermEnum te = _Reader.Terms(new Term(groupByField, ""));
+            if (te.Term().Field() != groupByField) return list;
+            list.Add(te.Term().Text());
+
+            while (te.Next())
+            {
+                if (te.Term().Field() != groupByField) break;
+                list.Add(te.Term().Text());
+            }
+            return list;
+        }
+
+        OpenBitSetDISI GetBitSet(string groupByField, string group)
+        {
+            TermQuery query = new TermQuery(new Term(groupByField, group));
+            Filter filter = new CachingWrapperFilter(new QueryWrapperFilter(query));
+            return new OpenBitSetDISI(filter.GetDocIdSet(_Reader).Iterator(), _Reader.MaxDoc());
+        }
+    }
+}

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Hits.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Hits.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Hits.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Hits.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,73 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Search
+{
+    public partial class SimpleFacetedSearch
+    {
+        public class Hits
+        {
+            long _TotalHitCount = -1;
+            HitsPerFacet[] _HitsPerGroup;
+            Dictionary<string, HitsPerFacet> _Indexer = new Dictionary<string, HitsPerFacet>();
+            
+            public HitsPerFacet this[string name]
+            {
+                get{ return _Indexer[name];}
+            }
+
+            public HitsPerFacet this[FacetName name]
+            {
+                get { return _Indexer[name.ToString()]; }
+            }
+
+            public long TotalHitCount
+            {
+                get
+                {
+                    if (_TotalHitCount == -1)
+                    {
+                        _TotalHitCount = 0;
+                        foreach (var h in _HitsPerGroup)
+                        {
+                            _TotalHitCount += h.HitCount;
+                        }
+                    }
+                    return _TotalHitCount;
+                }
+            }
+
+            public HitsPerFacet[] HitsPerFacet
+            {
+                get { return _HitsPerGroup; }
+                internal set
+                {
+                    _HitsPerGroup = value;
+                    foreach (var h in _HitsPerGroup)
+                    {
+                        _Indexer.Add(h.Name.ToString(), h);
+                    }
+                }
+            }
+        }
+    }
+}

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/HitsPerFacet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/HitsPerFacet.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/HitsPerFacet.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/HitsPerFacet.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,133 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Search
+{
+    public partial class SimpleFacetedSearch
+    {
+        public class HitsPerFacet : IEnumerable<Document>, IEnumerator<Document>
+        {
+            IndexReader _Reader;
+            int _MaxDocPerFacet;
+            int _ItemsReturned = 0;
+            DocIdSetIterator _ResultIterator;
+            OpenBitSet _ResultBitSet;
+            int _CurrentDocId;
+            DocIdSet _QueryDocidSet;
+            OpenBitSetDISI _GroupBitSet;
+
+            FacetName _FacetName;
+            long _HitCount = -1;
+
+            internal HitsPerFacet(FacetName facetName, IndexReader reader, DocIdSet queryDocidSet, OpenBitSetDISI groupBitSet, int maxDocPerFacet)
+            {
+                this._FacetName = facetName;
+                this._Reader = reader;
+                this._MaxDocPerFacet = maxDocPerFacet;
+                this._QueryDocidSet = queryDocidSet;
+                this._GroupBitSet = groupBitSet;
+                
+            }
+
+            internal void Calculate()
+            {
+                if (_QueryDocidSet == DocIdBitSet.EMPTY_DOCIDSET)
+                {
+                    _ResultBitSet = new OpenBitSet(0);
+                }
+                else
+                {
+                    _ResultBitSet = (OpenBitSet)((OpenBitSet)_QueryDocidSet).Clone();
+                    _ResultBitSet.And(_GroupBitSet);
+                }
+                
+                _ResultIterator = _ResultBitSet.Iterator();
+
+                _HitCount = _ResultBitSet.Cardinality();
+
+                _ResultBitSet = null;
+                _QueryDocidSet = null;
+                _GroupBitSet = null;
+            }
+
+            public FacetName Name
+            {
+                get { return _FacetName; }
+            }
+
+            public long HitCount
+            {
+                get{ return _HitCount; }
+            }
+
+            public Document Current
+            {
+                get { return _Reader.Document(_CurrentDocId); }
+            }
+
+            object System.Collections.IEnumerator.Current
+            {
+                get { return _Reader.Document(_CurrentDocId); }
+            }
+
+            public bool MoveNext()
+            {
+                _CurrentDocId = _ResultIterator.NextDoc();
+                return _CurrentDocId != DocIdSetIterator.NO_MORE_DOCS && ++_ItemsReturned <= _MaxDocPerFacet;
+            }
+
+            public IEnumerator<Document> GetEnumerator()
+            {
+                return this;
+            }
+
+            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+            {
+                return this;
+            }
+
+            public void Reset()
+            {
+                throw new NotImplementedException();
+            }
+
+            public void Dispose()
+            {
+
+            }
+
+            public HitsPerFacet Documents
+            {
+                get { return this; }
+            }
+        }
+    }
+}

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,40 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Lucene.Net.Search.SimpleFacetedSearch")]
+[assembly: AssemblyDescription("SimpleFacetedSearch for Lucene.Net")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Lucene.Net.SimpleFacetedSearch")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("dfa80a55-3bcc-4d3c-872c-dab7ccc1bfb5")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers 
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("2.9.4")]
+[assembly: AssemblyFileVersion("2.9.4")]
+
+
+
+
+

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/README.txt
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/README.txt?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/README.txt (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/README.txt Thu Jun  2 18:40:19 2011
@@ -0,0 +1,28 @@
+SimpleFacetedSearch: Dynamic clustering of search results into categories according to values in given field(s). 
+Its instances are tread-safe. So, the same instance can be shared among many threads like IndexReader.
+
+Sample Usage:
+
+    //Should be created only when IndexReader is opened/reopened. Creation with every search can be performance killer
+    SimpleFacetedSearch sfs = new SimpleFacetedSearch(indexReader, new string[] { "source", "category" });
+
+    Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, field, analyzer).Parse(searchString);
+    SimpleFacetedSearch.Hits hits = sfs.Search(query, 10);
+    
+	long totalHits = hits.TotalHitCount;
+	
+    foreach (SimpleFacetedSearch.HitsPerFacet hpf in hits.HitsPerFacet)
+    {
+		long hitCountPerFacet = hpf.HitCount;
+        SimpleFacetedSearch.FacetName name = hpf.Name;
+		//name[0] 
+		//name[1]
+		//name.ToString()
+		
+        foreach (Document doc in hpf.Documents)
+        {
+             ........
+        }
+    }
+
+

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,151 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using System.Threading;
+using System.Threading.Tasks;
+
+/*
+ Suppose, we want a faceted search on fields f1 f2 f3, 
+ and their values in index are
+ 
+          f1     f2     f3
+          --     --     --
+doc1      A      I      1  
+doc2      A      I      2  
+doc3      A      I      3  
+doc4      A      J      1  
+doc5      A      J      2  
+doc6      A      J      3  
+doc7      B      I      1  
+ 
+ Algorithm:
+ 1- Find all possible values for f1 which are (A,B) , for f2 which are (I,J) and for f3 which are (1,2,3)
+ 2- Find Cartesian Product of (A,B)X(I,J)X(1,2,3). (12 possible groups)
+ 3- Eliminate the ones that surely result in 0 hits. (for ex, B J 2. since they have no doc. in common)
+*/
+
+/*
+ TODO: Support for pre-built queries defining groups can be added 
+*/
+
+namespace Lucene.Net.Search
+{
+    public partial class SimpleFacetedSearch : IDisposable
+    {
+        public const int DefaultMaxDocPerGroup = 25;
+        public static int MAX_FACETS = 2048;
+
+        IndexReader _Reader;
+        List<KeyValuePair<List<string>, OpenBitSetDISI>> _Groups = new List<KeyValuePair<List<string>, OpenBitSetDISI>>();
+        
+        public SimpleFacetedSearch(IndexReader reader, string groupByField) : this(reader, new string[] { groupByField })
+        {
+        }
+
+        public SimpleFacetedSearch(IndexReader reader, string[] groupByFields)
+        {
+            this._Reader = reader;
+
+            List<FieldValuesBitSets> fieldValuesBitSets = new List<FieldValuesBitSets>();
+
+            //STEP 1
+            //f1 = A, B
+            //f2 = I, J
+            //f3 = 1, 2, 3
+            int maxFacets = 1;
+            List<List<string>> inputToCP = new List<List<string>>();
+            foreach (string field in groupByFields)
+            {
+                FieldValuesBitSets f = new FieldValuesBitSets(reader, field);
+                maxFacets *= f.FieldValueBitSetPair.Count;
+                if (maxFacets > MAX_FACETS) throw new Exception("Facet count exceeded " + MAX_FACETS);
+                fieldValuesBitSets.Add(f);
+                inputToCP.Add(f.FieldValueBitSetPair.Keys.ToList());
+            }
+
+            //STEP 2
+            // comb1: A I 1
+            // comb2: A I 2 etc.
+            var cp = inputToCP.CartesianProduct();
+
+            //SETP 3
+            //create a single BitSet for each combination
+            //BitSet1: A AND I AND 1
+            //BitSet2: A AND I AND 2 etc.
+            //and remove impossible comb's (for ex, B J 3) from list.
+            Parallel.ForEach(cp, combinations =>
+            {
+                OpenBitSetDISI bitSet = new OpenBitSetDISI(_Reader.MaxDoc());
+                bitSet.Set(0, bitSet.Size());
+
+                List<string> comb = combinations.ToList();
+
+                for (int j = 0; j < comb.Count; j++)
+                {
+                    bitSet.And(fieldValuesBitSets[j].FieldValueBitSetPair[comb[j]]);
+                }
+
+                //STEP 3
+                if (bitSet.Cardinality() > 0)
+                {
+                    lock(_Groups)
+                        _Groups.Add(new KeyValuePair<List<string>, OpenBitSetDISI>(comb, bitSet));
+                }
+            });
+
+            //Now _Groups has 7 rows (as <List<string>, BitSet> pairs) 
+        }
+        
+        public Hits Search(Query query, int maxDocPerGroup = DefaultMaxDocPerGroup)
+        {
+            List<HitsPerFacet> hitsPerGroup = new List<HitsPerFacet>();
+
+            DocIdSet queryDocidSet = new CachingWrapperFilter(new QueryWrapperFilter(query)).GetDocIdSet(_Reader);
+            Action[] actions = new Action[_Groups.Count];           
+            for (int i = 0; i < _Groups.Count; i++)
+            {
+                HitsPerFacet h = new HitsPerFacet(new FacetName(_Groups[i].Key.ToArray()), _Reader, queryDocidSet, _Groups[i].Value, maxDocPerGroup);
+                hitsPerGroup.Add(h);
+                actions[i] = () => h.Calculate();
+            }
+            
+            Parallel.Invoke(actions);
+            
+            Hits hits = new Hits();
+            hits.HitsPerFacet = hitsPerGroup.ToArray();
+
+            return hits;
+        }
+
+        public void Dispose()
+        {
+        }
+    }
+}

Added: incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.csproj?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.csproj (added)
+++ incubator/lucene.net/trunk/src/contrib/SimpleFacetedSearch/SimpleFacetedSearch.csproj Thu Jun  2 18:40:19 2011
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{66772190-FB3F-48F5-8E05-0B302BACEA73}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Lucene.Net.Search.SimpleFacetedSearch</RootNamespace>
+    <AssemblyName>Lucene.Net.Search.SimpleFacetedSearch</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\..\bin\contrib\SimpleFacetedSearch\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Extensions.cs" />
+    <Compile Include="FieldValuesBitSets.cs" />
+    <Compile Include="FacetName.cs" />
+    <Compile Include="Hits.cs" />
+    <Compile Include="HitsPerFacet.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SimpleFacetedSearch.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\core\Lucene.Net.csproj">
+      <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
+      <Name>Lucene.Net</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

Added: incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs (added)
+++ incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/Properties/AssemblyInfo.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Test for Lucene.Net.Search.SimpleFacetedSearch")]
+[assembly: AssemblyDescription("Test for SimpleFacetedSearch for Lucene.Net")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Lucene.Net.SimpleFacetedSearch")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("df0ddee7-24b4-48bd-ba39-21bbd4fc39c3")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers 
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("2.9.4")]
+[assembly: AssemblyFileVersion("2.9.4")]

Added: incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj (added)
+++ incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/SimpleFacetedSearch.Test.csproj Thu Jun  2 18:40:19 2011
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{D8CC9461-64E0-416E-BA6E-1DF6FA66CBF5}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Lucene.Net.Search.SimpleFacetedSearch</RootNamespace>
+    <AssemblyName>Lucene.Net.Search.SimpleFacetedSearch.Test</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\..\bin\contrib\SimpleFacetedSearch\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\lib\NUnit.org\NUnit\2.5.9\bin\net-2.0\nunit.framework.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="TestSimpleFacetedSearch.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\src\contrib\SimpleFacetedSearch\SimpleFacetedSearch.csproj">
+      <Project>{66772190-FB3F-48F5-8E05-0B302BACEA73}</Project>
+      <Name>SimpleFacetedSearch</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\src\core\Lucene.Net.csproj">
+      <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
+      <Name>Lucene.Net</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

Added: incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs?rev=1130715&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs (added)
+++ incubator/lucene.net/trunk/test/contrib/SimpleFacetedSearch/TestSimpleFacetedSearch.cs Thu Jun  2 18:40:19 2011
@@ -0,0 +1,334 @@
+/* 
+ * 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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.QueryParsers;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+
+using NUnit.Framework;
+
+namespace Lucene.Net.Search
+{
+    [TestFixture]
+    public class TestSimpleFacetedSearch
+    {
+        Directory _Dir = new RAMDirectory();
+        IndexReader _Reader;
+
+        [SetUp]
+        public void SetUp()
+        {
+
+            IndexWriter writer = new IndexWriter(_Dir, new StandardAnalyzer(), true);
+
+            AddDoc(writer, "us", "CCN", "politics", "The White House doubles down on social media");
+            AddDoc(writer, "us", "CCN", "politics", "Senate Dems fail to block filibuster over judicial nominee");
+            AddDoc(writer, "us", "BCC", "politics", "A frozen pig's foot and a note laced with anti-Semitic rants were sent to Rep. Peter King's Capitol Hill office, a congressional source familiar with the situation confirmed to CNN Monday");
+            AddDoc(writer, "us", "CCN", "sport", "But when all was said and done, Haslem's 13 points, five rebounds, two assists, one block and one steal in the course of 23 minutes");
+            AddDoc(writer, "en", "CCN", "tech", "blockingQueue<T> contains two private fields and exposes two public methods.");
+            AddDoc(writer, "en", "BCC", "tech", "An Argentine court this week granted an injunction that blocks the Internet giant from 'suggesting' searches that lead to certain sites that have been deemed anti-Semitic, and removes the sites from the search engine's index");
+            AddDoc(writer, "en", "CCN", "dummy", "oooooooooooooooooooooo");
+            writer.Close();
+
+            _Reader = IndexReader.Open(_Dir);
+        }
+
+        void AddDoc(IndexWriter writer, string lang, string source, string group, string text)
+        {
+            Field f0 = new Field("lang", lang, Field.Store.YES, Field.Index.NOT_ANALYZED);
+            Field f1 = new Field("source", source, Field.Store.YES, Field.Index.NOT_ANALYZED);
+            Field f2 = new Field("category", group, Field.Store.YES, Field.Index.NOT_ANALYZED);
+            Field f3 = new Field("text", text, Field.Store.YES, Field.Index.ANALYZED);
+            Document doc = new Document();
+            doc.Add(f0);
+            doc.Add(f1);
+            doc.Add(f2);
+            doc.Add(f3);
+            writer.AddDocument(doc);
+        }
+
+        [Test]
+        public void Test1()
+        {
+            //See, Is there an exception
+            HowToUse("block*");
+            HowToUse("qwertyuiop");
+            //OK. No exception
+        }
+
+        [Test]
+        public void Test2()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(4, hits.HitsPerFacet.Length);
+
+            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
+            {
+                if (hpg.Name[0] == "politics")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "tech")
+                {
+                    Assert.AreEqual(2, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "sport")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                {
+                    Assert.AreEqual(0, hpg.HitCount);
+                }
+            }
+
+            Assert.AreEqual(4, hits.TotalHitCount);
+
+            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
+            {
+                foreach (Document doc in hpg.Documents)
+                {
+                    string text = doc.GetField("text").StringValue();
+                    Assert.IsTrue(text.Contains("block"));
+                }
+            }
+        }
+
+        [Test]
+        public void Test3()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "lang", "source", "category" });
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(6, hits.HitsPerFacet.Length);
+            int nohit = 0;
+
+            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
+            {
+                //Test for [System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.]
+                var x = hits[hpg.Name];
+                var y = hits[hpg.Name.ToString()];
+
+                if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "politics")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "en" && hpg.Name[1] == "BCC" && hpg.Name[2] == "tech")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "sport")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                if (hpg.Name[0] == "en" && hpg.Name[1] == "CCN" && hpg.Name[2] == "tech")
+                {
+                    Assert.AreEqual(1, hpg.HitCount);
+                }
+                else
+                {
+                    nohit++;
+                    Assert.AreEqual(0, hpg.HitCount);
+                }
+            }
+            Assert.AreEqual(2, nohit);
+            Assert.AreEqual(4, hits.TotalHitCount);
+
+            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
+            {
+                foreach (Document doc in hpg.Documents)
+                {
+                    string text = doc.GetField("text").StringValue();
+                    Assert.IsTrue(text.Contains("block"));
+                }
+            }
+        }
+
+        [Test]
+        public void Test4()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("xxxxxxxxxxxxx");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(4, hits.HitsPerFacet.Length);
+            Assert.AreEqual(0, hits.HitsPerFacet[0].HitCount);
+            Assert.AreEqual(0, hits.HitsPerFacet[1].HitCount);
+            Assert.AreEqual(0, hits.HitsPerFacet[2].HitCount);
+        }
+
+        [Test]
+        public void Test5()
+        {
+            Query query = new MatchAllDocsQuery();
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(7, hits.TotalHitCount);
+        }
+
+        [Test]
+        public void Test6()
+        {
+            Query query = new MatchAllDocsQuery();
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "nosuchfield");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(0, hits.TotalHitCount);
+            Assert.AreEqual(0, hits.HitsPerFacet.Length);
+        }
+
+        [Test]
+        public void Test7()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("a");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");
+            SimpleFacetedSearch.Hits hits = sfs.Search(query);
+
+            Assert.AreEqual(0, hits.TotalHitCount, "Unexpected TotalHitCount");
+            foreach(var x in hits.HitsPerFacet.Where(h=>h.HitCount>0))
+            {
+                Assert.Fail("There must be no hit");
+            }
+            
+        }
+
+        int _errorCount = 0;
+        void MultiThreadedAccessThread(object o)
+        {
+            SimpleFacetedSearch sfs = (SimpleFacetedSearch)o;
+
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");
+
+            for (int i = 0; i < 2000; i++)
+            {
+                SimpleFacetedSearch.Hits hits = sfs.Search(query);
+                
+                if (6 != hits.HitsPerFacet.Length) _errorCount++;
+                
+                foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
+                {
+                    if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "politics")
+                    {
+                        if (1 != hpg.HitCount) _errorCount++;
+                    }
+                    else
+                    if (hpg.Name[0] == "en" && hpg.Name[1] == "BCC" && hpg.Name[2] == "tech")
+                    {
+                        if (1 != hpg.HitCount) _errorCount++;
+                    }
+                    else
+                    if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "sport")
+                    {
+                        if (1 != hpg.HitCount) _errorCount++;
+                    }
+                    else
+                    if (hpg.Name[0] == "en" && hpg.Name[1] == "CCN" && hpg.Name[2] == "tech")
+                    {
+                        if (1 != hpg.HitCount) _errorCount++;
+                    }
+                    else
+                    {
+                        if (0 != hpg.HitCount) _errorCount++;
+                    }
+
+                    if (4 != hits.TotalHitCount) _errorCount++;
+                }
+            }
+            
+        }
+
+        [Test]
+        public void TestMultiThreadedAccess()
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "lang", "source", "category" });
+            _errorCount = 0;
+
+            Thread[] t = new Thread[20];
+            for (int i = 0; i < t.Length; i++)
+            {
+                t[i] = new Thread(MultiThreadedAccessThread);
+                t[i].Start(sfs);
+            }
+            for (int i = 0; i < t.Length; i++)
+            {
+                t[i].Join();
+            }
+            
+            Assert.AreEqual(0, _errorCount);
+        }
+
+        /// <summary>
+        /// *****************************************************
+        /// * SAMPLE USAGE                                      *
+        /// *****************************************************
+        /// </summary>
+        void HowToUse(string searchString)
+        {
+            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse(searchString);
+
+            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "source", "category" });
+            SimpleFacetedSearch.Hits hits = sfs.Search(query, 10);
+
+            long totalHits = hits.TotalHitCount;
+            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
+            {
+                long hitCountPerGroup = hpg.HitCount;
+                SimpleFacetedSearch.FacetName facetName = hpg.Name;
+                for (int i = 0; i < facetName.Length; i++)
+                {
+                    string part = facetName[i];
+                }
+                foreach (Document doc in hpg.Documents)
+                {
+                    string text = doc.GetField("text").StringValue();
+                    System.Diagnostics.Debug.WriteLine(">>" + facetName + ": " + text);
+                }
+            }
+        }
+
+    }
+}
+



Mime
View raw message