Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
HitsPerFacet.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 
23 using Lucene.Net.Analysis;
24 using Lucene.Net.Documents;
25 using Lucene.Net.Analysis.Standard;
26 using Lucene.Net.Index;
27 using Lucene.Net.Search;
28 using Lucene.Net.QueryParsers;
29 using Lucene.Net.Store;
30 using Lucene.Net.Util;
31 
32 namespace Lucene.Net.Search
33 {
34  public partial class SimpleFacetedSearch
35  {
36  public class HitsPerFacet : IEnumerable<Document>, IEnumerator<Document>
37  {
38  IndexReader _Reader;
39  int _MaxDocPerFacet;
40  int _ItemsReturned = 0;
41  DocIdSetIterator _ResultIterator;
42  OpenBitSet _ResultBitSet;
43  int _CurrentDocId;
44  DocIdSet _QueryDocidSet;
45  OpenBitSetDISI _GroupBitSet;
46 
47  FacetName _FacetName;
48  long _HitCount = -1;
49 
50  internal HitsPerFacet(FacetName facetName, IndexReader reader, DocIdSet queryDocidSet, OpenBitSetDISI groupBitSet, int maxDocPerFacet)
51  {
52  this._FacetName = facetName;
53  this._Reader = reader;
54  this._MaxDocPerFacet = maxDocPerFacet;
55  this._QueryDocidSet = queryDocidSet;
56  this._GroupBitSet = groupBitSet;
57 
58  }
59 
60  internal void Calculate()
61  {
62  if (_QueryDocidSet == DocIdBitSet.EMPTY_DOCIDSET)
63  {
64  _ResultBitSet = new OpenBitSet(0);
65  }
66  else
67  {
68  _ResultBitSet = (OpenBitSet)((OpenBitSet)_QueryDocidSet).Clone();
69  _ResultBitSet.And(_GroupBitSet);
70  }
71 
72  _ResultIterator = _ResultBitSet.Iterator();
73 
74  _HitCount = _ResultBitSet.Cardinality();
75 
76  _ResultBitSet = null;
77  _QueryDocidSet = null;
78  _GroupBitSet = null;
79  }
80 
81  public FacetName Name
82  {
83  get { return _FacetName; }
84  }
85 
86  public long HitCount
87  {
88  get{ return _HitCount; }
89  }
90 
91  public Document Current
92  {
93  get { return _Reader.Document(_CurrentDocId); }
94  }
95 
96  object System.Collections.IEnumerator.Current
97  {
98  get { return _Reader.Document(_CurrentDocId); }
99  }
100 
101  public bool MoveNext()
102  {
103  _CurrentDocId = _ResultIterator.NextDoc();
104  return _CurrentDocId != DocIdSetIterator.NO_MORE_DOCS && ++_ItemsReturned <= _MaxDocPerFacet;
105  }
106 
107  public IEnumerator<Document> GetEnumerator()
108  {
109  return this;
110  }
111 
112  System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
113  {
114  return this;
115  }
116 
117  public void Reset()
118  {
119  throw new NotImplementedException();
120  }
121 
122  public void Dispose()
123  {
124 
125  }
126 
127  public HitsPerFacet Documents
128  {
129  get { return this; }
130  }
131  }
132  }
133 }