Permalink
Browse files

+ independent recipes, + geolocation, + range/area/volumetric searches

  • Loading branch information...
floere committed Dec 30, 2011
1 parent e4df484 commit ce3d03426859311c35c4f14c9885091dc4cc4673
View
@@ -15,6 +15,8 @@ h2. Basics
h2. Intermediate
* /searches (How to configure your search so it rocks)
+* /range (How to use range queries)
+* /geolocation (How to configure geosearches)
h2. Advanced
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
# We want to search 2 indexes at once.
# One index uses a source, the indexes at realtime.
#
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
# Loading the Picky index without a source,
# but purely by adding (replacing) items.
#
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
# An example where you give the Picky index
# an #each source.
#
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last
@@ -0,0 +1,4 @@
+h1. Geolocation Categories
+
+* basic.rb
+* multi_radius.rb (multiple radii)
@@ -0,0 +1,22 @@
+require File.expand_path '../../../server/lib/picky', __FILE__
+
+GeoCoords = Struct.new :id, :lat, :lng
+
+data = Picky::Index.new :people do
+ # 1.0 is the radius in k around which to search.
+ # precision 1 is low precision (20% error margin), but fast
+ #
+ geo_categories :lat, :lng, 1000.0 # 1000kms radius
+end
+cities = Picky::Search.new data
+
+data.replace GeoCoords.new(1, -37.813611, 144.963056) # Melbourne
+data.replace GeoCoords.new(2, -33.859972, 151.211111) # Sydney
+data.replace GeoCoords.new(3, 47.366667, 8.55) # Zurich
+data.replace GeoCoords.new(4, 41.9, 12.5) # Rome
+
+# Picky just returns results in range, not ordered
+# by distance. Usually that is fine for showing results
+# in a graph or on a map.
+#
+fail __FILE__ unless cities.search('lat:-33.85 lng:150.2').ids == [2, 1]
@@ -0,0 +1,29 @@
+require File.expand_path '../../../server/lib/picky', __FILE__
+
+GeoCoords = Struct.new :id, :lat, :lng
+
+data = Picky::Index.new :people do
+ # 1.0 is the radius in k around which to search.
+ # precision 1 is low precision (20% error margin), but fast
+ #
+ geo_categories :lat1, :lng1, 1.0, :lat_from => :lat, :lng_from => :lng
+ geo_categories :lat10, :lng10, 10.0, :lat_from => :lat, :lng_from => :lng
+ geo_categories :lat100, :lng100, 100.0, :lat_from => :lat, :lng_from => :lng
+ geo_categories :lat1000, :lng1000, 1000.0, :lat_from => :lat, :lng_from => :lng
+end
+
+data.replace GeoCoords.new(1, -37.813611, 144.963056) # Melbourne
+data.replace GeoCoords.new(2, -33.859972, 151.211111) # Sydney
+data.replace GeoCoords.new(3, 47.366667, 8.55) # Zurich
+data.replace GeoCoords.new(4, 41.9, 12.5) # Rome
+
+cities = Picky::Search.new data
+
+# Picky just returns results in range, not ordered
+# by distance. Usually that is fine for showing results
+# in a graph or on a map.
+#
+fail __FILE__ unless cities.search('lat1:-33.85 lng1:150.2').ids == []
+fail __FILE__ unless cities.search('lat10:-33.85 lng10:150.2').ids == []
+fail __FILE__ unless cities.search('lat100:-33.85 lng100:150.2').ids == [2]
+fail __FILE__ unless cities.search('lat1000:-33.85 lng1000:150.2').ids == [2, 1]
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
# Our special partializer only allows partials
# of even length.
#
View
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
@@ -0,0 +1,5 @@
+h1. Range Categories
+
+* one_dimensional.rb (Value range search)
+* two_dimensional.rb (Area search)
+* three_dimensional.rb (Volumetric search)
@@ -0,0 +1,27 @@
+require File.expand_path '../../../server/lib/picky', __FILE__
+
+OneD = Struct.new :id, :value
+
+data = Picky::Index.new :people do
+ # 1.0 is the range around which to search
+ # precision 1 is low precision (20% error margin), but fast
+ #
+ ranged_category :value, 1.0, precision: 1
+end
+
+data.replace OneD.new(1, 3.2)
+data.replace OneD.new(2, 1.8)
+data.replace OneD.new(3, 9.7)
+data.replace OneD.new(4, 4.1)
+
+one_d = Picky::Search.new data
+
+results = one_d.search '3.1'
+
+# p results.allocations
+
+# Picky just returns results in range, not ordered
+# by distance. Usually that is fine for showing results
+# in a graph or on a map.
+#
+fail __FILE__ unless results.ids == [4, 1]
@@ -0,0 +1,32 @@
+require File.expand_path '../../../server/lib/picky', __FILE__
+
+ThreeD = Struct.new :id, :x, :y, :z
+
+data = Picky::Index.new :people do
+ # 1.0 is the range around which to search
+ # precision 1 is low precision (20% error margin), but fast
+ #
+ ranged_category :x, 1.0, precision: 1
+ ranged_category :y, 1.0, precision: 1
+ ranged_category :z, 1.0, precision: 1
+end
+
+data.replace ThreeD.new(1, 3.2, 2.8, -8.5)
+data.replace ThreeD.new(2, 1.8, 0.4, 13.7)
+data.replace ThreeD.new(3, 9.7, 11.2, -7.0)
+data.replace ThreeD.new(4, 4.1, 2.2, -7.5)
+
+three_d = Picky::Search.new data
+
+# Since the x, y and z coordinates are not
+# disjunct, we have to specify which is which.
+#
+results = three_d.search 'x:3.1 y:2.4 z:-8.0'
+
+# p results.allocations
+
+# Picky just returns results in range, not ordered
+# by distance. Usually that is fine for showing results
+# in a graph or on a map.
+#
+fail __FILE__ unless results.ids == [4, 1]
@@ -0,0 +1,31 @@
+require File.expand_path '../../../server/lib/picky', __FILE__
+
+TwoD = Struct.new :id, :x, :y
+
+data = Picky::Index.new :people do
+ # 1.0 is the range around which to search
+ # precision 1 is low precision (20% error margin), but fast
+ #
+ ranged_category :x, 1.0, precision: 1
+ ranged_category :y, 1.0, precision: 1
+end
+
+data.replace TwoD.new(1, 3.2, 2.8)
+data.replace TwoD.new(2, 1.8, 0.4)
+data.replace TwoD.new(3, 9.7, 11.2)
+data.replace TwoD.new(4, 4.1, 2.2)
+
+two_d = Picky::Search.new data
+
+# Since the x and y coordinates are not
+# disjunct, we have to specify which is which.
+#
+results = two_d.search 'x:3.1 y:2.4'
+
+# p results.allocations
+
+# Picky just returns results in range, not ordered
+# by distance. Usually that is fine for showing results
+# in a graph or on a map.
+#
+fail __FILE__ unless results.ids == [4, 1]
View
@@ -1,3 +1 @@
-Person = Struct.new :id, :first, :last
-
Dir['**/*.rb'].each { |file| require File.expand_path "../#{file}", __FILE__ }
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
# Our similarizer just encodes text as if
# it had just vowels.
#
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last, similarity: Picky::Similarity::Metaphone.new
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last, similarity: Picky::Similarity::Metaphone.new
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last, similarity: Picky::Similarity::Soundex.new
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
category :last, weight: Picky::Weights::Constant.new(3.0)
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
# Our customized weighter for the last name.
# We weigh results higher that are only found once.
#
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
@@ -1,5 +1,7 @@
require File.expand_path '../../../server/lib/picky', __FILE__
+Person = Struct.new :id, :first, :last
+
data = Picky::Index.new :people do
category :first
@@ -239,7 +239,7 @@ def category category_name, options = {}
#
# === Options
# * precision: Default is 1 (20% error margin, very fast), up to 5 (5% error margin, slower) makes sense.
- # * anchor: Where to anchor the geo grid.
+ # * anchor: Where to anchor the grid.
# * ... all options of #category.
#
def ranged_category category_name, range, options = {}
@@ -15,7 +15,7 @@ class Allocation # :nodoc:all
#
#
def initialize index, combinations
- @combinations = combinations
+ @combinations = combinations
# Could this be rewritten?
#
@@ -3,7 +3,7 @@
require 'spec_helper'
describe "Regression" do
-
+
it 'does not get confused' do
index = Picky::Index.new :dynamic_weights do
category :text1

0 comments on commit ce3d034

Please sign in to comment.