Skip to content

Commit

Permalink
Merge pull request #69 from abdrmdn/always-bring-results
Browse files Browse the repository at this point in the history
Always bring results, improved the search tremendously and added title to search
  • Loading branch information
abidulrmdn authored Mar 24, 2017
2 parents 381734f + 4815c0d commit 989bc2c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
81 changes: 51 additions & 30 deletions y2bsearch/app/Src/SearchService/SearchProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,64 @@ public function generateTopSearchQuery()

public function generateSearchQuery($searchKeywords)
{
$searchKeywords = explode(' ', $searchKeywords);
//Taking half the number of keywords as a must match criteria
$minimumMatch = (int)ceil(count($searchKeywords) / 2);
$nestedQuery = [
'must' => [
"nested" => [
'path' => "subtitles",
'inner_hits' => [
'highlight' => [
'pre_tags' => ['<b>'],
'post_tags' => ['</b>'],
"order" => "score",
'fields' => [
"subtitles.sentence" => [
"fragment_size" => 300,
"number_of_fragments" => 100,
],
],
],
],
'query' => [
'bool' => [
'minimum_should_match' => $minimumMatch,
'should' => [],
'boost' => 2,
],
],
],
],
];
$titleQuery = [
'minimum_should_match' => $minimumMatch,
'boost' => 0.5,
'should' => [],
];
foreach ($searchKeywords as $keyword) {
$nestedQuery['must']['nested']['query']['bool']['should'][] = [
'term' => [
'subtitles.sentence' => $keyword,
],
];
$titleQuery['should'][] = [
'term' => [
'video_title' => $keyword,
],
];
}
$params = [
'index' => 'videos_en',
'type' => 'videosSubtitles',
'body' => [
'size' => 9,
'query' => [
'bool' => [
'must' => [
"nested" => [
'path' => "subtitles",
'inner_hits' => [
'highlight' => [
'pre_tags' => ['<b>'],
'post_tags' => ['</b>'],
"order" => "score",
'fields' => [
"subtitles.sentence" => [
"fragment_size" => 300,
"number_of_fragments" => 100,
],
],
],
],
'query' => [
'bool' => [
'must' => [],
],
],
],
'minimum_should_match' => 1, // either tilte or nested
'should' => [
['bool' => $nestedQuery],
['bool' => $titleQuery],
],
],
],
Expand All @@ -79,14 +108,6 @@ public function generateSearchQuery($searchKeywords)
],
],
];
$searchKeywords = explode(' ', $searchKeywords);
foreach ($searchKeywords as $keyword) {
$params['body']['query']['bool']['must']['nested']['query']['bool']['must'][] = [
'term' => [
'subtitles.sentence' => $keyword,
],
];
}

return $params;
}
Expand Down
1 change: 0 additions & 1 deletion y2bsearch/tests/SubtitleAnalyzer/SubtitleAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class SubtitleAnalyzerTest extends \PHPUnit_Framework_TestCase
{

/**
* @test
* @dataProvider ProvideSubtitles
*
* @param $searchTerm
Expand Down

0 comments on commit 989bc2c

Please sign in to comment.