mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Fix Solr Date Ranges
This commit is contained in:
parent
432df3fe8b
commit
88fe07c878
@ -160,21 +160,8 @@ class ZendLucenceDriver extends AbstractDriver
|
||||
}
|
||||
|
||||
if (!empty($request->dateFrom) || !empty($request->dateTo)) {
|
||||
if (str_contains(get_called_class(), 'Solr')) {
|
||||
$dateFrom = empty($request->dateFrom)
|
||||
? new Term('*', 'created_at')
|
||||
: new Term('"' . $request->dateFrom . ' 00:00:00"', 'created_at');
|
||||
$dateTo = empty($request->dateTo)
|
||||
? new Term('*', 'created_at')
|
||||
: new Term('"' . $request->dateTo . ' 23:59:59"', 'created_at');
|
||||
} else {
|
||||
$dateFrom = empty($request->dateFrom)
|
||||
? null
|
||||
: new Term($request->dateFrom . ' 00:00:00', 'created_at');
|
||||
$dateTo = empty($request->dateTo)
|
||||
? null
|
||||
: new Term($request->dateTo . ' 23:59:59', 'created_at');
|
||||
}
|
||||
$dateFrom = $this->convertRangeValue('created_at', $request->dateFrom, ' 00:00:00');
|
||||
$dateTo = $this->convertRangeValue('created_at', $request->dateTo, ' 23:59:59');
|
||||
$query->addSubquery(new Range($dateFrom, $dateTo, true), true);
|
||||
}
|
||||
|
||||
@ -213,6 +200,21 @@ class ZendLucenceDriver extends AbstractDriver
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZendLucene and Solr sometimes require a different format here.
|
||||
* e.g. Sol needs a "*" instead of "null" and quoted dates with time
|
||||
*
|
||||
* @param string $field
|
||||
* @param string|null $value
|
||||
* @param string $suffix
|
||||
* @return Term|null
|
||||
*/
|
||||
protected function convertRangeValue(string $field, ?string $value, string $suffix = ''): ?Term
|
||||
{
|
||||
return empty($value) ? null : new Term($value . $suffix, $field);
|
||||
}
|
||||
|
||||
|
||||
private function getIndex(): Index
|
||||
{
|
||||
if ($this->_index) {
|
||||
|
@ -65,15 +65,14 @@ abstract class AbstractDriverTestSuite extends HumHubDbTestCase
|
||||
$space = Space::findOne(['id' => 1]);
|
||||
$this->becomeUser('Admin');
|
||||
(new Post($space, Content::VISIBILITY_PUBLIC, ['message' => 'Some Other']))->save();
|
||||
(new Post($space, Content::VISIBILITY_PUBLIC, ['message' => 'Marabru Leav Test X']))->save();
|
||||
(new Post($space, Content::VISIBILITY_PUBLIC, ['message' => 'Marabru Leav Y Test X']))->save();
|
||||
|
||||
// Short keywords
|
||||
$this->assertEquals(0, count($this->getSearchResultByKeyword('R')->results));
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('T')->results));
|
||||
if ($this->searchDriver instanceof ZendLucenceDriver) {
|
||||
// MysqlDriver can find only at least 2 char exist after "X"
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('X')->results));
|
||||
}
|
||||
|
||||
// Most search indexes do not index individual letters.
|
||||
|
||||
}
|
||||
|
||||
private function getSearchRequest(): SearchRequest
|
||||
|
Loading…
x
Reference in New Issue
Block a user