diff --git a/app/controllers/v2/search_controller.rb b/app/controllers/v2/search_controller.rb index 9f598d13..1d8e640f 100644 --- a/app/controllers/v2/search_controller.rb +++ b/app/controllers/v2/search_controller.rb @@ -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 diff --git a/app/models/audio/file.rb b/app/models/audio/file.rb index 48b05133..ee9d8647 100644 --- a/app/models/audio/file.rb +++ b/app/models/audio/file.rb @@ -24,7 +24,6 @@ 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 = {}) @@ -32,6 +31,6 @@ def as_json(options = {}) 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 diff --git a/app/models/quran/ayah.rb b/app/models/quran/ayah.rb index 7dfad88f..fbbe57da 100644 --- a/app/models/quran/ayah.rb +++ b/app/models/quran/ayah.rb @@ -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) @@ -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 diff --git a/app/models/search/results.rb b/app/models/search/results.rb index 64613fc3..c3cc1f27 100644 --- a/app/models/search/results.rb +++ b/app/models/search/results.rb @@ -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 diff --git a/config/elasticsearch/README.md b/config/elasticsearch/README.md index 44dafd59..3b17d87c 100644 --- a/config/elasticsearch/README.md +++ b/config/elasticsearch/README.md @@ -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/ @@ -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 ``` @@ -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 diff --git a/db b/db index 44f5068a..f1572602 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 44f5068ac0204a991848e6eb828c91699e6d2b44 +Subproject commit f15726020ae5df5f5990b0c642b7cd547772feb6 diff --git a/docs/search.md b/docs/search.md index 8493e8af..ba79e67a 100644 --- a/docs/search.md +++ b/docs/search.md @@ -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" } } },