Skip to content

Commit

Permalink
Merge pull request #77 from quran/master
Browse files Browse the repository at this point in the history
Merge code into production branch
  • Loading branch information
ahmedre authored Aug 30, 2016
2 parents f51ac08 + 840a651 commit 6e8bf9d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/v2/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class V2::SearchController < ApplicationController

api :GET, '/v2/search', 'Quran search'
api_version '2.0'
param :q, String, desc: 'Query string to search', requred: true
param :q, String, desc: 'Query string to search', required: true
param :page, :number, desc: 'Page number'
param :size, :number, desc: 'Size of results per page'
def index
Expand Down
3 changes: 1 addition & 2 deletions app/models/audio/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ class Audio::File < ActiveRecord::Base
belongs_to :recitation, class_name: 'Audio::Recitation'
has_one :reciter, class_name: 'Audio::Reciter', through: :recitation

scope :ogg, -> { where(format: 'ogg') }
scope :mp3, -> { where(format: 'mp3') }

def as_json(options = {})
surah = ayah_key.split(':')[0]
ayah = ayah_key.split(':')[1]


super(only: [:reciter_id, :format, :duration, :mime_type, :url, :encrypted_segments], include: :reciter)
super(only: [:duration, :url, :encrypted_segments])
end
end
9 changes: 3 additions & 6 deletions app/models/quran/ayah.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def self.as_json_with_resources(ayahs, options = {})
if audio_option = options[:audio]
audio =
Audio::File
.preload(:reciter)
.where(ayah_key: keys, recitation_id: audio_option, is_enabled: true)
.order(:ayah_key)
.group_by(&:ayah_key)
Expand All @@ -109,11 +108,9 @@ def self.as_json_with_resources(ayahs, options = {})
ayahs.map do |ayah|
ayah_json = ayah.as_json
ayah_json.merge({
content: content_option && content[ayah.ayah_key] ? content[ayah.ayah_key] : [],
audio: audio_option ? {
ogg: audio[ayah.ayah_key].find{ |file| file['format'] == 'ogg'},
mp3: audio[ayah.ayah_key].find{ |file| file['format'] == 'mp3'}
} : {},
content: content_option && content[ayah.ayah_key] ?
content[ayah.ayah_key] : [],
audio: audio_option ? audio[ayah.ayah_key].first : {},
})
end
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/search/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ def aggregation_records
ayah_result[:ayah][:words].find{|word| word['word_id'] == id.to_i}[:highlight] = word_id_array.first
end
end
nil
else
hash
end

hash
end

ayah_result.merge!(match: match)
ayah_result.merge!(match: match.compact)

ayah_result
end
Expand Down
8 changes: 4 additions & 4 deletions config/elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#### Installation
Install via Homebrew
`brewi install elasticsearch`. You will then be prompted with this info:
`brew install elasticsearch`. You will then be prompted with this info:
```
==> Caveats
Data: /usr/local/var/elasticsearch/elasticsearch_mmahalwy/
Expand Down Expand Up @@ -31,14 +31,14 @@ Github: https://github.com/mobz/elasticsearch-head
To run: Open in browser http://localhost:9200/_plugin/head/

#### Starting
To run elasticsearch, in bash paste: Note: If you brew installed, this is done automatically
To run elasticsearch, in bash paste: (If you brew installed, this is done automatically)

```
elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
```

#### Setup
copy the 'analysis/' subfolder into your elasticsearch directory (typically /opt/elasticsearch-1.6.0, for example, or /usr/share/elasticsearch), as 'config/analysis'
Copy the 'analysis/' subfolder into your elasticsearch directory (typically /opt/elasticsearch-1.6.0, for example, or /usr/share/elasticsearch), as 'config/analysis'

#### Indices
```
Expand Down Expand Up @@ -70,7 +70,7 @@ View mappings: in browser - `http://localhost:9200/quran/_mapping`
client.indices.put_mapping index: 'quran', type: 'translation', body: { translation: { _parent: { type: 'ayah' }, _routing: { required: true, path: 'ayah_key' }, properties: { text: { type: 'string', term_vector: 'with_positions_offsets_payloads' } } } }
```

**Note**: you will run into the problem of not having the arabic_synonyms.txt file in the proper location for elasticsearch. That's fine. The file is located in the public directory and should be placed in `/etc/elasticsearch/analysis` on your server.
**Note**: You will run into the problem of not having the arabic_synonyms.txt file in the proper location for elasticsearch. That's fine. The file is located in the public directory and should be placed in `/etc/elasticsearch/analysis` on your server.

#### Querying

Expand Down
2 changes: 1 addition & 1 deletion db
Submodule db updated from 44f506 to f15726
13 changes: 3 additions & 10 deletions docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,9 @@ GET /search?content=17,18&audio=1&q=allah%20light
}
],
"audio": {
"ogg": {
"url": "http://audio.quran.com:9999/AbdulBaset/Mujawwad/ogg/024035.ogg",
"duration": 174.956,
"mime_type": "audio/ogg"
},
"mp3": {
"url": "http://audio.quran.com:9999/AbdulBaset/Mujawwad/mp3/024035.mp3",
"duration": 174.99,
"mime_type": "audio/mpeg"
}
"url": "http://audio.quran.com:9999/AbdulBaset/Mujawwad/mp3/024035.mp3",
"duration": 174.99,
"mime_type": "audio/mpeg"
}
}
},
Expand Down

0 comments on commit 6e8bf9d

Please sign in to comment.