forked from pat/thinking-sphinx
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refined the facet code, with thanks to Dan Pickett's fork, and added …
…drilling down within a facet set
- Loading branch information
Showing
13 changed files
with
136 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,26 @@ | |||
Feature: Search and browse models by their defined facets | Feature: Search and browse models by their defined facets | ||
|
|
||
Scenario: Test | Scenario: Requesting facets | ||
Given Sphinx is running | Given Sphinx is running | ||
And I am searching on developers | And I am searching on developers | ||
When I am requesting facet results | When I am requesting facet results | ||
Then I should see facet results | Then I should have valid facet results | ||
And I should have 4 facets | |||
And I should have the facet State | |||
And I should have the facet Country | |||
And I should have the facet Age | |||
And I should have the facet City | |||
|
|||
Scenario: Requesting facet results | |||
Given Sphinx is running | |||
And I am searching on developers | |||
When I am requesting facet results | |||
And I drill down where Country is Australia | |||
Then I should get 11 results | |||
|
|||
Scenario: Requesting facet results by multiple facets | |||
Given Sphinx is running | |||
And I am searching on developers | |||
When I am requesting facet results | |||
And I drill down where Country is Australia and Age is 30 | |||
Then I should get 4 results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
module ThinkingSphinx | |||
class FacetCollection < Hash | |||
attr_accessor :arguments | |||
|
|||
def initialize(arguments) | |||
@arguments = arguments.clone | |||
@attribute_values = {} | |||
@facets = [] | |||
end | |||
|
|||
def add_from_results(facet, results) | |||
self[facet.name] = {} | |||
@attribute_values[facet.name] = {} | |||
@facets << facet | |||
|
|||
results.each_with_groupby_and_count { |result, group, count| | |||
facet_value = facet.value(result, group) | |||
|
|||
self[facet.name][facet_value] = count | |||
@attribute_values[facet.name][facet_value] = group | |||
} | |||
end | |||
|
|||
def for(hash = {}) | |||
arguments = @arguments.clone | |||
options = arguments.extract_options! | |||
options[:with] ||= {} | |||
|
|||
hash.each do |key, value| | |||
attrib = facet_for_key(key).attribute_name | |||
options[:with][attrib] = @attribute_values[key][value] | |||
end | |||
|
|||
arguments << options | |||
ThinkingSphinx::Search.search *arguments | |||
end | |||
|
|||
private | |||
|
|||
def facet_for_key(key) | |||
@facets.detect { |facet| facet.name == key } | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters