Permalink
Browse files

More progress toward some basic functionality

 - Display search results from solr
 - Home made config for solr schema, added solr tasks directly as rake task
 - Some changes to element config and searchable setup
 - Updated .gitignore
  • Loading branch information...
1 parent bacfe4d commit 385b6a775999530389b31f2fa4f6715eaa43e874 coutud committed Nov 3, 2010
View
@@ -4,3 +4,8 @@ log/*.log
tmp/**/*
*.pid
*.swp
+forgery/
+log
+public/stylesheets/default.css
+
+.sass-cache/
View
@@ -11,6 +11,7 @@ gem 'rails', '~> 3.0'
gem "haml"
gem "hpricot"
gem "jquery-rails"
+gem "will_paginate", "~> 3.0.pre2"
# Deploy with Capistrano
# gem 'capistrano'
View
@@ -52,8 +52,13 @@ GEM
erubis (2.6.6)
abstract (>= 1.0.0)
escape (0.0.4)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
haml (3.0.18)
+ hpricot (0.8.2)
i18n (0.4.1)
+ jquery-rails (0.2.4)
+ rails (~> 3.0)
json (1.4.6)
mail (2.2.5)
activesupport (>= 2.3.6)
@@ -88,6 +93,8 @@ GEM
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
+ rb-inotify (0.8.1)
+ ffi (>= 0.5.0)
rdoc (2.5.11)
resque-mongo (1.9.8.1)
json (>= 1.1.0)
@@ -131,8 +138,11 @@ DEPENDENCIES
awesome_print
bson_ext (= 1.0.4)
haml
+ hpricot
+ jquery-rails
mongoid (= 2.0.0.beta.17)
rails (~> 3.0)
+ rb-inotify
rdoc
resque-mongo
rmagick
@@ -142,4 +152,5 @@ DEPENDENCIES
shared-mime-info!
sunspot
sunspot_mongoid!
+ will_paginate (~> 3.0.pre2)
wirble
@@ -4,11 +4,24 @@ def index
def search
@query = params[:q]
+
+ if @query.blank?
+ render :text=>""
+ return
+ end
+
@search = Sunspot.search(Element) do
keywords params[:q] do
highlight
end
+ facet :media
+ if params[:media]
+ with(:media, params[:media])
+ end
+ end
+
+ if request.xhr?
+ render :partial=>'search_results', :locals=>{:search=>@search, :query=>@query}
end
- render :layout=>false
end
end
@@ -1,2 +1,10 @@
module ApplicationHelper
+ #
+ # Returns _params_ hash without the _symbol_ pair.
+ # It's only a copy, _params_ remains unchanged
+ def params_remove(params, symbol)
+ url_hash = params.dup
+ url_hash.delete(symbol)
+ url_hash
+ end
end
View
@@ -1,3 +1,7 @@
+# We have to explicitely require shared-mime-info since MIME is a module
+# and rails autoloading seems to struggle loading it properly
+require 'shared-mime-info'
+
class Element
include Mongoid::Document
include Sunspot::Mongoid
@@ -14,7 +18,7 @@ class Element
# A hash of the file, nil when directories.
# Should be almost surely unique for the file
field :content_hash
- # List of fields to index in the search engine
+ # List of fields to index in full_text in the search engine
field :indexed_fields, :type=>Array, :default => []
index :path, :unique => true
@@ -48,22 +52,25 @@ def children
self.class.where(:parent_id=>id)
end
+ def mime_type
+ MIME[self[:mime_type]]
+ end
+
#
# Search definitions and related stuff
# Note : Sunspot::Rails defaults apply here : auto_index is true, auto_remove is true
#
searchable do
- text :name
+ text :name, :stored => true
text :indexed_fields do
self[:indexed_fields] = (self[:indexed_fields] || []).uniq
self[:indexed_fields].collect{|field| self[field]}.compact.join(' -- ')
end
- string :mime_types do
- # Return the whole mime_types hierarchy
- # MIME[self[:mime_type]].parents
- self[:mime_type].split('/').first
+ string :mime_type, :stored => true
+ string :media do
+ self[:mime_type] && self[:mime_type].split('/').first
end
# dynamic_text :custom_fields do
@@ -1,15 +1,17 @@
%h1 Listing collections
-%table
- %tr
- %th Name
- %th Path
- %th
- - @collections.each do |collection|
+%table.full
+ %thead
%tr
- %td= collection.name
- %td= collection.base_path
- %td
- = link_to 'Show', collection
+ %th Name
+ %th Path
+ %th
+ %tbody
+ - @collections.each do |collection|
+ %tr
+ %td= collection.name
+ %td= collection.base_path
+ %td
+ = link_to 'Show', collection
- content_for :sidebar do
.box
@@ -7,7 +7,14 @@
%p
= link_to 'Base element', @collection.base_element
-= link_to 'Edit', edit_collection_path(@collection)
-= link_to 'Crawl', enqueue_collection_path(@collection), :method=>:post
-= link_to 'Destroy', @collection, :confirm => 'Are you sure ?', :method=>:delete
-= link_to 'Back', collections_path
+- content_for :sidebar do
+ .box
+ %h4= @collection.name
+ %em= @collection.base_path
+ .contentarea
+ %ul.linklist
+ %li= link_to 'Edit', edit_collection_path(@collection)
+ %li= link_to 'Crawl', enqueue_collection_path(@collection), :method=>:post
+ %li= link_to 'Destroy', @collection, :confirm => 'Are you sure ?', :method=>:delete
+ %hr
+ %li= link_to 'Back to collections', collections_path
@@ -22,57 +22,60 @@
%h2 I can tell your disk is a mess by the way it is.
#menu
= render :partial => 'layouts/menu'
- #headerpic
- = render :partial => 'shared/search'
+ - if content_for?(:search)
+ #headerpic
+ = yield :search
#menubottom
#content
- / Normal content: Stuff that's not going to be put in the left or right column.
- /
+ - if content_for?(:sidebar)
+ / Primary content: Stuff that goes in the primary content column (by default, the left column)
+ .primarycontainer
+ .primarycontent
+ / Primary content area start
+ = yield
+ / Primary content area end
+ / Secondary content: Stuff that goes in the secondary content column (by default, the narrower right column)
+ .secondarycontent
+ / Secondary content area start
+ = yield :sidebar
+ / HINT: Set any div's class to "box" to encapsulate it in (you guessed it) a box
+ - else
#normalcontent
- %h3
- %strong Zenlike
- %sup 1.0
- %span by NodeThirtyThree
- .contentarea
- / Normal content area start
- %img.left{:alt => "A chinese lion statue", :src => "/images/pic1.jpg"}/
- %p
- Zenlike
+ = yield
+ /
+ %h3
+ %strong Zenlike
%sup 1.0
- is a free, lightweight, tableless, fluid W3C-compliant website design by
- = succeed "." do
- %a{:href => "http://www.nodethirtythree.com/"} NodeThirtyThree Design
- All photos came from
- %a{:href => "http://www.pdphoto.org/"} PDPhoto
- and the background texture is from
- = succeed "." do
- %a{:href => "http://www.mayang.com/textures/"} Mayang's texture site
- You're free to dissect, manipulate and use it to your heart's content. We only ask that you link back to
- %a{:href => "http://www.nodethirtythree.com/"} our site
- in some way. If you find this design useful, feel free to let us know :)
- %p
- You can find more of our free work at this site or
- = succeed "," do
+ %span by NodeThirtyThree
+ .contentarea
+ / Normal content area start
+ %img.left{:alt => "A chinese lion statue", :src => "/images/pic1.jpg"}/
+ %p
+ Zenlike
+ %sup 1.0
+ is a free, lightweight, tableless, fluid W3C-compliant website design by
+ = succeed "." do
+ %a{:href => "http://www.nodethirtythree.com/"} NodeThirtyThree Design
+ All photos came from
+ %a{:href => "http://www.pdphoto.org/"} PDPhoto
+ and the background texture is from
+ = succeed "." do
+ %a{:href => "http://www.mayang.com/textures/"} Mayang's texture site
+ You're free to dissect, manipulate and use it to your heart's content. We only ask that you link back to
%a{:href => "http://www.nodethirtythree.com/"} our site
- or some of our commercial work on
- = succeed "," do
- %a{:href => "http://www.4templates.com/?aff=n33"} 4Templates.com
- a commercial website template site.
- / Normal content area end
- / .divider1
- / Primary content: Stuff that goes in the primary content column (by default, the left column)
- #primarycontainer
- #primarycontent
- / Primary content area start
- = yield
- / Primary content area end
- / Secondary content: Stuff that goes in the secondary content column (by default, the narrower right column)
- #secondarycontent
- / Secondary content area start
- = yield :sidebar
- / HINT: Set any div's class to "box" to encapsulate it in (you guessed it) a box
+ in some way. If you find this design useful, feel free to let us know :)
+ %p
+ You can find more of our free work at this site or
+ = succeed "," do
+ %a{:href => "http://www.nodethirtythree.com/"} our site
+ or some of our commercial work on
+ = succeed "," do
+ %a{:href => "http://www.4templates.com/?aff=n33"} 4Templates.com
+ a commercial website template site.
+ / Normal content area end
+ .divider1
#footer
- .left © 2010 Loox
- .right
- Design by
- %a{:href => "http://www.nodethirtythree.com/"} NodeThirtyThree Design
+ .left © 2010 Loox
+ .right
+ Design by
+ %a{:href => "http://www.nodethirtythree.com/"} NodeThirtyThree Design
@@ -0,0 +1,49 @@
+.post
+ %h4 Lorem Ipsum Veroeros
+ .contentarea
+ .details
+ Posted by
+ %a{:href => "#"} Jane Doe
+ on September 25, 2006
+ %p Volutpat at varius sed sollicitudin et, arcu. Vivamus viverra. Nullam turpis. Vestibulum sed etiam. Lorem ipsum sit amet dolore. Nulla facilisi. Sed tortor. Aenean felis. Quisque eros. Cras lobortis commodo metus. Vestibulum vel purus. In eget odio in sapien adipiscing blandit. Quisque augue tortor, facilisis sit amet, aliquam, suscipit vitae, cursus sed, arcu lorem ipsum dolor sit amet.
+ %ul.controls
+ %li
+ %a.printerfriendly{:href => "#"} Printer Friendly
+ %li
+ %a.comments{:href => "#"} Comments (18)
+ %li
+ %a.more{:href => "#"} Read More
+.divider2
+.post
+ %h4 Consequat Odio Vestibulum
+ .contentarea
+ .details
+ Posted by
+ %a{:href => "#"} Jane Doe
+ on September 25, 2006
+ %img.left{:alt => "A chinese dragon", :src => "/images/pic3.jpg"}/
+ %p Aenean felis quisque eros. Cras lobortis commodo lorem ipsum dolor. Vestibulum vel purus. In eget odio in sapien adipiscing blandit. Lorem ipsum dolor sit amet consequat etiam sed dolore.
+ %ul.controls
+ %li
+ %a.printerfriendly{:href => "#"} Printer Friendly
+ %li
+ %a.comments{:href => "#"} Comments (18)
+ %li
+ %a.more{:href => "#"} Read More
+.divider2
+.post
+ %h4 Adipiscing Nullam
+ .contentarea
+ .details
+ Posted by
+ %a{:href => "#"} Jane Doe
+ on September 25, 2006
+ %p Eget odio in sapien adipiscing blandit. Quisque augue tortor, facilisis sit amet, aliquam, suscipit vitae, cursus sed, arcu lorem ipsum dolor sit amet felis quisque eros. Cras lobortis commodo lorem ipsum dolor. Vestibulum vel purus. In eget odio in sapien adipiscing blandit. Quisque augue tortor, facilisis sit amet, aliquam, suscipit lorem ipsum dolor.
+ %ul.controls
+ %li
+ %a.printerfriendly{:href => "#"} Printer Friendly
+ %li
+ %a.comments{:href => "#"} Comments (18)
+ %li
+ %a.more{:href => "#"} Read More
+
@@ -0,0 +1,26 @@
+.primarycontainer
+ .primarycontent
+ %h2= query
+ %ul
+ - search.each_hit_with_result do |hit, element|
+ %li
+ - if highlight = hit.highlight(:name)
+ != hit.highlight(:name).format {|f| "<span class=\"highlight\">" + h(f) + "</span>"}
+ - else
+ = element.name
+ .details
+ = element.full_path
+ .pagination
+ = will_paginate(search.hits)
+.secondarycontent
+ .box
+ %h4 Categories
+ .contentarea
+ - if params[:media]
+ %p Found #{search.total} results in category #{params[:media]}
+ %ul.linklist
+ %li= link_to "See all categories", url_for(params_remove(params, :media))
+ - else
+ %ul.linklist
+ - search.facet(:media).rows.each do |row|
+ %li= link_to "#{row.value} (#{row.count})", url_for({:media=>row.value}.update(params))
Oops, something went wrong.

0 comments on commit 385b6a7

Please sign in to comment.