Skip to content

Commit 27f8ae4

Browse files
author
Mat Brown
committed
Rename everything; clean up Gemfile
1 parent 8782487 commit 27f8ae4

39 files changed

+212
-242
lines changed

Gemfile

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
gem 'sunspot-query', :require => 'sunspot/query', :path => File.dirname(__FILE__)
1+
source :rubygems
22

3-
group :test do
4-
gem 'rspec', '~> 2.0'
5-
gem 'ZenTest'
6-
end
3+
gemspec

Gemfile.lock

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PATH
22
remote: .
33
specs:
4-
sunspot-query (1.0.0.alpha.1)
4+
soolr (2.0.pre.1)
55

66
GEM
7+
remote: http://rubygems.org/
78
specs:
8-
ZenTest (4.5.0)
99
diff-lcs (1.1.2)
1010
rspec (2.5.0)
1111
rspec-core (~> 2.5.0)
@@ -20,6 +20,5 @@ PLATFORMS
2020
ruby
2121

2222
DEPENDENCIES
23-
ZenTest
2423
rspec (~> 2.0)
25-
sunspot-query!
24+
soolr!

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2011 sunspot-query contributors
3+
Copyright (c) 2011 Soolr contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.mkd

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Sunspot::Query
1+
# Soolr
22

3-
sunspot-query is a library for constructing Solr queries using an
3+
Soolr is a library for constructing Solr queries using an
44
object-oriented API. It is a (conceptual) extraction from the
55
[Sunspot](http://github.com/outoftime/sunspot) library, but unlike Sunspot,
66
it makes no assumptions about how you want to use Solr.
@@ -11,5 +11,5 @@ This is very much a work in progress. Contributions are welcome!
1111

1212
## License
1313

14-
Sunspot::Query can be freely distributed under the MIT License. See the LICENSE
14+
Soolr can be freely distributed under the MIT License. See the LICENSE
1515
file in this repository for details.

lib/soolr.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Soolr
2+
TypeMismatch = Class.new(StandardError)
3+
4+
autoload :Type, 'soolr/type'
5+
autoload :StringType, 'soolr/string_type'
6+
autoload :IntegerType, 'soolr/integer_type'
7+
autoload :FloatType, 'soolr/float_type'
8+
autoload :TimeType, 'soolr/time_type'
9+
autoload :BooleanType, 'soolr/boolean_type'
10+
11+
autoload :Field, 'soolr/field'
12+
13+
autoload :Condition, 'soolr/condition'
14+
autoload :Not, 'soolr/not'
15+
autoload :EqualTo, 'soolr/equal_to'
16+
autoload :LessThan, 'soolr/less_than'
17+
end

lib/soolr/boolean_type.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Soolr
2+
class BooleanType < Type
3+
def serialize(boolean)
4+
(!!boolean).inspect
5+
end
6+
end
7+
end

lib/soolr/condition.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Soolr
2+
class Condition
3+
def initialize(field, value)
4+
@field, @value, @inverted = field, value, inverted
5+
end
6+
7+
def to_boolean_query
8+
@boolean_query ||=
9+
begin
10+
query = "#{@field.name}:#{to_boolean_expression}"
11+
if @inverted then "-#{query}"
12+
else query
13+
end
14+
end
15+
end
16+
17+
def ==(other)
18+
!other.respond_to?(:to_boolean_query) ||
19+
to_boolean_query == other.to_boolean_query
20+
end
21+
22+
private
23+
24+
def serialized_value
25+
@field.serialize(@value)
26+
end
27+
28+
def escape(string)
29+
string.gsub(/[ :\\\-]/) { |c| "\\#{c}" } #FIXME Escape all special characters; figure out how to do this with back-references
30+
end
31+
end
32+
end

lib/soolr/equal_to.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Soolr
2+
class EqualTo < Condition
3+
def inverse
4+
Not.new(self)
5+
end
6+
7+
def to_boolean_expression
8+
escape(serialized_value)
9+
end
10+
end
11+
end

lib/soolr/field.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Soolr
2+
class Field
3+
attr_reader :name, :type
4+
5+
def initialize(name, type)
6+
@name, @type = name, type
7+
end
8+
9+
def serialize(value)
10+
@type.serialize(value)
11+
end
12+
end
13+
end

lib/soolr/float_type.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Soolr
2+
class FloatType < Type
3+
def serialize(float)
4+
if Float === float then float.to_s
5+
else float.to_f.to_s
6+
end
7+
rescue NoMethodError
8+
raise TypeMismatch, "Unable to cast #{float.inspect} to float"
9+
end
10+
end
11+
end

lib/soolr/integer_type.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Soolr
2+
class IntegerType < Type
3+
def serialize(integer)
4+
if Integer === integer then integer.to_s
5+
else integer.to_i.to_s
6+
end
7+
rescue NoMethodError
8+
raise TypeMismatch, "Unable to cast #{integer.inspect} to integer"
9+
end
10+
end
11+
end

lib/soolr/less_than.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Soolr
2+
class LessThan < Condition
3+
private
4+
5+
def to_boolean_expression
6+
"(..#{escape(serialized_value)})"
7+
end
8+
end
9+
end

lib/soolr/not.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Soolr
2+
class Not
3+
def initialize(condition)
4+
@condition = condition
5+
end
6+
7+
def to_boolean_query
8+
"-#{@condition.to_boolean_query}"
9+
end
10+
11+
def inverse
12+
@condition
13+
end
14+
end
15+
end

lib/soolr/string_type.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Soolr
2+
class StringType < Type
3+
def serialize(string)
4+
string.to_s
5+
end
6+
end
7+
end

lib/soolr/time_type.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'time'
2+
3+
module Soolr
4+
class TimeType < Type
5+
def serialize(time)
6+
time.utc.xmlschema
7+
end
8+
end
9+
end

lib/soolr/type.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'singleton'
2+
3+
module Soolr
4+
class Type
5+
include Singleton
6+
7+
class <<self
8+
def method_missing(method, *args, &block)
9+
if instance.respond_to?(method)
10+
instance.__send__(method, *args, &block)
11+
else
12+
super
13+
end
14+
end
15+
end
16+
end
17+
end

lib/soolr/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Soolr
2+
VERSION = '2.0.pre.1'
3+
end

lib/sunspot/query.rb

-19
This file was deleted.

lib/sunspot/query/boolean_type.rb

-9
This file was deleted.

lib/sunspot/query/condition.rb

-34
This file was deleted.

lib/sunspot/query/equal_to.rb

-13
This file was deleted.

lib/sunspot/query/field.rb

-15
This file was deleted.

lib/sunspot/query/float_type.rb

-13
This file was deleted.

lib/sunspot/query/integer_type.rb

-13
This file was deleted.

lib/sunspot/query/less_than.rb

-11
This file was deleted.

lib/sunspot/query/not.rb

-17
This file was deleted.

lib/sunspot/query/string_type.rb

-9
This file was deleted.

0 commit comments

Comments
 (0)