Skip to content

Commit 8d8586f

Browse files
Merge pull request #149 from ContentsViewer/pre
関連ページ調整. タイトルからタグ提示
2 parents 3eb4bd1 + be7d9de commit 8d8586f

File tree

4 files changed

+82
-24
lines changed

4 files changed

+82
-24
lines changed

Client/ContentsViewer/ContentsViewerStandard.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,10 @@ ul.tagline li a:visited {
768768
-webkit-transition: 0.2s;
769769
transition: 0.2s;
770770
}
771-
771+
ul.tagline li.suggested a,
772+
ul.tagline li.suggested a:visited{
773+
opacity: 0.5;
774+
}
772775
ul.tagline li a::before {
773776
position: absolute;
774777
top: 0;
@@ -782,7 +785,6 @@ ul.tagline li a::before {
782785
-webkit-transition: 0.2s;
783786
transition: 0.2s;
784787
}
785-
786788
ul.tagline li a::after {
787789
position: absolute;
788790
top: 50%;
@@ -1997,8 +1999,7 @@ a.directory .name, a.file .name{
19971999
background-color: var(--tag-background-color);
19982000
}
19992001
[theme="dark"] ul.tagline li a:not(:hover)::before {
2000-
border-color: transparent var(--tag-background-color) transparent
2001-
transparent;
2002+
border-color: transparent var(--tag-background-color) transparent transparent;
20022003
}
20032004
[theme="dark"] ul.tag-list > li > a:not(:hover) > span {
20042005
background-color: var(--tag-background-color);

Frontend/contents-viewer.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
$vars['layerName'] = $out['layerName'];
4949
$vars['language'] = $out['language'];
5050
$vars['layerSelector'] = CreateRelatedLayerSelector($contentPath);
51-
51+
$layerSuffix = ContentsDatabaseManager::GetLayerSuffix($vars['layerName']);
5252

5353
// テキストの読み込み
5454
$stopwatch->Start();
@@ -152,12 +152,27 @@
152152

153153
// End navigator 作成 ------------------------------------------------
154154

155-
156155
// メタデータの更新
157156
// contentsChangedTime がここで更新される
158157
ContentsDatabaseManager::RegistMetadata($currentContent);
159158
ContentsDatabase::SaveMetadata($metaFileName);
160159

160+
$suggestedTags = [];
161+
if(SearchEngine\Index::Load(
162+
CONTENTS_HOME_DIR . $vars['rootDirectory'] . '/.index.tagmap' . $layerSuffix
163+
)){
164+
$titleQuery = NotBlankText(
165+
[$currentContent->title, ContentsDatabaseManager::GetContentPathInfo($currentContent->path)['filename']]
166+
);
167+
$suggestions = SearchEngine\Searcher::Search($titleQuery);
168+
foreach($suggestions as $i => $suggested){
169+
if($suggested['score'] < 0.8 || in_array($suggested['id'], $currentContent->tags, true)){
170+
continue;
171+
}
172+
$suggestedTags[] = $suggested['id'];
173+
}
174+
}
175+
161176
// インデックスの読み込み
162177
ContentsDatabaseManager::LoadRelatedIndex($contentPath);
163178

@@ -208,6 +223,7 @@
208223

209224
// tagline の設定
210225
$vars['tagline']['tags'] = $currentContent->tags;
226+
$vars['tagline']['suggestedTags'] = $suggestedTags;
211227

212228
// content summary の設定
213229
$vars['contentSummary'] = $currentContent->summary;

Frontend/related-viewer.php

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,16 @@
3030
$vars['rootContentPath'] = ContentsDatabaseManager::GetRelatedRootFile($vars['contentPath']);
3131
$vars['rootDirectory'] = substr(GetTopDirectory($vars['rootContentPath']), 1);
3232

33-
3433
// ContentsDatabaseManager::LoadRelatedMetadata($vars['rootContentPath']);
3534
// $tag2path = array_key_exists('tag2path', ContentsDatabase::$metadata) ? ContentsDatabase::$metadata['tag2path'] : [];
3635
// $path2tag = array_key_exists('path2tag', ContentsDatabase::$metadata) ? ContentsDatabase::$metadata['path2tag'] : [];
3736
// ksort($tag2path);
3837

39-
4038
// layerの再設定
4139
$out = UpdateLayerNameAndResetLocalization($vars['contentPath'], $vars['layerName'], $vars['language']);
4240
$vars['layerName'] = $out['layerName'];
4341
$vars['language'] = $out['language'];
44-
45-
46-
$indexFilePath = ContentsDatabaseManager::GetRelatedIndexFileName($contentPath);
47-
SearchEngine\Index::Load($indexFilePath);
42+
$layerSuffix = ContentsDatabaseManager::GetLayerSuffix($vars['layerName']);
4843

4944

5045
$parent = $currentContent->Parent();
@@ -59,6 +54,7 @@
5954
}
6055

6156
// === 関連コンテンツの検索 =================================================
57+
$titleTagSuggestions = [];
6258
$titleSuggestions = [];
6359

6460
/**
@@ -68,24 +64,49 @@
6864
* ]
6965
*/
7066
$tagSuggestions = [];
71-
7267
$countSuggestions = 0;
7368

69+
7470
// "<title> <parent.title> で検索
7571
// ただし, parent は rootではない
76-
$titleQuery = NotBlankText(
72+
$title = NotBlankText(
7773
[$currentContent->title, ContentsDatabaseManager::GetContentPathInfo($currentContent->path)['filename']]
7874
);
75+
76+
if(SearchEngine\Index::Load(
77+
CONTENTS_HOME_DIR . $vars['rootDirectory'] . '/.index.tagmap' . $layerSuffix
78+
)){
79+
$suggestions = SearchEngine\Searcher::Search($title);
80+
foreach($suggestions as $i => $suggested){
81+
if($suggested['score'] < 0.8 || in_array($suggested['id'], $currentContent->tags, true)){
82+
continue;
83+
}
84+
$titleTagSuggestions[] = ['tag' => $suggested['id'], 'suggestions' => []];
85+
}
86+
}
87+
88+
SearchEngine\Index::Load(ContentsDatabaseManager::GetRelatedIndexFileName($contentPath));
89+
90+
$titleQuery = $title;
7991
if($parent !== false){
8092
$parentPathInfo = ContentsDatabaseManager::GetContentPathInfo($parent->path);
8193
if($parentPathInfo['filename'] != ROOT_FILE_NAME){
82-
$titleQuery .= ' ' . NotBlankText([$parent->title, $parentPathInfo['filename']]);
94+
$titleQuery = NotBlankText([$parent->title, $parentPathInfo['filename']]) . ' ' . $titleQuery;
8395
}
8496
}
85-
$titleSuggestions = SelectSuggestions(
86-
SearchEngine\Searcher::Search($titleQuery), $currentContent->path, $childPathList, 0.5
87-
);
88-
$countSuggestions += count($titleSuggestions);
97+
if($title !== $titleQuery || count($titleTagSuggestions) <= 0){
98+
$titleSuggestions = SelectSuggestions(
99+
SearchEngine\Searcher::Search($titleQuery), $currentContent->path, $childPathList, 0.5
100+
);
101+
$countSuggestions += count($titleSuggestions);
102+
}
103+
104+
foreach ($titleTagSuggestions as $i => $each) {
105+
$titleTagSuggestions[$i]['suggestions'] = SelectSuggestions(
106+
SearchEngine\Searcher::Search($each['tag']), $currentContent->path, $childPathList
107+
);
108+
$countSuggestions += count($titleTagSuggestions[$i]['suggestions']);
109+
}
89110

90111
// <tag1> <tag2> <tag3> ..."で検索
91112
foreach($currentContent->tags as $tag){
@@ -176,12 +197,19 @@
176197
$body .= '</div>';
177198
}
178199

200+
foreach($titleTagSuggestions as $each){
201+
if(count($each['suggestions']) > 0){
202+
$body .= '<h2>"' . $each['tag'] . '"</h2><div class="section">';
203+
$body .= CreateTagLine($each['tag'], $vars['rootDirectory'], $vars['layerName']);
204+
$body .= CreateSuggestedContentList($each['suggestions']);
205+
$body .= '</div>';
206+
}
207+
}
208+
179209
foreach($tagSuggestions as $each){
180-
if(count($each['suggestions'])){
210+
if(count($each['suggestions']) > 0){
181211
$body .= '<h2>"' . $each['tag'] . '"</h2><div class="section">';
182-
$body .= '<ul class="tagline" style="text-align: right;"><li><a href="' .
183-
CreateTagMapHREF([[$each['tag']]], $vars['rootDirectory'], $vars['layerName']) .
184-
'">' . $each['tag'] . '</a></li></ul>';
212+
$body .= CreateTagLine($each['tag'], $vars['rootDirectory'], $vars['layerName']);
185213
$body .= CreateSuggestedContentList($each['suggestions']);
186214
$body .= '</div>';
187215
}
@@ -299,4 +327,10 @@ function CreateSuggestedContentList($suggestions){
299327
}
300328
$html .= '</ul>';
301329
return $html;
330+
}
331+
332+
function CreateTagLine($tag, $rootDirectory, $layerName){
333+
return '<ul class="tagline" style="text-align: right;"><li><a href="' .
334+
CreateTagMapHREF([[$tag]], $rootDirectory, $layerName) .
335+
'">' . $tag . '</a></li></ul>';
302336
}

Frontend/viewer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* $vars['addEditLink']
2424
* $vars['openNewTabEditLink']
2525
* $vars['fileDate'] = ['createdTime' => '', 'modifiedTime' => '']
26-
* $vars['tagline']['tags']
26+
* $vars['tagline'] = ['tags' => [], 'suggestedTags' => []]
2727
* $vars['tagList']
2828
* $vars['latestContents']
2929
* $vars['leftContent'] = ['title' => '', 'url' => '']
@@ -159,9 +159,16 @@
159159

160160
<?php if (isset($vars['tagline'])): ?>
161161
<ul class="tagline">
162+
<?php if (isset($vars['tagline']['tags'])): ?>
162163
<?php foreach ($vars['tagline']['tags'] as $tag): ?>
163164
<li><a href='<?=CreateTagMapHREF([[$tag]], $vars['rootDirectory'], $vars['layerName'])?>'><?=$tag?></a></li>
164165
<?php endforeach; ?>
166+
<?php endif;?>
167+
<?php if (isset($vars['tagline']['suggestedTags'])): ?>
168+
<?php foreach ($vars['tagline']['suggestedTags'] as $tag): ?>
169+
<li class="suggested"><a href='<?=CreateTagMapHREF([[$tag]], $vars['rootDirectory'], $vars['layerName'])?>'><?=$tag?></a></li>
170+
<?php endforeach; ?>
171+
<?php endif;?>
165172
</ul>
166173
<?php endif;?>
167174

0 commit comments

Comments
 (0)