picky
https://github.com/floere/picky
HTML
Picky is an easy to use and fast Ruby semantic search engine that helps your users find what they are looking for.
Picky::Query::Indexes#expand_combinations_from
This is the core of the search engine. No kidding.
Gets an array of
[
[<combinations for token1>],
[<combinations for token2>],
[<combinations for token3>]
]
Generates all possible allocations of combinations.
[
[first combination of token1, first c of t2, first c of t3],
[first combination of token1, first c of t2, second c of t3]
...
]
Generates all possible combinations of array elements:
[1,2,3] x [a,b,c] x [k,l,m] => [[1,a,k], [1,a,l], [1,a,m], [1,b,k], [1,b,l], [1,b,m], [1,c,k], ..., [3,c,m]]
Note: Also calculates the weights and sorts them accordingly.
Note: This is a heavily optimized ruby version.
Works like this:
[1,2,3], [a,b,c], [k,l,m] are expanded to
group mult: 1
<- single mult ->
[1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3] = 27 elements
group mult: 3
<- -> s/m
[a,a,a,b,b,b,c,c,c,a,a,a,b,b,b,c,c,c,a,a,a,b,b,b,c,c,c] = 27 elements
group mult: 9
<> s/m
[k,l,m,k,l,m,k,l,m,k,l,m,k,l,m,k,l,m,k,l,m,k,l,m,k,l,m] = 27 elements
It is then recombined, where
[
[a,a,b,b,c,c]
[d,e,d,e,d,e]
]
becomes
[
[a,d],
[a,e],
[b,d],
[b,e],
[c,d],
[c,e]
]
Note: Not using transpose as it is slower.
Returns nil if there are no combinations.
Note: Of course I could split this method up into smaller
ones, but I guess I am a bit sentimental.Edit
git clone [email protected]:floere/picky.git
cd picky
open server/lib/picky/query/indexes.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Picky--Query--Indexes-expand_combinations_from-for-pr
# Commit to gitgit add server/lib/picky/query/indexes.rbgit commit -m "better docs for Picky::Query::Indexes#expand_combinations_from"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Picky--Query--Indexes-expand_combinations_from-for-pr
hub pull-request
# Celebrate!