mama_search 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +119 -0
  4. data/LICENSE +20 -0
  5. data/README.md +46 -0
  6. data/Rakefile +7 -0
  7. data/cucumber.yml +8 -0
  8. data/features/rails_generator.feature +10 -0
  9. data/features/rake_tasks.feature +12 -0
  10. data/features/step_definitions/elasticsearch_steps.rb +5 -0
  11. data/features/step_definitions/rails_steps.rb +38 -0
  12. data/features/support/aruba.rb +1 -0
  13. data/features/support/hooks.rb +3 -0
  14. data/lib/mama_search.rb +5 -0
  15. data/lib/mama_search/generators/USAGE +12 -0
  16. data/lib/mama_search/generators/install_generator.rb +32 -0
  17. data/lib/mama_search/generators/templates/elasticsearch.app.yml +5 -0
  18. data/lib/mama_search/generators/templates/elasticsearch.in.sh +41 -0
  19. data/lib/mama_search/generators/templates/elasticsearch.rb +5 -0
  20. data/lib/mama_search/generators/templates/elasticsearch.yml +0 -0
  21. data/lib/mama_search/generators/templates/logging.yml +29 -0
  22. data/lib/mama_search/tasks.rb +8 -0
  23. data/lib/mama_search/version.rb +3 -0
  24. data/mama_search.gemspec +28 -0
  25. data/vendor/elasticsearch-0.14.2/LICENSE.txt +537 -0
  26. data/vendor/elasticsearch-0.14.2/NOTICE.txt +12 -0
  27. data/vendor/elasticsearch-0.14.2/README.textile +219 -0
  28. data/vendor/elasticsearch-0.14.2/bin/elasticsearch +180 -0
  29. data/vendor/elasticsearch-0.14.2/bin/elasticsearch.bat +37 -0
  30. data/vendor/elasticsearch-0.14.2/bin/elasticsearch.in.sh +41 -0
  31. data/vendor/elasticsearch-0.14.2/bin/plugin +33 -0
  32. data/vendor/elasticsearch-0.14.2/bin/plugin.bat +25 -0
  33. data/vendor/elasticsearch-0.14.2/config/elasticsearch.yml +0 -0
  34. data/vendor/elasticsearch-0.14.2/config/logging.yml +29 -0
  35. data/vendor/elasticsearch-0.14.2/lib/elasticsearch-0.14.2.jar +0 -0
  36. data/vendor/elasticsearch-0.14.2/lib/jline-0.9.94.jar +0 -0
  37. data/vendor/elasticsearch-0.14.2/lib/jna-3.2.7.jar +0 -0
  38. data/vendor/elasticsearch-0.14.2/lib/log4j-1.2.15.jar +0 -0
  39. data/vendor/elasticsearch-0.14.2/lib/lucene-analyzers-3.0.3.jar +0 -0
  40. data/vendor/elasticsearch-0.14.2/lib/lucene-core-3.0.3.jar +0 -0
  41. data/vendor/elasticsearch-0.14.2/lib/lucene-fast-vector-highlighter-3.0.3.jar +0 -0
  42. data/vendor/elasticsearch-0.14.2/lib/lucene-highlighter-3.0.3.jar +0 -0
  43. data/vendor/elasticsearch-0.14.2/lib/lucene-memory-3.0.3.jar +0 -0
  44. data/vendor/elasticsearch-0.14.2/lib/lucene-queries-3.0.3.jar +0 -0
  45. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-amd64-linux.so +0 -0
  46. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-amd64-solaris.so +0 -0
  47. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-sparc-solaris.so +0 -0
  48. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-sparc64-solaris.so +0 -0
  49. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-universal-macosx.dylib +0 -0
  50. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-universal64-macosx.dylib +0 -0
  51. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-x86-freebsd-5.so +0 -0
  52. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-x86-freebsd-6.so +0 -0
  53. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-x86-linux.so +0 -0
  54. data/vendor/elasticsearch-0.14.2/lib/sigar/libsigar-x86-solaris.so +0 -0
  55. data/vendor/elasticsearch-0.14.2/lib/sigar/sigar-1.6.3.jar +0 -0
  56. data/vendor/elasticsearch-0.14.2/lib/sigar/sigar-amd64-winnt.dll +0 -0
  57. data/vendor/elasticsearch-0.14.2/lib/sigar/sigar-x86-winnt.dll +0 -0
  58. data/vendor/elasticsearch-0.14.2/lib/sigar/sigar-x86-winnt.lib +0 -0
  59. metadata +218 -0
@@ -0,0 +1,12 @@
1
+ ElasticSearch
2
+ Copyright 2009-2010 Elastic Search and Shay Banon
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
6
+
7
+ This product makes use of the google-collections library from
8
+ http://code.google.com/p/google-collections/.
9
+ Copyright (C) 2008 Google Inc.
10
+
11
+ Yaml support uses SnakeYaml Copyright of Andrey Somov under the
12
+ Apache 2 License.
@@ -0,0 +1,219 @@
1
+ h1. ElasticSearch
2
+
3
+ h2. A Distributed RESTful Search Engine
4
+
5
+ h3. "http://www.elasticsearch.com":http://www.elasticsearch.com
6
+
7
+ ElasticSearch is a distributed RESTful search engine built for the cloud. Features include:
8
+
9
+ * Distributed and Highly Available Search Engine.
10
+ ** Each index is fully sharded with a configurable number of shards.
11
+ ** Each shard can have one or more replicas.
12
+ ** Read / Search operations performed on either one of the replica shard.
13
+ * Multi Tenant with Multi Types.
14
+ ** Support for more than one index.
15
+ ** Support for more than one type per index.
16
+ ** Index level configuration (number of shards, index storage, ...).
17
+ * Various set of APIs
18
+ ** HTTP RESTful API
19
+ ** Native Java API.
20
+ ** All APIs perform automatic node operation rerouting.
21
+ * Document oriented
22
+ ** No need for upfront schema definition.
23
+ ** Schema can be defined per type for customization of the indexing process.
24
+ * Reliable, Asynchronous Write Behind for long term persistency.
25
+ * (Near) Real Time Search.
26
+ * Built on top of Lucene
27
+ ** Each shard is a fully functional Lucene index
28
+ ** All the power of Lucene easily exposed through simple configuration / plugins.
29
+ * Per operation consistency
30
+ ** Single document level operations are atomic, consistent, isolated and durable.
31
+ * Open Source under Apache 2 License.
32
+
33
+ h2. Getting Started
34
+
35
+ Fist of all, DON'T PANIC. It will take 5 minutes to get the gist of what ElasticSearch is all about.
36
+
37
+ h3. Installation
38
+
39
+ * Download and unzip the ElasticSearch installation.
40
+ * Run @bin/elasticsearch -f@ on unix, or @bin/elasticsearch.bat@ on windows.
41
+ * Run @curl -X GET http://localhost:9200/@.
42
+ * Start more servers ...
43
+
44
+ h3. Indexing
45
+
46
+ Lets try and index some twitter like information. First, lets create a twitter user, and add some tweets (the @twitter@ index will be created automatically):
47
+
48
+ <pre>
49
+ curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ "name" : "Shay Banon" }'
50
+
51
+ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
52
+ {
53
+ "user": "kimchy",
54
+ "postDate": "2009-11-15T13:12:00",
55
+ "message": "Trying out Elastic Search, so far so good?"
56
+ }'
57
+
58
+ curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
59
+ {
60
+ "user": "kimchy",
61
+ "postDate": "2009-11-15T14:12:12",
62
+ "message": "Another tweet, will it be indexed?"
63
+ }'
64
+ </pre>
65
+
66
+ Now, lets see if the information was added by GETting it:
67
+
68
+ <pre>
69
+ curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true'
70
+ curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true'
71
+ curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true'
72
+ </pre>
73
+
74
+ h3. Searching
75
+
76
+ Mmm search..., shouldn't it be elastic?
77
+ Lets find all the tweets that @kimchy@ posted:
78
+
79
+ <pre>
80
+ curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true'
81
+ </pre>
82
+
83
+ We can also use the JSON query language ElasticSearch provides instead of a query string:
84
+
85
+ <pre>
86
+ curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
87
+ {
88
+ "query" : {
89
+ "term" : { "user": "kimchy" }
90
+ }
91
+ }'
92
+ </pre>
93
+
94
+ Just for kicks, lets get all the documents stored (we should see the user as well):
95
+
96
+ <pre>
97
+ curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
98
+ {
99
+ "query" : {
100
+ "matchAll" : {}
101
+ }
102
+ }'
103
+ </pre>
104
+
105
+ We can also do range search (the @postDate@ was automatically identified as date)
106
+
107
+ <pre>
108
+ curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
109
+ {
110
+ "query" : {
111
+ "range" : {
112
+ "postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
113
+ }
114
+ }
115
+ }'
116
+ </pre>
117
+
118
+ There are many more options to perform search, after all, its a search product no? All the familiar Lucene queries are available through the JSON query language, or through the query parser.
119
+
120
+ h3. Multi Tenant - Indices and Types
121
+
122
+ Maan, that twitter index might get big (in this case, index size == valuation). Lets see if we can structure our twitter system a bit differently in order to support such large amount of data.
123
+
124
+ ElasticSearch support multiple indices, as well as multiple types per index. In the previous example we used an index called @twitter@, with two types, @user@ and @tweet@.
125
+
126
+ Another way to define our simple twitter system is to have a different index per user (though note that an index has an overhead). Here is the indexing curl's in this case:
127
+
128
+ <pre>
129
+ curl -XPUT 'http://localhost:9200/kimchy/info/1' -d '{ "name" : "Shay Banon" }'
130
+
131
+ curl -XPUT 'http://localhost:9200/kimchy/tweet/1' -d '
132
+ {
133
+ "user": "kimchy",
134
+ "postDate": "2009-11-15T13:12:00",
135
+ "message": "Trying out Elastic Search, so far so good?"
136
+ }'
137
+
138
+ curl -XPUT 'http://localhost:9200/kimchy/tweet/2' -d '
139
+ {
140
+ "user": "kimchy",
141
+ "postDate": "2009-11-15T14:12:12",
142
+ "message": "Another tweet, will it be indexed?"
143
+ }'
144
+ </pre>
145
+
146
+ The above index information into the @kimchy@ index, with two types, @info@ and @tweet@. Each user will get his own special index.
147
+
148
+ Complete control on the index level is allowed. As an example, in the above case, we would want to change from the default 5 shards with 1 replica per index, to only 1 shard with 1 replica per index (== per twitter user). Here is how this can be done (the configuration can be in yaml as well):
149
+
150
+ <pre>
151
+ curl -XPUT http://localhost:9200/another_user/ -d '
152
+ {
153
+ "index" : {
154
+ "numberOfShards" : 1,
155
+ "numberOfReplicas" : 1
156
+ }
157
+ }'
158
+ </pre>
159
+
160
+ Search (and similar operations) are multi index aware. This means that we can easily search on more than one
161
+ index (twitter user), for example:
162
+
163
+ <pre>
164
+ curl -XGET 'http://localhost:9200/kimchy,another_user/_search?pretty=true' -d '
165
+ {
166
+ "query" : {
167
+ "matchAll" : {}
168
+ }
169
+ }'
170
+ </pre>
171
+
172
+ Or on all the indices:
173
+
174
+ <pre>
175
+ curl -XGET 'http://localhost:9200/_search?pretty=true' -d '
176
+ {
177
+ "query" : {
178
+ "matchAll" : {}
179
+ }
180
+ }'
181
+ </pre>
182
+
183
+ {One liner teaser}: And the cool part about that? You can easily search on multiple twitter users (indices), with different boost levels per user (index), making social search so much simpler (results from my friends rank higher than results from my friends friends).
184
+
185
+ h3. Distributed, Highly Available
186
+
187
+ Lets face it, things will fail....
188
+
189
+ ElasticSearch is a highly available and distributed search engine. Each index is broken down into shards, and each shard can have one or more replica. By default, an index is created with 5 shards and 1 replica per shard (5/1). There are many topologies that can be used, including 1/10 (improve search performance), or 20/1 (improve indexing performance, with search executed in a map reduce fashion across shards).
190
+
191
+ In order to play with Elastic Search distributed nature, simply bring more nodes up and shut down nodes. The system will continue to serve requests (make sure you use the correct http port) with the latest data indexed.
192
+
193
+ h3. Where to go from here?
194
+
195
+ We have just covered a very small portion of what ElasticSearch is all about. For more information, please refer to: .
196
+
197
+ h3. Building from Source
198
+
199
+ ElasticSearch uses Gradle:http://www.gradle.org for its build system. In order to create a distribution, simply run @gradlew@, the distribution will be created under @build/distributions@.
200
+
201
+ h1. License
202
+
203
+ <pre>
204
+ This software is licensed under the Apache 2 license, quoted below.
205
+
206
+ Copyright 2009-2010 Shay Banon and ElasticSearch <http://www.elasticsearch.com>
207
+
208
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
209
+ use this file except in compliance with the License. You may obtain a copy of
210
+ the License at
211
+
212
+ http://www.apache.org/licenses/LICENSE-2.0
213
+
214
+ Unless required by applicable law or agreed to in writing, software
215
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
216
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
217
+ License for the specific language governing permissions and limitations under
218
+ the License.
219
+ </pre>
@@ -0,0 +1,180 @@
1
+ #!/bin/sh
2
+
3
+ # OPTIONS:
4
+ # -f: start in the foreground
5
+ # -p <filename>: log the pid to a file (useful to kill it later)
6
+
7
+ # CONTROLLING STARTUP:
8
+ #
9
+ # This script relies on few environment variables to determine startup
10
+ # behavior, those variables are:
11
+ #
12
+ # CLASSPATH -- A Java classpath containing everything necessary to run.
13
+ # JAVA_OPTS -- Additional arguments to the JVM for heap size, etc
14
+ # ES_JAVA_OPTS -- External Java Opts on top of the defaults set
15
+ #
16
+ #
17
+ # Optionally, exact memory values can be set using the following values, note,
18
+ # they can still be set using the `ES_JAVA_OPTS`. Sample format include "512m", and "10g".
19
+ #
20
+ # ES_MIN_MEM -- The minimum number of memory to allocate.
21
+ # ES_MAX_MEM -- The maximum number of memory to allocate.
22
+ #
23
+ # As a convenience, a fragment of shell is sourced in order to set one or
24
+ # more of these variables. This so-called `include' can be placed in a
25
+ # number of locations and will be searched for in order. The lowest
26
+ # priority search path is the same directory as the startup script, and
27
+ # since this is the location of the sample in the project tree, it should
28
+ # almost work Out Of The Box.
29
+ #
30
+ # Any serious use-case though will likely require customization of the
31
+ # include. For production installations, it is recommended that you copy
32
+ # the sample to one of /usr/share/elasticsearch/elasticsearch.in.sh,
33
+ # /usr/local/share/elasticsearch/elasticsearch.in.sh, or
34
+ # /opt/elasticsearch/elasticsearch.in.sh and make your modifications there.
35
+ #
36
+ # Another option is to specify the full path to the include file in the
37
+ # environment. For example:
38
+ #
39
+ # $ ES_INCLUDE=/path/to/in.sh elasticsearch -p /var/run/es.pid
40
+ #
41
+ # Note: This is particularly handy for running multiple instances on a
42
+ # single installation, or for quick tests.
43
+ #
44
+ # If you would rather configure startup entirely from the environment, you
45
+ # can disable the include by exporting an empty ES_INCLUDE, or by
46
+ # ensuring that no include files exist in the aforementioned search list.
47
+ # Be aware that you will be entirely responsible for populating the needed
48
+ # environment variables.
49
+
50
+
51
+ SCRIPT="$0"
52
+
53
+ # SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
54
+ while [ -h "$SCRIPT" ] ; do
55
+ ls=`ls -ld "$SCRIPT"`
56
+ # Drop everything prior to ->
57
+ link=`expr "$ls" : '.*-> \(.*\)$'`
58
+ if expr "$link" : '/.*' > /dev/null; then
59
+ SCRIPT="$link"
60
+ else
61
+ SCRIPT=`dirname "$SCRIPT"`/"$link"
62
+ fi
63
+ done
64
+
65
+ # determine elasticsearch home
66
+ ES_HOME=`dirname "$SCRIPT"`/..
67
+
68
+ # make ELASTICSEARCH_HOME absolute
69
+ ES_HOME=`cd $ES_HOME; pwd`
70
+
71
+
72
+ if [ -x $JAVA_HOME/bin/java ]; then
73
+ JAVA=$JAVA_HOME/bin/java
74
+ else
75
+ JAVA=`which java`
76
+ fi
77
+
78
+ # If an include wasn't specified in the environment, then search for one...
79
+ if [ "x$ES_INCLUDE" = "x" ]; then
80
+ # Locations (in order) to use when searching for an include file.
81
+ for include in /usr/share/elasticsearch/elasticsearch.in.sh \
82
+ /usr/local/share/elasticsearch/elasticsearch.in.sh \
83
+ /opt/elasticsearch/elasticsearch.in.sh \
84
+ ~/.elasticsearch.in.sh \
85
+ `dirname $0`/elasticsearch.in.sh; do
86
+ if [ -r $include ]; then
87
+ . $include
88
+ break
89
+ fi
90
+ done
91
+ # ...otherwise, source the specified include.
92
+ elif [ -r $ES_INCLUDE ]; then
93
+ . $ES_INCLUDE
94
+ fi
95
+
96
+ if [ -z $CLASSPATH ]; then
97
+ echo "You must set the CLASSPATH var" >&2
98
+ exit 1
99
+ fi
100
+
101
+ # Special-case path variables.
102
+ case "`uname`" in
103
+ CYGWIN*)
104
+ CLASSPATH=`cygpath -p -w "$CLASSPATH"`
105
+ ;;
106
+ esac
107
+
108
+ launch_service()
109
+ {
110
+ pidpath=$1
111
+ foreground=$2
112
+ props=$3
113
+ es_parms="-Delasticsearch -Des.path.home=$ES_HOME"
114
+
115
+ if [ "x$pidpath" != "x" ]; then
116
+ es_parms="$es_parms -Des-pidfile=$pidpath"
117
+ fi
118
+
119
+ # The es-daemon option will tell Bootstrap to close stdout/stderr,
120
+ # but it's up to us not to background.
121
+ if [ "x$foreground" != "x" ]; then
122
+ es_parms="$es_parms -Des-foreground=yes"
123
+ exec $JAVA $JAVA_OPTS $ES_JAVA_OPTS $es_parms -cp $CLASSPATH $props \
124
+ org.elasticsearch.bootstrap.Bootstrap
125
+ else
126
+ # Startup Bootstrap, background it, and write the pid.
127
+ exec $JAVA $JAVA_OPTS $ES_JAVA_OPTS $es_parms -cp $CLASSPATH $props \
128
+ org.elasticsearch.bootstrap.Bootstrap <&- &
129
+ [ ! -z $pidpath ] && printf "%d" $! > $pidpath
130
+ fi
131
+
132
+ return $?
133
+ }
134
+
135
+ # Parse any command line options.
136
+ args=`getopt vfhp:D:X: "$@"`
137
+ eval set -- "$args"
138
+
139
+ while true; do
140
+ case "$1" in
141
+ -v)
142
+ $JAVA $JAVA_OPTS $ES_JAVA_OPTS $es_parms -cp $CLASSPATH $props \
143
+ org.elasticsearch.Version
144
+ exit 0
145
+ ;;
146
+ -p)
147
+ pidfile="$2"
148
+ shift 2
149
+ ;;
150
+ -f)
151
+ foreground="yes"
152
+ shift
153
+ ;;
154
+ -h)
155
+ echo "Usage: $0 [-f] [-h] [-p pidfile]"
156
+ exit 0
157
+ ;;
158
+ -D)
159
+ properties="$properties -D$2"
160
+ shift 2
161
+ ;;
162
+ -X)
163
+ properties="$properties -X$2"
164
+ shift 2
165
+ ;;
166
+ --)
167
+ shift
168
+ break
169
+ ;;
170
+ *)
171
+ echo "Error parsing arguments!" >&2
172
+ exit 1
173
+ ;;
174
+ esac
175
+ done
176
+
177
+ # Start up the service
178
+ launch_service "$pidfile" "$foreground" "$properties"
179
+
180
+ exit $?
@@ -0,0 +1,37 @@
1
+ @echo off
2
+
3
+ SETLOCAL
4
+
5
+ if NOT DEFINED JAVA_HOME goto err
6
+
7
+ set SCRIPT_DIR=%~dp0
8
+ for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI
9
+
10
+
11
+ REM ***** JAVA options *****
12
+
13
+ set JAVA_OPTS=^
14
+ -Xms256m^
15
+ -Xmx1G^
16
+ -Djline.enabled=false^
17
+ -XX:+AggressiveOpts^
18
+ -XX:+UseParNewGC^
19
+ -XX:+UseConcMarkSweepGC^
20
+ -XX:+CMSParallelRemarkEnabled^
21
+ -XX:+HeapDumpOnOutOfMemoryError
22
+
23
+ set ES_CLASSPATH=%CLASSPATH%;%ES_HOME%/lib/elasticsearch-0.14.2.jar;%ES_HOME%/lib/*;%ES_HOME%/lib/sigar/*
24
+ set ES_PARAMS=-Delasticsearch -Des-foreground=yes -Des.path.home="%ES_HOME%"
25
+
26
+ "%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Bootstrap"
27
+ goto finally
28
+
29
+
30
+ :err
31
+ echo JAVA_HOME environment variable must be set!
32
+ pause
33
+
34
+
35
+ :finally
36
+
37
+ ENDLOCAL