blob: d16f5e8fe8d0f84b52d8a6c4b294215a0429f837 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
<?php
namespace SMW\Query;
use SMW\DIWikiPage;
/**
* Record excerpts for query results that support an excerpt retrieval function.
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class Excerpts {
/**
* @var []
*/
protected $excerpts = [];
/**
* @var boolean
*/
protected $noHighlight = false;
/**
* @var boolean
*/
protected $hasHighlight = false;
/**
* @var boolean
*/
protected $stripTags = true;
/**
* @since 3.0
*/
public function noHighlight() {
$this->noHighlight = true;
}
/**
* @note The hash is expected to be equivalent to DIWikiPage::getHash to
* easily match result subjects available in an QueryResult instance.
*
* @since 3.0
*
* @param DIWikiPage|string $hash
* @param string|integer $score
*/
public function addExcerpt( $hash, $excerpt ) {
if ( $hash instanceof DIWikiPage ) {
$hash = $hash->getHash();
}
$this->excerpts[] = [ $hash, $excerpt ];
}
/**
* @since 3.0
*
* @param DIWikiPage|string $hash
*
* @return string|integer|false
*/
public function getExcerpt( $hash ) {
if ( $hash instanceof DIWikiPage ) {
$hash = $hash->getHash();
}
foreach ( $this->excerpts as $map ) {
if ( $map[0] === $hash ) {
return $map[1];
}
}
return false;
}
/**
* @since 3.0
*
* @return []
*/
public function getExcerpts() {
return $this->excerpts;
}
/**
* @since 3.0
*
* @return boolean
*/
public function hasHighlight() {
return $this->hasHighlight;
}
}
|