Skip to content

Instantly share code, notes, and snippets.

View ktopping's full-sized avatar

Kieran Topping ktopping

  • Unbound, and self
  • Dublin, Ireland
View GitHub Profile
@ktopping
ktopping / gist:286058
Created January 25, 2010 17:44
A javascript function for turning a space (or punctuation) - delimited string into a camel case String.
// There's probably a more concise solution, but I prefer clarity over conciseness
// Splits on any number of non-word characters.
// Apostrophes don't cause case-change.
function toCamelCase(str) {
if (str==null || str==undefined || str.length==0) return str;
str = str.replace(/'/g, "");
var arr = str.split(/[^\w]+/g); // split on any sequence of one or more
// non-word chars.
var ret = "";
// Look for the first non-zero-length String.
public!
git-rm --cached log/development.log
config.gem 'sunspot', :lib => 'sunspot'
config.gem 'sunspot_rails', :lib => 'sunspot/rails'
common: &common
solr:
hostname: localhost
port: 8983
production:
<<: *common
development:
<<: *common
searchable do
text :xml, :boost => 2.0
end
[kieran@localhost myapp]$ script/console
Loading development environment (Rails 2.3.2)
>> c = Content.new(:xml => '<content><field1>abc</field1><field2>def</field2></content>')
>> c.save
=> true
>> Content.search.results
=> []
>> Sunspot.commit
=> {"responseHeader"=>{"status"=>0, "QTime"=>33}}
=> Content.search.results
query.adjust_solr_params do |params|
params[:"f.#{Sunspot::Setup.for(MyModel).dynamic_field_factory(:custom).build(:my_field).indexed_name}.facet.prefix"] = my_leading_str
end
test "sunspot available" do
begin
# Search for instances of "String". The String class will always
# exist, so I use it in order to make this test simpler. It then
# has no dependency on my application classes.
s = Sunspot.search(String) {}
rescue
assert false, "Cannot connect to solr server #{Sunspot.config.solr.url}\n#{$!}"
end
end
[kieran@localhost myapp]$ # Build docs
[kieran@localhost myapp]$ rake doc:app
[kieran@localhost myapp]$ # The following line shows you where to browse to
[kieran@localhost myapp]$ # in order to view your docs
[kieran@localhost myapp]$ echo "Find your docs here: file:///$PWD/doc/app/index.html"