Skip to content

Commit

Permalink
feat(custom_ranking): Renaming the weight key to custom_ranking
Browse files Browse the repository at this point in the history
This makes understanding its usage easier
  • Loading branch information
pixelastic committed Mar 12, 2018
1 parent 04dda60 commit 8f44d32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Here is one of the records extracted:
:lvl5 => nil,
:lvl6 => nil
},
:weight => {
:custom_ranking => {
:heading => 70,
:position => 3
}
Expand Down Expand Up @@ -118,7 +118,7 @@ Anchors are searched in `name` and `id` attributes of headings.
paragraph. The `lvlX` syntax is used to be compatible with the records
[DocSearch][9] is using.

The `weight` attribute is used to provide an easy way to rank two records
The `custom_ranking` attribute is used to provide an easy way to rank two records
relative to each other.

- `heading` gives the depth level in the hierarchy where the record is. Records
Expand Down
2 changes: 1 addition & 1 deletion lib/algolia_html_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def self.run(input, options: {})
hierarchy: current_hierarchy.clone,
anchor: current_anchor,
node: node,
weight: {
custom_ranking: {
position: current_position,
heading: heading_weight(current_lvl)
}
Expand Down
20 changes: 10 additions & 10 deletions spec/algolia_html_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
actual = AlgoliaHTMLExtractor.run(input)

# Then
expect(actual[0][:weight][:position]).to eq 0
expect(actual[1][:weight][:position]).to eq 1
expect(actual[2][:weight][:position]).to eq 2
expect(actual[0][:custom_ranking][:position]).to eq 0
expect(actual[1][:custom_ranking][:position]).to eq 1
expect(actual[2][:custom_ranking][:position]).to eq 2
end
end

Expand Down Expand Up @@ -428,7 +428,7 @@
actual = AlgoliaHTMLExtractor.run(input)

# Then
expect(actual[0][:weight][:heading]).to eq 100
expect(actual[0][:custom_ranking][:heading]).to eq 100
end

it 'should have decreasing value under small headers' do
Expand All @@ -444,12 +444,12 @@
actual = AlgoliaHTMLExtractor.run(input)

# Then
expect(actual[0][:weight][:heading]).to eq 90
expect(actual[1][:weight][:heading]).to eq 80
expect(actual[2][:weight][:heading]).to eq 70
expect(actual[3][:weight][:heading]).to eq 60
expect(actual[4][:weight][:heading]).to eq 50
expect(actual[5][:weight][:heading]).to eq 40
expect(actual[0][:custom_ranking][:heading]).to eq 90
expect(actual[1][:custom_ranking][:heading]).to eq 80
expect(actual[2][:custom_ranking][:heading]).to eq 70
expect(actual[3][:custom_ranking][:heading]).to eq 60
expect(actual[4][:custom_ranking][:heading]).to eq 50
expect(actual[5][:custom_ranking][:heading]).to eq 40
end
end
end
Expand Down

0 comments on commit 8f44d32

Please sign in to comment.