You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/03/30 15:05:34 UTC

[lucenenet] 07/15: docs: Lucene.Net.Grouping: Fixed broken formatting and links (see #284, #300)

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 1132c37321cd7a48d1a386de602e7ebfa2040d62
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Tue Mar 30 19:42:11 2021 +0700

    docs: Lucene.Net.Grouping: Fixed broken formatting and links (see #284, #300)
---
 src/Lucene.Net.Grouping/Function/package.md |   2 +-
 src/Lucene.Net.Grouping/package.md          | 132 +++++++++++++++-------------
 2 files changed, 72 insertions(+), 62 deletions(-)

diff --git a/src/Lucene.Net.Grouping/Function/package.md b/src/Lucene.Net.Grouping/Function/package.md
index 73ff1a5..76567d8 100644
--- a/src/Lucene.Net.Grouping/Function/package.md
+++ b/src/Lucene.Net.Grouping/Function/package.md
@@ -1,4 +1,4 @@
----
+---
 uid: Lucene.Net.Search.Grouping.Function
 summary: *content
 ---
diff --git a/src/Lucene.Net.Grouping/package.md b/src/Lucene.Net.Grouping/package.md
index 8b3118c..1c563a3 100644
--- a/src/Lucene.Net.Grouping/package.md
+++ b/src/Lucene.Net.Grouping/package.md
@@ -1,4 +1,4 @@
----
+---
 uid: Lucene.Net.Grouping
 title: Lucene.Net.Grouping
 summary: *content
@@ -21,7 +21,7 @@ summary: *content
  limitations under the License.
 -->
 
-This module enables search result grouping with Lucene, where hits with the same value in the specified single-valued group field are grouped together. For example, if you group by the `author` field, then all documents with the same value in the `author` field fall into a single group.
+This module enables search result grouping with Lucene.NET, where hits with the same value in the specified single-valued group field are grouped together. For example, if you group by the `author` field, then all documents with the same value in the `author` field fall into a single group.
 
 Grouping requires a number of inputs:
 
@@ -56,7 +56,7 @@ Grouping requires a number of inputs:
 *   `withinGroupOffset`: which "slice" of top
       documents you want to retrieve from each group.
 
-The implementation is two-pass: the first pass (<xref:Lucene.Net.Grouping.Term.TermFirstPassGroupingCollector>) gathers the top groups, and the second pass (<xref:Lucene.Net.Grouping.Term.TermSecondPassGroupingCollector>) gathers documents within those groups. If the search is costly to run you may want to use the <xref:Lucene.Net.Search.CachingCollector> class, which caches hits and can (quickly) replay them for the second pass. This way you only run the query once, but you pay a RAM co [...]
+The implementation is two-pass: the first pass (<xref:Lucene.Net.Search.Grouping.Terms.TermFirstPassGroupingCollector>) gathers the top groups, and the second pass (<xref:Lucene.Net.Search.Grouping.Terms.TermSecondPassGroupingCollector>) gathers documents within those groups. If the search is costly to run you may want to use the <xref:Lucene.Net.Search.CachingCollector> class, which caches hits and can (quickly) replay them for the second pass. This way you only run the query once, but  [...]
 
  This module abstracts away what defines group and how it is collected. All grouping collectors are abstract and have currently term based implementations. One can implement collectors that for example group on multiple fields. 
 
@@ -75,71 +75,79 @@ Known limitations:
 
 Typical usage for the generic two-pass grouping search looks like this using the grouping convenience utility (optionally using caching for the second pass search):
 
-      GroupingSearch groupingSearch = new GroupingSearch("author");
-      groupingSearch.setGroupSort(groupSort);
-      groupingSearch.setFillSortFields(fillFields);
-    
-  if (useCache) {
-        // Sets cache in MB
-        groupingSearch.setCachingInMB(4.0, true);
-      }
-    
-  if (requiredTotalGroupCount) {
-        groupingSearch.setAllGroups(true);
-      }
-    
-  TermQuery query = new TermQuery(new Term("content", searchTerm));
-      TopGroups<BytesRef> result = groupingSearch.search(indexSearcher, query, groupOffset, groupLimit);
-    
-  // Render groupsResult...
-      if (requiredTotalGroupCount) {
-        int totalGroupCount = result.totalGroupCount;
-      }
+```cs
+GroupingSearch groupingSearch = new GroupingSearch("author");
+groupingSearch.SetGroupSort(groupSort);
+groupingSearch.SetFillSortFields(fillFields);
+
+if (useCache)
+{
+    // Sets cache in MB
+    groupingSearch.SetCachingInMB(maxCacheRAMMB: 4.0, cacheScores: true);
+}
+
+if (requiredTotalGroupCount)
+{
+    groupingSearch.SetAllGroups(true);
+}
+
+TermQuery query = new TermQuery(new Term("content", searchTerm));
+TopGroups<BytesRef> result = groupingSearch.Search(indexSearcher, query, groupOffset, groupLimit);
+
+// Render groupsResult...
+if (requiredTotalGroupCount)
+{
+    // If null, the value is not computed
+    int? totalGroupCount = result.TotalGroupCount;
+}
+```
 
 To use the single-pass `BlockGroupingCollector`, first, at indexing time, you must ensure all docs in each group are added as a block, and you have some way to find the last document of each group. One simple way to do this is to add a marker binary field:
 
-      // Create Documents from your source:
-      List<Document> oneGroup = ...;
+```cs
+// Create Documents from your source:
+List<Document> oneGroup = ...;
 
-      Field groupEndField = new Field("groupEnd", "x", Field.Store.NO, Field.Index.NOT_ANALYZED);
-      groupEndField.setIndexOptions(IndexOptions.DOCS_ONLY);
-      groupEndField.setOmitNorms(true);
-      oneGroup.get(oneGroup.size()-1).add(groupEndField);
-    
-  // You can also use writer.updateDocuments(); just be sure you
-      // replace an entire previous doc block with this new one.  For
-      // example, each group could have a "groupID" field, with the same
-      // value for all docs in this group:
-      writer.addDocuments(oneGroup);
+Field groupEndField = new StringField("groupEnd", "x", Field.Store.NO);
+oneGroup[oneGroup.Count - 1].Add(groupEndField);
 
+// You can also use writer.UpdateDocuments(); just be sure you
+// replace an entire previous doc block with this new one.  For
+// example, each group could have a "groupID" field, with the same
+// value for all docs in this group:
+writer.AddDocuments(oneGroup);
+```
 
 Then, at search time, do this up front:
 
-      // Set this once in your app & save away for reusing across all queries:
-      Filter groupEndDocs = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupEnd", "x"))));
-
+```cs
+// Set this once in your app & save away for reusing across all queries:
+Filter groupEndDocs = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupEnd", "x"))));
+```
 
 Finally, do this per search:
 
-      // Per search:
-      BlockGroupingCollector c = new BlockGroupingCollector(groupSort, groupOffset+topNGroups, needsScores, groupEndDocs);
-      s.search(new TermQuery(new Term("content", searchTerm)), c);
-      TopGroups groupsResult = c.getTopGroups(withinGroupSort, groupOffset, docOffset, docOffset+docsPerGroup, fillFields);
-    
-  // Render groupsResult...
+```cs
+// Per search:
+BlockGroupingCollector c = new BlockGroupingCollector(groupSort, groupOffset + topNGroups, needsScores, groupEndDocs);
+s.Search(new TermQuery(new Term("content", searchTerm)), c);
+TopGroups<object> groupsResult = c.GetTopGroups(withinGroupSort, groupOffset, docOffset, docOffset + docsPerGroup, fillFields);
 
+// Render groupsResult...
+```
 
 Or alternatively use the `GroupingSearch` convenience utility:
 
-      // Per search:
-      GroupingSearch groupingSearch = new GroupingSearch(groupEndDocs);
-      groupingSearch.setGroupSort(groupSort);
-      groupingSearch.setIncludeScores(needsScores);
-      TermQuery query = new TermQuery(new Term("content", searchTerm));
-      TopGroups groupsResult = groupingSearch.search(indexSearcher, query, groupOffset, groupLimit);
-    
-  // Render groupsResult...
+```cs
+// Per search:
+GroupingSearch groupingSearch = new GroupingSearch(groupEndDocs);
+groupingSearch.SetGroupSort(groupSort);
+groupingSearch.SetIncludeScores(needsScores);
+TermQuery query = new TermQuery(new Term("content", searchTerm));
+TopGroups<object> groupsResult = groupingSearch.Search(indexSearcher, query, groupOffset, groupLimit);
 
+// Render groupsResult...
+```
 
 Note that the `groupValue` of each `GroupDocs`
 will be `null`, so if you need to present this value you'll
@@ -148,12 +156,14 @@ fields, `FieldCache`, etc.).
 
 Another collector is the `TermAllGroupHeadsCollector` that can be used to retrieve all most relevant documents per group. Also known as group heads. This can be useful in situations when one wants to compute group based facets / statistics on the complete query result. The collector can be executed during the first or second phase. This collector can also be used with the `GroupingSearch` convenience utility, but when if one only wants to compute the most relevant documents per group it  [...]
 
-      AbstractAllGroupHeadsCollector c = TermAllGroupHeadsCollector.create(groupField, sortWithinGroup);
-      s.search(new TermQuery(new Term("content", searchTerm)), c);
-      // Return all group heads as int array
-      int[] groupHeadsArray = c.retrieveGroupHeads()
-      // Return all group heads as FixedBitSet.
-      int maxDoc = s.maxDoc();
-      FixedBitSet groupHeadsBitSet = c.retrieveGroupHeads(maxDoc)
-
-For each of the above collector types there is also a variant that works with `ValueSource` instead of of fields. Concretely this means that these variants can work with functions. These variants are slower than there term based counter parts. These implementations are located in the `org.apache.lucene.search.grouping.function` package, but can also be used with the `GroupingSearch` convenience utility 
\ No newline at end of file
+```cs
+AbstractAllGroupHeadsCollector c = TermAllGroupHeadsCollector.Create(groupField, sortWithinGroup);
+s.Search(new TermQuery(new Term("content", searchTerm)), c);
+// Return all group heads as int array
+int[] groupHeadsArray = c.RetrieveGroupHeads();
+// Return all group heads as FixedBitSet.
+int maxDoc = s.MaxDoc;
+FixedBitSet groupHeadsBitSet = c.RetrieveGroupHeads(maxDoc);
+```
+
+For each of the above collector types there is also a variant that works with `ValueSource` instead of of fields. Concretely this means that these variants can work with functions. These variants are slower than there term based counter parts. These implementations are located in the `Lucene.Net.Search.Grouping.Function` package, but can also be used with the `GroupingSearch` convenience utility 
\ No newline at end of file