-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ typed backends now responsible for intersecting ids, + this means t…
…hat Picky now has exchangeable backends! Hooray!
- Loading branch information
Showing
9 changed files
with
218 additions
and
68 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Picky | ||
|
||
module Query | ||
|
||
# Combinations are a number of Combination-s. | ||
# | ||
# They are the core of an allocation. | ||
# An allocation consists of a number of combinations. | ||
# | ||
# Base Combinations contain methods for calculating score and ids. | ||
# | ||
class Combinations # :nodoc:all | ||
|
||
attr_reader :combinations | ||
|
||
delegate :empty?, :inject, :to => :@combinations | ||
|
||
def initialize combinations = [] | ||
@combinations = combinations | ||
end | ||
|
||
def hash | ||
@combinations.hash | ||
end | ||
|
||
# Uses user specific weights to calculate a score for the combinations. | ||
# | ||
def calculate_score weights | ||
total_score + weighted_score(weights) | ||
end | ||
def total_score | ||
@combinations.sum &:weight | ||
end | ||
def weighted_score weights | ||
weights.score_for @combinations | ||
end | ||
|
||
# Filters the tokens and identifiers such that only identifiers | ||
# that are passed in, remain, including their tokens. | ||
# | ||
# Note: This method is not totally independent of the calculate_ids one. | ||
# Since identifiers are only nullified, we need to not include the | ||
# ids that have an associated identifier that is nil. | ||
# | ||
def keep identifiers = [] | ||
@combinations.reject! { |combination| !combination.in?(identifiers) } | ||
end | ||
|
||
# Filters the tokens and identifiers such that identifiers | ||
# that are passed in, are removed, including their tokens. | ||
# | ||
# Note: This method is not totally independent of the calculate_ids one. | ||
# Since identifiers are only nullified, we need to not include the | ||
# ids that have an associated identifier that is nil. | ||
# | ||
def remove identifiers = [] | ||
@combinations.reject! { |combination| combination.in?(identifiers) } | ||
end | ||
|
||
# | ||
# | ||
def to_result | ||
@combinations.map &:to_result | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Picky | ||
|
||
# TODO Remove. | ||
# | ||
class IndexesCheck | ||
|
||
class << self | ||
|
||
# Returns the right combinations strategy for | ||
# a number of query indexes. | ||
# | ||
# Currently it isn't possible using Memory and Redis etc. | ||
# indexes in the same query index group. | ||
# | ||
# Picky will raise a Query::Indexes::DifferentTypesError. | ||
# | ||
def check_backend_types index_definitions_ary # :nodoc: | ||
backend_types = index_definitions_ary.map(&:backend).map(&:class) | ||
backend_types.uniq! | ||
raise_different backend_types if backend_types.size > 1 | ||
backend_types | ||
end | ||
def raise_different backend_types # :nodoc: | ||
raise DifferentTypesError.new(backend_types) | ||
end | ||
|
||
# Currently it isn't possible using Memory and Redis etc. | ||
# indexes in the same query index group. | ||
# | ||
class DifferentTypesError < StandardError # :nodoc:all | ||
def initialize types | ||
@types = types | ||
end | ||
def to_s | ||
"Currently it isn't possible to mix Indexes with backends #{@types.join(" and ")} in the same Search instance." | ||
end | ||
end | ||
|
||
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 was deleted.
Oops, something went wrong.