aboutsummaryrefslogtreecommitdiffhomepage
path: root/related/inverted_index_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-02-23 15:20:31 +0100
committerBjørn Erik Pedersen <[email protected]>2023-02-23 17:06:22 +0100
commite442a63bb7659d95aec2d48bf954cd9d61163559 (patch)
treed8868929c74430e530f41ff8a359f451fd981729 /related/inverted_index_test.go
parentd5601e8391470be952ba48948c5a976884fea871 (diff)
downloadhugo-e442a63bb7659d95aec2d48bf954cd9d61163559.tar.gz
hugo-e442a63bb7659d95aec2d48bf954cd9d61163559.zip
related: Add config option cardinalityThreshold
Fixes #10744
Diffstat (limited to 'related/inverted_index_test.go')
-rw-r--r--related/inverted_index_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/related/inverted_index_test.go b/related/inverted_index_test.go
index d38a7f6eb..c7348e088 100644
--- a/related/inverted_index_test.go
+++ b/related/inverted_index_test.go
@@ -86,6 +86,41 @@ func (d *testDoc) PublishDate() time.Time {
return d.date
}
+func TestCardinalityThreshold(t *testing.T) {
+ c := qt.New(t)
+ config := Config{
+ Threshold: 90,
+ IncludeNewer: false,
+ Indices: IndexConfigs{
+ IndexConfig{Name: "tags", Weight: 50, CardinalityThreshold: 79},
+ IndexConfig{Name: "keywords", Weight: 65, CardinalityThreshold: 90},
+ },
+ }
+
+ idx := NewInvertedIndex(config)
+ hasKeyword := func(index, keyword string) bool {
+ _, found := idx.index[index][StringKeyword(keyword)]
+ return found
+ }
+
+ docs := []Document{
+ newTestDoc("tags", "a", "b", "c", "d"),
+ newTestDoc("tags", "b", "d", "g"),
+ newTestDoc("tags", "b", "d", "g"),
+ newTestDoc("tags", "b", "h").addKeywords("keywords", "a"),
+ newTestDoc("tags", "g", "h").addKeywords("keywords", "a", "b", "z"),
+ }
+
+ idx.Add(context.Background(), docs...)
+ c.Assert(idx.Finalize(context.Background()), qt.IsNil)
+ // Only tags=b should be removed.
+ c.Assert(hasKeyword("tags", "a"), qt.Equals, true)
+ c.Assert(hasKeyword("tags", "b"), qt.Equals, false)
+ c.Assert(hasKeyword("tags", "d"), qt.Equals, true)
+ c.Assert(hasKeyword("keywords", "b"), qt.Equals, true)
+
+}
+
func TestSearch(t *testing.T) {
config := Config{
Threshold: 90,