Skip to content

Commit

Permalink
first import
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrec1 committed Aug 25, 2009
0 parents commit 46533f0
Show file tree
Hide file tree
Showing 196 changed files with 12,806 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
*.log
*.log
*_pid
coverage/*
coverage.data
solr/solr/data/*
.svn
test/db/*.db
test/log/*.log
pkg/*
*.sw?
.DS_Store
coverage
rdoc
pkg
239 changes: 239 additions & 0 deletions CHANGE_LOG
@@ -0,0 +1,239 @@

== CHANGE_LOG
=== Development
<b>NEW</b>:: Return an empty SearchResult, rather than nil, when the query returns nothing.
<b>NEW</b>:: Better error message for parse errors.
<b>NEW</b>:: Using ENV['RAILS_ENV'] instead of RAILS_ENV, so multiple test environments are supported.
<b>FIX</b>:: Fixed load path collisions
<b>NEW</b>:: Gemified acts_as_solr
<b>NEW</b>:: A unit test suite based on Shoulda, not requiring a running Solr or a Rails environment. (Mathias Meyer)
<b>NEW</b>:: Added the :offline option to the acts_as_solr method. (Mathias Meyer)
<b>NEW</b>:: Added :lazy flag to find_by_solr, and with that support to load records lazily. (Mathias Meyer)
<b>FIX</b>:: Added test: to solr.yml so you don't need to do this by hand. (Ken Harris)
<b>FIX</b>:: Updated bundled Solr to 1.3. (Mathias Meyer)
<b>FIX</b>:: Updated bundled solr-ruby to 0.0.6 which comes bundled with Solr 1.3. (Mathias Meyer)
<b>FIX</b>:: Improved logging of the reindex rake task. (David Stevenson)
<b>FIX</b>:: Added requirement for libxml-ruby > 0.7, if libxml-ruby is installed. (David Stevenson)
<b>FIX</b>:: Ruby 1.9 compatibility fixes. (David Palm)
<b>FIX</b>:: Fixed compatibility with Desert by renaming environment.rb to solr_environment.rb. (David Stevenson)
<b>FIX</b>:: Moved the require of solr_environment only into tasks that need it. (David Stevenson)
<b>NEW</b>:: Added support to alias fields and includes using the option :as for acts_as_solr. See the RDoc for details. (Nick Hengeveld)
<b>NEW</b>:: Added support to attach the score to multi search results. (Mathias Meyer)
<b>NEW</b>:: Added support for facets on date fields. (Curtis Hatter)

=== 06-18-2007: Version 0.9
<b>NEW</b>:: Added the option :scores when doing a search. If set to true this will return the score as a 'solr_score' attribute or each one of the instances found
books = Book.find_by_solr 'ruby OR splinter', :scores => true
books.records.first.solr_score
=> 1.21321397
books.records.last.solr_score
=> 0.12321548

<b>NEW</b>:: Major change on the way the results returned are accessed.
books = Book.find_by_solr 'ruby'
# the above will return a SearchResults class with 4 methods:
# docs|results|records: will return an array of records found
#
# books.records.is_a?(Array)
# => true
#
# total|num_found|total_hits: will return the total number of records found
#
# books.total
# => 2
#
# facets: will return the facets when doing a faceted search
#
# max_score|highest_score: returns the highest score found
#
# books.max_score
# => 1.3213213

<b>NEW</b>:: Integrating acts_as_solr to use solr-ruby as the 'backend'. Integration based on the patch submitted by Erik Hatcher
<b>NEW</b>:: Re-factoring rebuild_solr_index to allow adds to be done in batch; and if a finder block is given, it will be called to retrieve the items to index. (thanks Daniel E.)
<b>NEW</b>:: Adding the option to specify the port Solr should start when using rake solr:start
rake solr:start RAILS_ENV=your_env PORT=XX

<b>NEW</b>:: Adding deprecation warning for the :background configuration option. It will no longer be updated.
<b>NEW</b>:: Adding support for models that use a primary key other than integer
class Posting < ActiveRecord::Base
set_primary_key 'guid' #string
#make sure you set the :primary_key_field => 'pk_s' if you wish to use a string field as the primary key
acts_as_solr({},{:primary_key_field => 'pk_s'})
end

<b>FIX</b>:: Disabling of storing most fields. Storage isn't useful for acts_as_solr in any field other than the pk and id fields. It just takes up space and time. (thanks Daniel E.)
<b>FIX</b>:: Re-factoring code submitted by Daniel E.
<b>NEW</b>:: Adding an :auto_commit option that will only send the commit command to Solr if it is set to true
class Author < ActiveRecord::Base
acts_as_solr :auto_commit => false
end

<b>FIX</b>:: Fixing bug on rake's test task
<b>FIX</b>:: Making acts_as_solr's Post class compatible with Solr 1.2 (thanks Si)
<b>NEW</b>:: Adding Solr 1.2
<b>FIX</b>:: Removing Solr 1.1
<b>NEW</b>:: Adding a conditional :if option to the acts_as_solr call. It behaves the same way ActiveRecord's :if argument option does.
class Electronic < ActiveRecord::Base
acts_as_solr :if => proc{|record| record.is_active?}
end

<b>NEW</b>:: Adding fixtures to Solr index when using rake db:fixtures:load
<b>FIX</b>:: Fixing boost warning messages
<b>FIX</b>:: Fixing bug when adding a facet to a field that contains boost
<b>NEW</b>:: Deprecating find_with_facet and combining functionality with find_by_solr
<b>NEW</b>:: Adding the option to :exclude_fields when indexing a model
class User < ActiveRecord::Base
acts_as_solr :exclude_fields => [:password, :login, :credit_card_number]
end

<b>FIX</b>:: Fixing branch bug on older ruby version
<b>NEW</b>:: Adding boost support for fields and documents being indexed:
class Electronic < ActiveRecord::Base
# You can add boosting on a per-field basis or on the entire document
acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => 5.0
end

<b>FIX</b>:: Fixed the acts_as_solr limitation to only accept test|development|production environments.

=== 05-16-2007: Version 0.8.5
<b>FIX</b>:: There's no need to specify the :field_types anymore when doing a search in a model that specifies a field type for a field.
<b>FIX</b>:: Better handling of nil values from indexed fields. Solr complained when indexing fields with field type and the field values being passed as nils.
<b>NEW</b>:: Adding Solr sort (order by) option to the search query (thanks Kevin Hunt)
<b>FIX</b>:: Applying patch suggested for increasing the Solr commit speed (thanks Mourad Hammiche)
<b>FIX</b>:: Updated documentation

=== 05-10-2007: Version 0.8
<b>NEW</b>: New video tutorial
<b>NEW</b>: Faceted search has been implemented and its possible to 'drill-down' on the facets
<b>NEW</b>: New rake tasks you can use to start/stop the solr server in test, development and production environments: (thanks Matt Clark)
rake solr:start|stop RAILS_ENV=test|development|production (defaults to development if none given)

<b>NEW</b>: Changes to the plugin's test framework and it now supports Sqlite as well (thanks Matt Clark)
<b>FIX</b>: Patch applied (thanks Micah) that allows one to have multiple solr instances in the same servlet
<b>FIX</b>: Patch applied (thanks Micah) that allows indexing of STIs
<b>FIX</b>: Patch applied (thanks Gordon) that allows the plugin to use a table's primary key different than 'id'
<b>FIX</b>: Returning empty array instead of empty strings when no records are found
<b>FIX</b>: Problem with unit tests failing due to order of the tests and speed of the commits

=== 02-16-2007: Version 0.7
<b>NEW</b>: You can now specify the field types when indexing and searching if
you'd like to preserve its original type:

<b>Indexing</b>

Each field passed can also be a hash with the value being a field type

class Electronic < ActiveRecord::Base
acts_as_solr :fields => [{:price => :range_float}, {:current_time => :date}]
def current_time
Time.now
end
end

<b>Searching</b>
Electronic.find_by_solr "ipod AND price:[* TO 59.99]",
:field_types => [{:price => :range_float}]

The field types accepted are:
<em>:float</em>:: Index the field value as a float (ie.: 12.87)
<em>:integer</em>:: Index the field value as an integer (ie.: 31)
<em>:boolean</em>:: Index the field value as a boolean (ie.: true/false)
<em>:date</em>:: Index the field value as a date (ie.: Wed Nov 15 23:13:03 PST 2006)
<em>:string</em>:: Index the field value as a text string, not applying the same indexing filters as a regular text field
<em>:range_integer</em>:: Index the field value for integer range queries (ie.:[5 TO 20])
<em>:range_float</em>:: Index the field value for float range queries (ie.:[14.56 TO 19.99])

<b>Setting the field type preserves its original type when indexed</b>

<b>FIX</b>: Fixing sorting bug. Thanks for the catch Laurel

<b>FIX</b>: Fixing small bug when installing the plugin

<b>NEW</b>: Adding the :additional_fields option to the acts_as_solr method

=== 02-05-2007: Version 0.6.5
<b>NEW</b>:: Added multi-model search, which can be used to execute a search across multiple models:
Book.multi_solr_search "Napoleon OR Tom", :models => [Movie]

====options:
Accepts the same options as find_by_solr plus:
models:: The additional models you'd like to include in the search
results_format:: Specify the format of the results found
:objects :: Will return an array with the results being objects (default). Example:
Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects
:ids :: Will return an array with the ids of each entry found. Example:
Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :ids
=> [{"id" => "Movie:1"},{"id" => Book:1}]
Where the value of each array is as Model:instance_id

=== 02-03-2007: Version 0.6
<b>NEW</b>:: Added basic faceted search functionality for indexing and searching:

==== Indexing:

class Electronic < ActiveRecord::Base
acts_as_solr :facets => [:category, :manufacturer]
end

==== Searching:

Electronic.find_with_facet "memory", :facets => {:fields =>[:category]}

=== 01-15-2007: Version 0.5
<b>NEW</b>:: Added model association indexing, which means you can include any :has_one, :has_many,
:belongs_to and :has_and_belongs_to_many association to be indexed:

class Category < ActiveRecord::Base
has_many :books
acts_as_solr :include => [:books]
end

class Book < ActiveRecord::Base
belongs_to :category
acts_as_solr :include => [:category]
end

=== 01-11-2007:
<b>NEW</b>:: Added the acts_as_solr's plugin tests

=== 11-07-2006: Version 0.4
<b>NEW</b>:: Added :background option, which takes and integer value (in minutes) to wait before committing the changes to Solr. This depends on rail_cron being installed. By setting up the background job we prevent the users from having to wait for Solr records to be created, and we keep from updating the index over and over for quickly successive changes. (Rob Kaufman)

=== 11-02-2006: Version 0.3
<b>NEW</b>:: Added a method (Model.count_by_solr) that returns the total number of documents found based on query passed
<b>NEW</b>:: Added configuration for production and development environments

=== 10-21-2006: Version 0.2
<b>PLUGIN</b>
<b>FIX</b>:: Fixed bug when mixing search-by-field and 'free' search: Model.find_by_solr 'solr AND name:Thiago'
<b>FIX</b>:: Fixed bug with multi-terms search: Book.find_by_solr 'anteater john'
<b>FIX</b>:: Fixed bug when including more than one search field: Model.find_by_solr 'name:Thiago AND engine:Solr'
<b>FIX</b>:: Fixed bug when rebuilding the index, it wasn't saving the data
<b>NEW</b>:: Added the ability to index custom methods from a model as search fields
<b>NEW</b>:: Added a search method (Model.find_id_by_solr) that will return only the id of the results

<b>SCHEMA.XML</b>
<b>NEW</b>:: Added a new field: <field name="default" type="text" indexed="true" stored="true" />
<b>NEW</b>:: Added a default search field: <defaultSearchField>default</defaultSearchField>
<b>FIX</b>:: Changed the defaultOperator to AND instead of OR

=== 09-29-2006: Version 0.1
<b>PLUGIN</b>
<b>NEW</b>:: Included the option of having a Solr config file inside the rails env.
<b>NEW</b>:: Added the ability of indexing only certain fields, if you chose to.
<b>NEW</b>:: Added configuration options
<b>NEW</b>:: Changed the way the search was done:
Old: You were forced the specify the field you wanted to look for
('field:value') and you had to specify a default search field as
well, for when you didn't include the 'field' in the search term
New: The new search features include:
- You don't have to specify a default search field;
- You are not forced to include the field name in the search term,
unless you choose to search for a specific field ('name:Thiago');
- You can pass the starting row and the number of rows per page,
which is usefull for pagination
<b>NEW</b>:: Included a method to rebuild the index files

<b>SCHEMA.XML</b>
<b>NEW</b>:: Created an optimized version of the config file to better work with this plugin
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2006 Erik Hatcher, Thiago Jackiw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions README.markdown
@@ -0,0 +1,64 @@
Description
======
This plugin adds full text search capabilities and many other nifty features from Apache's [Solr](http://lucene.apache.org/solr/) to any Rails model.
It was based on the first draft by Erik Hatcher.

Installation
======

script/plugin install git://github.com/mattmatt/acts_as_solr.git

Requirements
------
* Java Runtime Environment(JRE) 1.5 aka 5.0 [http://www.java.com/en/download/index.jsp](http://www.java.com/en/download/index.jsp)
* If you have libxml-ruby installed, make sure it's at least version 0.7

Configuration
======
If you are using acts_as_solr as a Rails plugin, everything is configured to work out of the box. You can use `rake solr:start` and `rake solr:stop`
to start and stop the Solr web server (an embedded Jetty). If the default JVM options aren't suitable for
your environment, you can configure them in solr.yml with the option `jvm_options`. There is a default
set for the production environment to have some more memory available for the JVM than the defaults, but
feel free to change them to your liking.

If you are using acts_as_solr as a gem, create a file named lib/tasks/acts_as_solr.rake:
<pre><code>
require "acts_as_solr/tasks"
</code></pre>

Basic Usage
======
<pre><code>
# Just include the line below to any of your ActiveRecord models:
acts_as_solr

# Or if you want, you can specify only the fields that should be indexed:
acts_as_solr :fields => [:name, :author]

# Then to find instances of your model, just do:
Model.search(query) #query is a string representing your query

# Please see ActsAsSolr::ActsMethods for a complete info

</code></pre>


`acts_as_solr` in your tests
======
To test code that uses `acts_as_solr` you must start a Solr server for the test environment. You can do that with `rake solr:start RAILS_ENV=test`

However, if you would like to mock out Solr calls so that a Solr server is not needed (and your tests will run much faster), just add this to your `test_helper.rb` or similar:

<pre><code>
class ActsAsSolr::Post
def self.execute(request)
true
end
end
</pre></code>

([via](http://www.subelsky.com/2007/10/actsassolr-capistranhttpwwwbloggercomim.html#c1646308013209805416))

Release Information
======
Released under the MIT license.

0 comments on commit 46533f0

Please sign in to comment.