Skip to content

Commit

Permalink
make searching by id trivial by letting the user type in the id
Browse files Browse the repository at this point in the history
directly.
  • Loading branch information
hrishikeshs committed Jan 25, 2014
1 parent a31feb5 commit 204367d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{#if controller.isLoaded}}
<ul>
<li class="inline-search-box">
<form {{action search on="submit"}} class="inline-form-search-box" title="syntax is: field:value, separate nested fields by a dot.">
<form {{action search on="submit"}} class="inline-form-search-box" title="syntax is: field:value, separate nested fields by a dot. For ObjectIds, just copy paste the id and hit return.">
{{input valueBinding="searchtext" class="documents-search-box" placeholder="Type to search..." }}
</form>
</li>
Expand Down
28 changes: 17 additions & 11 deletions Mongoman/app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ def search
collection = db[collection_name]
searchphrase = params[:id]
parsed_list = searchphrase.split(':')
field = parsed_list[0].strip!
value = parsed_list.slice(1)
value = Regexp.new(value.lstrip!)
query = {}
field.gsub! /\*/, "."
query[field] = value
count = collection.find(query).count()
data = {}
puts query
puts "======================"
data[:documents] = collection.find(query).limit(300).map do |e|
e = self.BsonFieldsToString(e)
if parsed_list.length < 2
id = BSON::ObjectId(searchphrase)
data[:documents] = collection.find("_id" => id).map do |e|
e = self.BsonFieldsToString(e)
end
count = 1
else
field = parsed_list[0].strip!
value = parsed_list.slice(1)
value = Regexp.new(value.lstrip!)
query = {}
field.gsub! /\*/, "."
query[field] = value
count = collection.find(query).count()
data[:documents] = collection.find(query).limit(300).map do |e|
e = self.BsonFieldsToString(e)
end
end

data[:count] = count
Expand Down

0 comments on commit 204367d

Please sign in to comment.