Skip to content

Commit c42ebf9

Browse files
検索調整
1 parent 235b89e commit c42ebf9

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Frontend/related-viewer.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
(($parent === false || $parent->IsRoot()) ? '' : ' ' . NotBlankText([$parent->title, basename($parent->path)]) );
4848

4949
$titleSuggestions = SearchEngine\Searcher::Search($titleQuery);
50-
50+
// Debug::Log($titleSuggestions);
5151
// score 0.5 未満 は除外
5252
foreach($titleSuggestions as $i => $suggestion){
5353
if($suggestion['score'] < 0.5){
@@ -83,9 +83,18 @@
8383
// }
8484
// $uniqueKeys[$suggestion['id']] = true;
8585
// }
86-
87-
$titleSuggestions = SelectDifferentDirectoryContents($titleSuggestions, $currentContent->path);
88-
$tagSuggestions = SelectDifferentDirectoryContents($tagSuggestions, $currentContent->path);
86+
$childPathList = [];
87+
if($parent !== false){
88+
$childCount = $parent->ChildCount();
89+
for($i = 0; $i < $childCount; $i++){
90+
if(($child = $parent->Child($i)) !== false){
91+
$childPathList[] = $child->path;
92+
}
93+
}
94+
}
95+
// Debug::Log($childPathList);
96+
$titleSuggestions = SelectDifferentDirectoryContents($titleSuggestions, $currentContent->path, $childPathList);
97+
$tagSuggestions = SelectDifferentDirectoryContents($tagSuggestions, $currentContent->path, $childPathList);
8998

9099
// End 関連コンテンツの検索 =================================================
91100

@@ -198,11 +207,17 @@ function CountSteps($pathFrom, $pathTo){
198207
return $steps;
199208
}
200209

201-
function SelectDifferentDirectoryContents($suggestions, $currentContentPath){
210+
function SelectDifferentDirectoryContents($suggestions, $currentContentPath, $childPathList){
202211
foreach($suggestions as $i => $suggestion){
212+
if(in_array($suggestion['id'], $childPathList)){
213+
unset($suggestions[$i]);
214+
continue;
215+
}
216+
203217
$steps = CountSteps($suggestion['id'], $currentContentPath);
204218
if($steps !== false && $steps < 4){
205219
unset($suggestions[$i]);
220+
continue;
206221
}
207222
}
208223
return $suggestions;

0 commit comments

Comments
 (0)