Skip to content

Commit

Permalink
Allow configuration of searchable classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh French committed Aug 8, 2010
1 parent bedef0f commit d8cdc56
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 11 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ quickstart guide, but these commands should be enough to get you started:
## Indexing

SphinxSearch indexes your pages on title and content (parts.) Sphinx
attributes are created for `status_id`, `updated_at`, `virtual`, and
`class_name`.
attributes are created for `status_id`, `updated_at`, and `virtual`.

## Building a Search Page

Expand Down
2 changes: 1 addition & 1 deletion lib/sphinx_search.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SphinxSearch
mattr_accessor :param_name, :content_length
mattr_accessor :param_name, :content_length, :hidden_classes
end
13 changes: 10 additions & 3 deletions lib/sphinx_search/page_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ def self.included(base)
set_property :delta => true, :group_concat_max_len => SphinxSearch.content_length || 8.kilobytes
set_property :field_weights => { 'title' => 100 }
indexes title, parts.content
has updated_at, status_id, virtual, class_name
has updated_at, status_id, virtual
end

base.extend ClassMethods
end

module ClassMethods
def searchable(search=true)
search ? SphinxSearch.hidden_classes.delete(self.name) : SphinxSearch.hidden_classes.push(self.name)
end
end

end

end
end
6 changes: 5 additions & 1 deletion lib/sphinx_search/radius_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ def will_paginate_options(tag)
end

def thinking_sphinx_options(tag)
{ :with => { :status_id => 100, :virtual => false }, :retry_stale => true }
{
:with => { :status_id => 100, :virtual => false },
:without => { :class_crc => SphinxSearch.hidden_classes.map(&:to_crc32) },
:retry_stale => true
}
end
end
end
6 changes: 5 additions & 1 deletion lib/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

# Max length of content to index, per page. Bump this up if you have more than
# 8k of text per page (as calculated by combining all page parts.)
SphinxSearch.content_length = 8.kilobytes
SphinxSearch.content_length = 8.kilobytes

# Don't include these page subclasses in the search results. This can also be
# accessed by declaring `self.searchable [true|false]` in your Page subclasses.
SphinxSearch.hidden_classes = %w(SearchPage JavascriptPage StylesheetPage)
4 changes: 2 additions & 2 deletions radiant-sphinx_search-extension.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Gem::Specification.new do |s|
"lib/templates/sphinx.yml",
"radiant-sphinx_search-extension.gemspec",
"spec/datasets/search_pages_dataset.rb",
"spec/lib/radiant-sphinx_search-extension.rb",
"spec/lib/search_radius_tags_spec.rb",
"spec/models/page_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"sphinx_search_extension.rb"
Expand All @@ -47,8 +47,8 @@ Gem::Specification.new do |s|
s.summary = %q{Sphinx Search Extension for Radiant CMS}
s.test_files = [
"spec/datasets/search_pages_dataset.rb",
"spec/lib/radiant-sphinx_search-extension.rb",
"spec/lib/search_radius_tags_spec.rb",
"spec/models/page_spec.rb",
"spec/spec_helper.rb"
]

Expand Down
1 change: 0 additions & 1 deletion spec/lib/radiant-sphinx_search-extension.rb

This file was deleted.

25 changes: 25 additions & 0 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Page do
describe "Page.searchable" do
it "should add itself to the hidden classes array" do
SphinxSearch.hidden_classes = []
FileNotFoundPage.searchable false
SphinxSearch.hidden_classes.should include('FileNotFoundPage')
end

it "should remove itself from the hidden classes array" do
SphinxSearch.hidden_classes = %w(FileNotFoundPage)
FileNotFoundPage.searchable true
SphinxSearch.hidden_classes.should_not include("FileNotFoundPage")
end
end

describe "#thinking_sphinx_options" do
it "should description" do
SphinxSearch.hidden_classes = %w(FileNotFoundPage)
opts = SearchPage.new.send :thinking_sphinx_options, nil
opts[:without][:class_crc].should include('FileNotFoundPage'.to_crc32)
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
end

Spec::Runner.configure do |config|
SphinxSearch.hidden_classes ||= %w(SearchPage JavascriptPage StylesheetPage)
# config.use_transactional_fixtures = true
# config.use_instantiated_fixtures = false
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
Expand Down

0 comments on commit d8cdc56

Please sign in to comment.