Skip to content

Commit ce4a1c2

Browse files
committed
[BUGFIX] Explain is not rendred with Apache Solr 8.2
Add's a testcase and the recursive lookup in the rootline for a node with a given fieldname. Fixes: #7
1 parent d3880e0 commit ce4a1c2

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

Classes/Domain/Result/Explanation/Parser.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected function parseChildNodes($contextContent, \ArrayObject $collection, $p
8484
preg_match_all('~((?<=^)|(?<=\n))(?<token>[0-9].*?\n)((?=[0-9])|(?=$))~s',$contextContent,$matches);
8585

8686
if( array_key_exists('token',$matches)) {
87+
8788
foreach($matches['token'] as $tokenKey => $tokenContent) {
8889
$nodeParts = explode(PHP_EOL,$tokenContent);
8990
$nodeContent = trim(array_shift($nodeParts));
@@ -107,8 +108,6 @@ protected function parseChildNodes($contextContent, \ArrayObject $collection, $p
107108
}
108109
}
109110
}
110-
111-
$collection;
112111
}
113112

114113
/**
@@ -175,7 +174,6 @@ protected function getQueryAttribute($content) {
175174
protected function getFieldNameFromNodeName($nodeName) {
176175
$result = '';
177176
$matches = array();
178-
179177
if (mb_strpos($nodeName,'weight(Synonym(') !== false ) {
180178
preg_match('~weight\(Synonym\((?<fieldname>[^\):]*)~', $nodeName, $matches);
181179
} elseif(mb_strpos($nodeName,'weight(') !== false ){

Classes/Domain/Result/Explanation/Visitors/SummarizeFieldImpacts.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class SummarizeFieldImpacts implements ExplainNodeVisitorInterface {
1212

1313
/**
14-
* @var float
14+
* @var array
1515
*/
1616
protected $sums = array();
1717

@@ -22,8 +22,7 @@ class SummarizeFieldImpacts implements ExplainNodeVisitorInterface {
2222
public function visit(Explain $node) {
2323
if($node->getNodeType() == $node::NODE_TYPE_LEAF) {
2424
if($node->getParent() != null) {
25-
$fieldName = $node->getParent()->getFieldName();
26-
25+
$fieldName = $this->getClosestFieldName($node);
2726
if(trim($fieldName) === '') {
2827
return;
2928
}
@@ -38,6 +37,25 @@ public function visit(Explain $node) {
3837
}
3938
}
4039

40+
/**
41+
* Returns the closest fieldname in the parent root line and and empty string when none is present.
42+
*
43+
* @param $node
44+
* @return string
45+
*/
46+
protected function getClosestFieldName($node) {
47+
while(!is_null($node->getParent())) {
48+
$parent = $node->getParent();
49+
if ($parent->getFieldName() !== '') {
50+
return $parent->getFieldName();
51+
}
52+
53+
$node = $parent;
54+
}
55+
56+
return '';
57+
}
58+
4159
/**
4260
* Returns the fieldnames that have been relevant during the explain.
4361
*

Tests/Domain/Result/Explanation/ExplainServiceTestCase.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ public function testCanParseSynonymeNodes() {
6262

6363
$this->assertEquals($expectedResult, $result);
6464
}
65+
66+
/**
67+
* @test
68+
*/
69+
public function testCanParse82Response() {
70+
$content = $this->getFixtureContent('8.2.001.txt');
71+
$result = ExplainService::getFieldImpactsFromRawContent(
72+
$content,
73+
'foo',
74+
'bar'
75+
);
76+
77+
$expectedResult = [
78+
'content' => 85.44380986095436,
79+
'tagsH2H3' => 4.056216176545581,
80+
'title' => 10.499972051284612
81+
];
82+
83+
$this->assertEquals($expectedResult, $result);
84+
}
6585
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
44.474316 = sum of:
2+
44.474316 = max plus 0.5 times others of:
3+
3.6079488 = weight(tagsH2H3:page in 45) [SchemaSimilarity], result of:
4+
3.6079488 = score(freq=1.0), product of:
5+
3.0 = boost
6+
1.6405284 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:
7+
9 = n, number of documents containing term
8+
48 = N, total number of documents with field
9+
0.73308676 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:
10+
1.0 = freq, occurrences of term within document
11+
1.2 = k1, term saturation parameter
12+
0.75 = b, length normalization parameter
13+
1.0 = dl, length of field
14+
14.041667 = avgdl, average length of field
15+
9.3395815 = weight(title:page in 45) [SchemaSimilarity], result of:
16+
9.3395815 = score(freq=1.0), product of:
17+
5.0 = boost
18+
3.2884018 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:
19+
2 = n, number of documents containing term
20+
66 = N, total number of documents with field
21+
0.56803167 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:
22+
1.0 = freq, occurrences of term within document
23+
1.2 = k1, term saturation parameter
24+
0.75 = b, length normalization parameter
25+
1.0 = dl, length of field
26+
1.9545455 = avgdl, average length of field
27+
38.00055 = weight(content:page in 45) [SchemaSimilarity], result of:
28+
38.00055 = score(freq=4.0), product of:
29+
40.0 = boost
30+
1.0761395 = idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:
31+
22 = n, number of documents containing term
32+
65 = N, total number of documents with field
33+
0.882798 = tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:
34+
4.0 = freq, occurrences of term within document
35+
1.2 = k1, term saturation parameter
36+
0.75 = b, length normalization parameter
37+
72.0 = dl, length of field (approximate)
38+
280.46155 = avgdl, average length of field

0 commit comments

Comments
 (0)