xapit 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
1
+ *0.2.6* (July 6th, 2009)
2
+
3
+ * search for field conditions in query string, only supported by ClassicQueryParser
4
+
5
+ search("age:17")
6
+
7
+ * check if xapian database exists before removing
8
+
9
+ * search multiple conditions with OR by passing an array
10
+
11
+ :conditions => [{ :category_id => 1 }, { :priority => 2 }]
12
+
13
+
1
14
  *0.2.5* (June 26th, 2009)
2
15
 
3
16
  * adding wildcard matching for general search query (ClassicQueryParser only)
data/Manifest CHANGED
@@ -57,5 +57,4 @@ spec/xapit/query_spec.rb
57
57
  spec/xapit_member.rb
58
58
  tasks/spec.rb
59
59
  tasks/xapit.rake
60
- TODO
61
60
  uninstall.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('xapit', '0.2.5') do |p|
5
+ Echoe.new('xapit', '0.2.6') do |p|
6
6
  p.summary = "Ruby library for interacting with Xapian, a full text search engine."
7
7
  p.description = "Ruby library for interacting with Xapian, a full text search engine."
8
8
  p.url = "http://github.com/ryanb/xapit"
@@ -109,3 +109,22 @@ Scenario: Query no partial match in keywords with one letter
109
109
  | Jack | J |
110
110
  When I query for " J*"
111
111
  Then I should find records named "Jack"
112
+
113
+ Scenario: Query for separate OR conditions
114
+ Given the following indexed records
115
+ | name | age |
116
+ | John | 23 |
117
+ | Jane | 17 |
118
+ | Jack | 18 |
119
+ When I query "age" matching "17" or "name" matching "Jack"
120
+ Then I should find records named "Jane, Jack"
121
+
122
+ @focus
123
+ Scenario: Query for condition in keywords string
124
+ Given the following indexed records
125
+ | name | age |
126
+ | John | 23 |
127
+ | Jane | 17 |
128
+ | Jack | 17 |
129
+ When I query for "age:17"
130
+ Then I should find records named "Jane, Jack"
@@ -67,27 +67,31 @@ Then /^I should have ([0-9]+) records? total$/ do |num|
67
67
  end
68
68
 
69
69
  When /^I query "([^\"]*)" matching "([^\"]*)"$/ do |field, value|
70
- @records = XapitMember.search("", :conditions => { field.to_sym => value })
70
+ @records = XapitMember.search(:conditions => { field.to_sym => value })
71
71
  end
72
72
 
73
73
  When /^I query "([^\"]*)" not matching "([^\"]*)"$/ do |field, value|
74
- @records = XapitMember.search("", :not_conditions => { field.to_sym => value })
74
+ @records = XapitMember.search(:not_conditions => { field.to_sym => value })
75
+ end
76
+
77
+ When /^I query "([^\"]*)" matching "([^\"]*)" or "([^\"]*)" matching "([^\"]*)"$/ do |field1, value1, field2, value2|
78
+ @records = XapitMember.search(:conditions => [{ field1.to_sym => value1 }, { field2.to_sym => value2 }])
75
79
  end
76
80
 
77
81
  When /^I query "([^\"]*)" between (\d+) and (\d+)$/ do |field, beginning, ending|
78
- @records = XapitMember.search("", :conditions => { field.to_sym => beginning.to_i..ending.to_i })
82
+ @records = XapitMember.search(:conditions => { field.to_sym => beginning.to_i..ending.to_i })
79
83
  end
80
84
 
81
85
  When /^I query page ([0-9]+) at ([0-9]+) per page$/ do |page, per_page|
82
- @records = XapitMember.search("", :page => page, :per_page => per_page.to_i)
86
+ @records = XapitMember.search(:page => page, :per_page => per_page.to_i)
83
87
  end
84
88
 
85
89
  When /^I query facets "([^\"]*)"$/ do |facets|
86
- @records = XapitMember.search("", :facets => facets)
90
+ @records = XapitMember.search(:facets => facets)
87
91
  end
88
92
 
89
93
  When /^I query "([^\"]*)" sorted by (.*?)( descending)?$/ do |keywords, sort, descending|
90
- @records = XapitMember.search("", :order => sort.split(', '), :descending => descending)
94
+ @records = XapitMember.search(:order => sort.split(', '), :descending => descending)
91
95
  end
92
96
 
93
97
  When /^I query for similar records for "([^\"]*)"$/ do |keywords|
data/lib/xapit/config.rb CHANGED
@@ -65,8 +65,8 @@ module Xapit
65
65
  end
66
66
 
67
67
  # Removes the configured database file and clears the stored one in memory.
68
- def remove_database # this can be a bit dangers, maybe do some checking here first?
69
- FileUtils.rm_rf(path) if File.exist? path
68
+ def remove_database
69
+ FileUtils.rm_rf(path) if File.exist? File.join(path, "iamflint")
70
70
  @database = nil
71
71
  @writable_database = nil
72
72
  end
@@ -49,7 +49,7 @@ module Xapit
49
49
  # Adds a field attribute. Field terms are not split by word so it is not designed for full text search.
50
50
  # Instead you can filter through a field using the :conditions hash in a search query.
51
51
  #
52
- # Article.search("", :conditions => { :priority => 5 })
52
+ # Article.search(:conditions => { :priority => 5 })
53
53
  #
54
54
  # Multiple field values are supported if the given attribute is an array.
55
55
  #
@@ -84,7 +84,10 @@ module Xapit
84
84
  # @articles = Article.search("phone", :order => [:category_id, :id], :descending => true)
85
85
  #
86
86
  # # basic boolean matching is supported
87
- # @articles = Article.search("phone or fax not email")
87
+ # @articles = Article.search("phone OR fax NOT email")
88
+ #
89
+ # # field conditions in query string
90
+ # @articles = Article.search("priority:3")
88
91
  #
89
92
  # # no need to specify first query string when searching all records
90
93
  # @articles = Article.search(:conditions => { :category_id => params[:category_id] })
@@ -92,6 +95,9 @@ module Xapit
92
95
  # # search partial terms with asterisk (only supported at end of term)
93
96
  # @articles = Article.search("sab*", :conditions => { :name => "Din*" })
94
97
  #
98
+ # # search multiple conditions with OR by passing an array
99
+ # @articles = Article.search(:conditions => [{ :category_id => 1 }, { :priority => 2 }])
100
+ #
95
101
  def search(*args)
96
102
  Collection.new(self, *args)
97
103
  end
@@ -68,11 +68,11 @@ module Xapit
68
68
  end
69
69
 
70
70
  def condition_terms
71
- condition_terms_from_hash(@options[:conditions])
71
+ parse_conditions(@options[:conditions])
72
72
  end
73
73
 
74
74
  def not_condition_terms
75
- condition_terms_from_hash(@options[:not_conditions])
75
+ parse_conditions(@options[:not_conditions])
76
76
  end
77
77
 
78
78
  def facet_terms
@@ -108,20 +108,26 @@ module Xapit
108
108
 
109
109
  private
110
110
 
111
- def condition_terms_from_hash(conditions)
112
- if conditions
113
- conditions.map do |name, value|
114
- if value.kind_of? Array
115
- Query.new(value.map { |v| condition_term(name, v) }, :or)
116
- else
117
- condition_term(name, value)
118
- end
119
- end.flatten
111
+ def parse_conditions(conditions)
112
+ if conditions.kind_of? Array
113
+ [Query.new(conditions.map { |hash| Query.new(condition_terms_from_hash(hash)) }, :or)]
114
+ elsif conditions.kind_of? Hash
115
+ condition_terms_from_hash(conditions)
120
116
  else
121
117
  []
122
118
  end
123
119
  end
124
120
 
121
+ def condition_terms_from_hash(conditions)
122
+ conditions.map do |name, value|
123
+ if value.kind_of? Array
124
+ Query.new(value.map { |v| condition_term(name, v) }, :or)
125
+ else
126
+ condition_term(name, value)
127
+ end
128
+ end.flatten
129
+ end
130
+
125
131
  def condition_term(name, value)
126
132
  if value.kind_of?(Range) && @member_class
127
133
  position = @member_class.xapit_index_blueprint.position_of_field(name)
@@ -18,6 +18,11 @@ module Xapit
18
18
  parser.stemmer = Xapian::Stem.new(Config.stemming)
19
19
  parser.stemming_strategy = Xapian::QueryParser::STEM_SOME
20
20
  parser.default_op = Xapian::Query::OP_AND
21
+ if @member_class
22
+ @member_class.xapit_index_blueprint.field_attributes.each do |field|
23
+ parser.add_prefix(field.to_s, "X#{field}-")
24
+ end
25
+ end
21
26
  parser
22
27
  end
23
28
  end
@@ -45,4 +45,18 @@ describe Xapit::Config do
45
45
  Xapit::Config.setup(:stemming => "german")
46
46
  Xapit::Config.stemming == "german"
47
47
  end
48
+
49
+ it "should remove the database if it is a true xapian database" do
50
+ Xapit::Config.writable_database # load the database
51
+ Xapit::Config.remove_database
52
+ File.exist?(Xapit::Config.path).should be_false
53
+ end
54
+
55
+ it "should NOT remove the database if it is not a xapian database" do
56
+ path = Xapit::Config.path + "/testing"
57
+ FileUtils.mkdir_p(path)
58
+ Xapit::Config.remove_database
59
+ File.exist?(Xapit::Config.path).should be_true
60
+ FileUtils.rm_rf(Xapit::Config.path)
61
+ end
48
62
  end
@@ -65,7 +65,7 @@ describe Xapit::Facet do
65
65
 
66
66
  it "should not list facets if only one option is found" do
67
67
  blueprint = Xapit::FacetBlueprint.new(XapitMember, 0, :visible)
68
- facets = XapitMember.search("", :facets => blueprint.identifiers_for(@visible1)).facets
68
+ facets = XapitMember.search(:facets => blueprint.identifiers_for(@visible1)).facets
69
69
  facets.should be_empty
70
70
  end
71
71
  end
data/xapit.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{xapit}
5
- s.version = "0.2.5"
5
+ s.version = "0.2.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Bates"]
9
- s.date = %q{2009-06-26}
9
+ s.date = %q{2009-07-06}
10
10
  s.description = %q{Ruby library for interacting with Xapian, a full text search engine.}
11
11
  s.email = %q{ryan (at) railscasts (dot) com}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/xapit/adapters/abstract_adapter.rb", "lib/xapit/adapters/active_record_adapter.rb", "lib/xapit/adapters/data_mapper_adapter.rb", "lib/xapit/collection.rb", "lib/xapit/config.rb", "lib/xapit/facet.rb", "lib/xapit/facet_blueprint.rb", "lib/xapit/facet_option.rb", "lib/xapit/index_blueprint.rb", "lib/xapit/indexers/abstract_indexer.rb", "lib/xapit/indexers/classic_indexer.rb", "lib/xapit/indexers/simple_indexer.rb", "lib/xapit/membership.rb", "lib/xapit/query.rb", "lib/xapit/query_parsers/abstract_query_parser.rb", "lib/xapit/query_parsers/classic_query_parser.rb", "lib/xapit/query_parsers/simple_query_parser.rb", "lib/xapit/rake_tasks.rb", "lib/xapit.rb", "LICENSE", "README.rdoc", "tasks/spec.rb", "tasks/xapit.rake", "TODO"]
13
- s.files = ["CHANGELOG", "features/facets.feature", "features/finding.feature", "features/indexing.feature", "features/sorting.feature", "features/step_definitions/common_steps.rb", "features/step_definitions/xapit_steps.rb", "features/suggestions.feature", "features/support/env.rb", "features/support/xapit_helpers.rb", "init.rb", "install.rb", "lib/xapit/adapters/abstract_adapter.rb", "lib/xapit/adapters/active_record_adapter.rb", "lib/xapit/adapters/data_mapper_adapter.rb", "lib/xapit/collection.rb", "lib/xapit/config.rb", "lib/xapit/facet.rb", "lib/xapit/facet_blueprint.rb", "lib/xapit/facet_option.rb", "lib/xapit/index_blueprint.rb", "lib/xapit/indexers/abstract_indexer.rb", "lib/xapit/indexers/classic_indexer.rb", "lib/xapit/indexers/simple_indexer.rb", "lib/xapit/membership.rb", "lib/xapit/query.rb", "lib/xapit/query_parsers/abstract_query_parser.rb", "lib/xapit/query_parsers/classic_query_parser.rb", "lib/xapit/query_parsers/simple_query_parser.rb", "lib/xapit/rake_tasks.rb", "lib/xapit.rb", "LICENSE", "Manifest", "rails_generators/xapit/templates/setup_xapit.rb", "rails_generators/xapit/templates/xapit.rake", "rails_generators/xapit/USAGE", "rails_generators/xapit/xapit_generator.rb", "Rakefile", "README.rdoc", "spec/spec_helper.rb", "spec/xapit/adapters/active_record_adapter_spec.rb", "spec/xapit/adapters/data_mapper_adapter_spec.rb", "spec/xapit/collection_spec.rb", "spec/xapit/config_spec.rb", "spec/xapit/facet_blueprint_spec.rb", "spec/xapit/facet_option_spec.rb", "spec/xapit/facet_spec.rb", "spec/xapit/index_blueprint_spec.rb", "spec/xapit/indexers/abstract_indexer_spec.rb", "spec/xapit/indexers/classic_indexer_spec.rb", "spec/xapit/indexers/simple_indexer_spec.rb", "spec/xapit/membership_spec.rb", "spec/xapit/query_parsers/abstract_query_parser_spec.rb", "spec/xapit/query_parsers/classic_query_parser_spec.rb", "spec/xapit/query_parsers/simple_query_parser_spec.rb", "spec/xapit/query_spec.rb", "spec/xapit_member.rb", "tasks/spec.rb", "tasks/xapit.rake", "TODO", "uninstall.rb", "xapit.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/xapit/adapters/abstract_adapter.rb", "lib/xapit/adapters/active_record_adapter.rb", "lib/xapit/adapters/data_mapper_adapter.rb", "lib/xapit/collection.rb", "lib/xapit/config.rb", "lib/xapit/facet.rb", "lib/xapit/facet_blueprint.rb", "lib/xapit/facet_option.rb", "lib/xapit/index_blueprint.rb", "lib/xapit/indexers/abstract_indexer.rb", "lib/xapit/indexers/classic_indexer.rb", "lib/xapit/indexers/simple_indexer.rb", "lib/xapit/membership.rb", "lib/xapit/query.rb", "lib/xapit/query_parsers/abstract_query_parser.rb", "lib/xapit/query_parsers/classic_query_parser.rb", "lib/xapit/query_parsers/simple_query_parser.rb", "lib/xapit/rake_tasks.rb", "lib/xapit.rb", "LICENSE", "README.rdoc", "tasks/spec.rb", "tasks/xapit.rake"]
13
+ s.files = ["CHANGELOG", "features/facets.feature", "features/finding.feature", "features/indexing.feature", "features/sorting.feature", "features/step_definitions/common_steps.rb", "features/step_definitions/xapit_steps.rb", "features/suggestions.feature", "features/support/env.rb", "features/support/xapit_helpers.rb", "init.rb", "install.rb", "lib/xapit/adapters/abstract_adapter.rb", "lib/xapit/adapters/active_record_adapter.rb", "lib/xapit/adapters/data_mapper_adapter.rb", "lib/xapit/collection.rb", "lib/xapit/config.rb", "lib/xapit/facet.rb", "lib/xapit/facet_blueprint.rb", "lib/xapit/facet_option.rb", "lib/xapit/index_blueprint.rb", "lib/xapit/indexers/abstract_indexer.rb", "lib/xapit/indexers/classic_indexer.rb", "lib/xapit/indexers/simple_indexer.rb", "lib/xapit/membership.rb", "lib/xapit/query.rb", "lib/xapit/query_parsers/abstract_query_parser.rb", "lib/xapit/query_parsers/classic_query_parser.rb", "lib/xapit/query_parsers/simple_query_parser.rb", "lib/xapit/rake_tasks.rb", "lib/xapit.rb", "LICENSE", "Manifest", "rails_generators/xapit/templates/setup_xapit.rb", "rails_generators/xapit/templates/xapit.rake", "rails_generators/xapit/USAGE", "rails_generators/xapit/xapit_generator.rb", "Rakefile", "README.rdoc", "spec/spec_helper.rb", "spec/xapit/adapters/active_record_adapter_spec.rb", "spec/xapit/adapters/data_mapper_adapter_spec.rb", "spec/xapit/collection_spec.rb", "spec/xapit/config_spec.rb", "spec/xapit/facet_blueprint_spec.rb", "spec/xapit/facet_option_spec.rb", "spec/xapit/facet_spec.rb", "spec/xapit/index_blueprint_spec.rb", "spec/xapit/indexers/abstract_indexer_spec.rb", "spec/xapit/indexers/classic_indexer_spec.rb", "spec/xapit/indexers/simple_indexer_spec.rb", "spec/xapit/membership_spec.rb", "spec/xapit/query_parsers/abstract_query_parser_spec.rb", "spec/xapit/query_parsers/classic_query_parser_spec.rb", "spec/xapit/query_parsers/simple_query_parser_spec.rb", "spec/xapit/query_spec.rb", "spec/xapit_member.rb", "tasks/spec.rb", "tasks/xapit.rake", "uninstall.rb", "xapit.gemspec"]
14
14
  s.homepage = %q{http://github.com/ryanb/xapit}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Xapit", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-26 00:00:00 -07:00
12
+ date: 2009-07-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -44,7 +44,6 @@ extra_rdoc_files:
44
44
  - README.rdoc
45
45
  - tasks/spec.rb
46
46
  - tasks/xapit.rake
47
- - TODO
48
47
  files:
49
48
  - CHANGELOG
50
49
  - features/facets.feature
@@ -105,7 +104,6 @@ files:
105
104
  - spec/xapit_member.rb
106
105
  - tasks/spec.rb
107
106
  - tasks/xapit.rake
108
- - TODO
109
107
  - uninstall.rb
110
108
  - xapit.gemspec
111
109
  has_rdoc: true
data/TODO DELETED
@@ -1,23 +0,0 @@
1
- Indexing
2
- + re-indexing support for new/changed models (?)
3
- + auto-reload xapian database in memory if database recently indexed
4
-
5
- Finding
6
- ? support non-ascii characters in find (å, ä, ö)
7
- + range in conditions
8
- + support "age:17" condition matching in query
9
- + add classes option to Xapit.search to limit which classes are included
10
- + support @collection.facets on Xapit.search (multiple classes)
11
- + support :order option for Xapit.search (multiple classes)
12
-
13
- Facets
14
- + sort facet options
15
- + handle unique id collision gracefully
16
-
17
- Performance
18
- - benchmark indexing
19
- - multiple id finds in a single query
20
-
21
- Other
22
- - turn into Ruby Gem with clear instructions on requirements
23
- + remove dependency on active_support