Skip to content

Commit bf0cc29

Browse files
author
Jordan Hall
committed
Correct relevance calculation code and added time
1 parent 05b3f09 commit bf0cc29

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Search.php

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ private function buildSearchTerms($term) {
102102

103103
public function query($term, $limit = PHP_INT_MAX) {
104104

105+
$startMicrotime = microtime(true);
106+
105107
$this->sanityCheck();
106108

107109
$terms = $this->buildSearchTerms($term);
@@ -178,6 +180,7 @@ public function query($term, $limit = PHP_INT_MAX) {
178180
}
179181

180182
$searchResults->calculateRelevances();
183+
$searchResults->time = microtime(true) - $startMicrotime;
181184

182185
return $searchResults;
183186

src/SearchResults.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ class SearchResults {
1010
public $highestRelevance = null;
1111
public $lowestRelevance = null;
1212
public $averageRelevance = null;
13+
public $time = null;
1314

1415
public function addSearchResult(SearchResult $searchResult) {
1516
$this->results[] = $searchResult;
1617
}
1718

1819
public function calculateRelevances() {
1920

20-
if (!$results) {
21+
if (!$this->results) {
2122
return;
2223
}
2324

@@ -26,7 +27,7 @@ public function calculateRelevances() {
2627

2728
$relevances = [];
2829

29-
foreach($results as $result) {
30+
foreach($this->results as $result) {
3031
if ($result->relevance < $this->lowestRelevance) {
3132
$this->lowestRelevance = $result->relevance;
3233
}

0 commit comments

Comments
 (0)