search_query_parser 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9603da0b877d7fea0467d4faa78080ca7994c70
4
- data.tar.gz: b6e9dc1c95f6b56ab5a7efc749ce54baf5be19b4
3
+ metadata.gz: 5a22c4a198ee6692de837e0af3252257436bf5c7
4
+ data.tar.gz: 3d761b1c78bf1c2be79c1e61f6e4fb4c1c287e15
5
5
  SHA512:
6
- metadata.gz: 70764ba808723f89d94c0c2b2d8b06938ee8e3001357c7ac98aa33e4f2462d8c70e3cb25f70377b99bb693776cbad60c064ecb361a81c1cd6177550bf8bfa0cd
7
- data.tar.gz: 0b4d974c8cf774fe3d612a1268e7e237866182fd2946c1b28033ef972983a1c27d75ff8badbc2dfa377659ae295e1d23a2fbd938b553077b73e8e22a9364449a
6
+ metadata.gz: 7d34b521cd22c1c4a415bc8d2d91999bf3ed92a0d544cf2242610172e599684f88483c8985729d142e6ba74b7c0bc93cc2e799b51208d5f63a90368eeb60e9ee
7
+ data.tar.gz: db7665fa7c4fbd470411afe28cc17426153bc4f366cd813b1d4ea6b1a35acc1b14740d257eb13ded83d6ced1e312fbd26bae9aecb7809b08a554bdcfd2dbcf1a
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.gem
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SearchQueryParser
1
+ # Search Query Parser
2
2
 
3
3
  This gem allows you to create PostgreSQL 9.6 compatible ts_query expressions from simple-to-use "query language".
4
4
 
@@ -9,7 +9,7 @@ See for reference:
9
9
 
10
10
  Example:
11
11
 
12
- ```
12
+ ```ruby
13
13
  require 'search_query_parser'
14
14
 
15
15
  q = SearchQueryParser.to_ts_query("
@@ -34,7 +34,7 @@ When you use PostgreSQL full-text search you want your users to be able to utili
34
34
 
35
35
  Unfortunately, you can't use Postgres' `plain_tosquery` ([link](https://www.postgresql.org/docs/9.6/static/functions-textsearch.html)) function for that, which would be the closest match to our goal. If you give the string `cates & !dogs` to `plainto_tsquery`, the result will be:
36
36
 
37
- ```
37
+ ```sql
38
38
  => select plainto_tsquery('cats & !dogs');
39
39
  plainto_tsquery
40
40
  -----------------
@@ -51,7 +51,7 @@ Use `SearchQueryParser.to_ts_query(q)` to produce PostgreSQL-compatible expressi
51
51
 
52
52
  Use it in your Rails finders for models with `tsdata` columns like that:
53
53
 
54
- ```
54
+ ```ruby
55
55
  q = SearchQueryParser.to_ts_query('кошки & !собаки', 'russian')
56
56
  Document.where("tsdata @@ #{q}")
57
57
  ```
@@ -4,6 +4,10 @@ require "search_query_parser/interpreter"
4
4
  module SearchQueryParser
5
5
  @interpreter = SearchQueryParser::Interpreter.new
6
6
 
7
+ def self.to_string(str)
8
+ @interpreter.parse(str).to_s
9
+ end
10
+
7
11
  def self.to_ts_query(str, language = 'english', prefix = true)
8
12
  language = language.gsub(/[^a-zA-Z\-]/, '')
9
13
  @interpreter.parse(str).reduce do |op, x, y|
@@ -7,8 +7,10 @@ module SearchQueryParser
7
7
  gsub(/[^[:alnum:]\-()&|!]+/, ' ').
8
8
  gsub(/([^[:alnum:]]|^)\-/, '\1').
9
9
  gsub(/\-([^[:alnum:]]|$)/, '\1').
10
- gsub(/ ?([|&!]) /, '\1').
11
- gsub(/ ?([()]) ?/, '\1').
10
+ gsub(/ ?([|&]) ?/, '\1').
11
+ gsub(/(!) /, '\1').
12
+ gsub(/(\() /, '\1').
13
+ gsub(/ (\))/, '\1').
12
14
  strip
13
15
  end
14
16
 
@@ -1,3 +1,3 @@
1
1
  module SearchQueryParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_query_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Zolotarev