From 28352d7bbe15b71f12d49631cfb0602c52e91d73 Mon Sep 17 00:00:00 2001 From: ahmedre Date: Sun, 10 Jul 2016 22:52:41 -0700 Subject: [PATCH 1/6] Fix search documentation regarding query parameter Fix #69. --- app/controllers/v2/search_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 0b581470578229cb7ab317350f8f37417fd5d75d Mon Sep 17 00:00:00 2001 From: Maryam Labib Date: Sun, 17 Jul 2016 19:56:46 -0700 Subject: [PATCH 2/6] Fix typo --- config/elasticsearch/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From e94854011fb351756493e99d158a347d64fa11d3 Mon Sep 17 00:00:00 2001 From: ahmedre Date: Wed, 3 Aug 2016 23:21:24 -0700 Subject: [PATCH 3/6] Update submodule for db --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index 44f5068a..2f1945c9 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 44f5068ac0204a991848e6eb828c91699e6d2b44 +Subproject commit 2f1945c9110aeee854e8ef06f895445b33ed1f89 From 6638e3b4cd39c2db029d47e840c7bc1ecc925dab Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Tue, 16 Aug 2016 21:06:08 -0700 Subject: [PATCH 4/6] Remove oggs since they're now gone from the db (#73) Remove oggs since they're now gone from the db --- app/models/audio/file.rb | 3 +-- app/models/quran/ayah.rb | 8 +++----- db | 2 +- docs/search.md | 13 +++---------- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/app/models/audio/file.rb b/app/models/audio/file.rb index 48b05133..44bfe285 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], include: :reciter) end end diff --git a/app/models/quran/ayah.rb b/app/models/quran/ayah.rb index 7dfad88f..4fbc0d36 100644 --- a/app/models/quran/ayah.rb +++ b/app/models/quran/ayah.rb @@ -109,11 +109,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/db b/db index 2f1945c9..f1572602 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 2f1945c9110aeee854e8ef06f895445b33ed1f89 +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" } } }, From e892043188699c4425115f1b8b3b50140a48ee8b Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Sun, 21 Aug 2016 22:00:56 -0700 Subject: [PATCH 5/6] Remove unnecessary reciter from audio response (#75) The audio structure in the json was repeated per ayah - this is not necessary (as a matter of fact, it's not needed at all, since the reciter id is already known before making this call). This saves a database query and a very small amount of transfer (4k uncompressed, much less compressed (~100 bytes)). --- app/models/audio/file.rb | 2 +- app/models/quran/ayah.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/audio/file.rb b/app/models/audio/file.rb index 44bfe285..ee9d8647 100644 --- a/app/models/audio/file.rb +++ b/app/models/audio/file.rb @@ -31,6 +31,6 @@ def as_json(options = {}) ayah = ayah_key.split(':')[1] - super(only: [:duration, :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 4fbc0d36..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) From 840a65116bae6a68454f6394a9e049dc708b9548 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Thu, 25 Aug 2016 12:49:43 -0700 Subject: [PATCH 6/6] Don't return font numbers in search api (#76) When we do a search, we also search the fonts - we use the information from these to properly highlight the results. While this is all good, we should not be returning these results back from the api. This patch fixes that by returning a nil from that block, and then compacting the match array in order to remove the nil element before returning. Fixes #63. --- app/models/search/results.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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