Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sporkmonger/32087 to your computer and use it in GitHub Desktop.
Save sporkmonger/32087 to your computer and use it in GitHub Desktop.
From 044bd08970c8f5475c53b62a003c332543b7aa71 Mon Sep 17 00:00:00 2001
From: Bob Aman <[email protected]>
Date: Thu, 4 Dec 2008 16:20:45 -0500
Subject: [PATCH] Fixed issue with indexing models with non-numeric id values.
---
lib/acts_as_xapian.rb | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/lib/acts_as_xapian.rb b/lib/acts_as_xapian.rb
index 1a379ca..2a0389e 100644
--- a/lib/acts_as_xapian.rb
+++ b/lib/acts_as_xapian.rb
@@ -322,7 +322,7 @@ module ActsAsXapian
lhash = {}
lhash.default = []
for doc in docs
- k = doc[:data].split('-')
+ k = doc[:data].split("-\\-")
lhash[k[0]] = lhash[k[0]] + [k[1]]
end
# for each class, look up all ids
@@ -331,13 +331,20 @@ module ActsAsXapian
conditions = [ "#{cls.constantize.table_name}.#{cls.constantize.primary_key} in (?)", ids ]
found = cls.constantize.find(:all, :conditions => conditions, :include => cls.constantize.xapian_options[:eager_load])
for f in found
- chash[[cls, f.id]] = f
+ chash[[cls, f.id.to_s]] = f
end
end
# now get them in right order again
results = []
- docs.each{|doc| k = doc[:data].split('-'); results << { :model => chash[[k[0], k[1].to_i]],
- :percent => doc[:percent], :weight => doc[:weight], :collapse_count => doc[:collapse_count] } }
+ docs.each do |doc|
+ model_name, model_id = doc[:data].split("-\\-")
+ results << {
+ :model => chash[[model_name, model_id]],
+ :percent => doc[:percent],
+ :weight => doc[:weight],
+ :collapse_count => doc[:collapse_count]
+ }
+ end
self.cached_results = results
return results
end
@@ -591,7 +598,7 @@ module ActsAsXapian
module InstanceMethods
# Used internally
def xapian_document_term
- self.class.to_s + "-" + self.id.to_s
+ self.class.to_s + "-\\-" + self.id.to_s
end
# Extract value of a field from the model
--
1.5.4.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment