Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
284
Merge Requests
39
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
500115cd
Commit
500115cd
authored
5 hours ago
by
Mark Harding
Committed by
Mark Harding
4 hours ago
Browse files
Options
Download
(feat): improve new top feeds to work with channels and groups
parent
f81ca6ec
chore/improve-new-top-feeds-for-channels
No related merge requests found
Pipeline
#102255313
passed with stages
in 7 minutes and 56 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
35 deletions
+111
-35
Controllers/Cli/Top/All.php
View file @
500115cd
...
...
@@ -154,7 +154,7 @@ class All extends Cli\Controller implements Interfaces\CliControllerInterface
$this
->
out
(
sprintf
(
"%s -> %s"
,
date
(
'r'
,
$from
),
date
(
'r'
,
$to
)
,
date
(
'r'
,
$to
)
));
$this
->
out
(
"Syncing
{
$displayType
}
/
{
$metric
}
"
);
...
...
This diff is collapsed.
Core/Feeds/Elastic/Repository.php
View file @
500115cd
...
...
@@ -250,6 +250,16 @@ class Repository
];
}
if
(
$type
===
'group'
)
{
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
][]
=
[
'range'
=>
[
'access_id'
=>
[
'gt'
=>
2
,
]
]
];
}
// Time bounds
$timestampUpperBounds
=
[];
// LTE
...
...
@@ -386,6 +396,10 @@ class Repository
$esType
=
$opts
[
'type'
];
if
(
$type
===
'user'
||
$type
===
'group'
)
{
$esType
=
'activity,object:image,object:video,object:blog'
;
}
if
(
$esType
===
'all'
)
{
$esType
=
'object:image,object:video,object:blog'
;
}
...
...
@@ -416,9 +430,31 @@ class Repository
]);
}
}
$docs
=
$response
[
'hits'
][
'hits'
];
// Sort channels / groups by post scores
if
(
$type
===
'user'
||
$type
===
'group'
)
{
$newDocs
=
[];
// New array so we return only users and groups, not posts
foreach
(
$docs
as
$doc
)
{
$key
=
$doc
[
'_source'
][
$this
->
getSourceField
(
$type
)];
$newDocs
[
$key
]
=
$newDocs
[
$key
]
??
[
'_source'
=>
[
'guid'
=>
$key
,
'owner_guid'
=>
$key
,
$this
->
getSourceField
(
$type
)
=>
$key
,
'@timestamp'
=>
$doc
[
'_source'
][
'@timestamp'
],
],
'_type'
=>
$type
,
'_score'
=>
0
,
];
$newDocs
[
$key
][
'_score'
]
=
log10
(
$newDocs
[
$key
][
'_score'
]
+
$algorithm
->
fetchScore
(
$doc
));
}
$docs
=
$newDocs
;
}
$guids
=
[];
foreach
(
$
response
[
'hits'
][
'hits'
]
as
$doc
)
{
foreach
(
$
docs
as
$doc
)
{
$guid
=
$doc
[
'_source'
][
$this
->
getSourceField
(
$opts
[
'type'
])];
if
(
isset
(
$guids
[
$guid
]))
{
continue
;
...
...
@@ -436,12 +472,12 @@ class Repository
private
function
getSourceField
(
string
$type
)
{
switch
(
$type
)
{
//
case 'user':
//
return 'owner_guid';
//
break;
//
case 'group':
//
return 'container_guid';
//
break;
case
'user'
:
return
'owner_guid'
;
break
;
case
'group'
:
return
'container_guid'
;
break
;
default
:
return
'guid'
;
break
;
...
...
This diff is collapsed.
Core/Search/SortingAlgorithms/Hot.php
View file @
500115cd
...
...
@@ -7,10 +7,23 @@
namespace
Minds\Core\Search\SortingAlgorithms
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Features\Manager
as
Features
;
class
Hot
implements
SortingAlgorithm
{
/** @var Features */
protected
$features
;
/** @var string */
protected
$period
;
public
function
__construct
(
$features
=
null
)
{
$this
->
features
=
$features
??
Di
::
_
()
->
get
(
'Features'
);
}
/**
* @return bool
*/
...
...
@@ -25,7 +38,9 @@ class Hot implements SortingAlgorithm
*/
public
function
setPeriod
(
$period
)
{
$this
->
period
=
$period
;
if
(
!
$this
->
features
->
has
(
'top-feeds-by-age'
))
{
$this
->
period
=
$period
;
}
return
$this
;
}
...
...
@@ -34,24 +49,34 @@ class Hot implements SortingAlgorithm
*/
public
function
getQuery
()
{
return
[
'bool'
=>
[
'must'
=>
[
[
'range'
=>
[
"votes:up:
{
$this
->
period
}
:synced"
=>
[
'gte'
=>
strtotime
(
"1 hour ago"
,
time
()),
if
(
$this
->
period
)
{
return
[
'bool'
=>
[
'must'
=>
[
[
'range'
=>
[
"votes:up:
{
$this
->
period
}
:synced"
=>
[
'gte'
=>
strtotime
(
"7 days ago"
,
time
()),
],
],
],
/*'range' => [
"votes:up:{$this->period}" => [
'gte' => 1,
],
],*/
],
],
]
];
]
];
}
return
[
'bool'
=>
[
'must'
=>
[
[
'range'
=>
[
"votes:up"
=>
[
'gte'
=>
1
,
],
],
],
],
]
];
}
/**
...
...
@@ -60,17 +85,32 @@ class Hot implements SortingAlgorithm
public
function
getScript
()
{
$time
=
time
();
if
(
$this
->
period
)
{
return
"
def up = doc['votes:up:
{
$this
->
period
}
'].value ?: 0;
def down = doc['votes:down:
{
$this
->
period
}
'].value ?: 0;
def age =
$time
- (doc['@timestamp'].value.millis / 1000) - 1546300800;
def votes = up - down;
def sign = (votes > 0) ? 1 : (votes < 0 ? -1 : 0);
def order = Math.log(Math.max(Math.abs(votes), 1));
return (sign * order) - (age / 43200);
"
;
}
return
"
def up = doc['votes:up
:
{
$this
->
period
}
'].value ?: 0;
def down = doc['votes:down
:
{
$this
->
period
}
'].value ?: 0;
def up = doc['votes:up'].value ?: 0;
def down = doc['votes:down'].value ?: 0;
def age =
$time
- (doc['@timestamp'].value.millis / 1000) - 15463008
00;
def age =
doc['@timestamp'].value.millis / 10
00;
def votes = up - down;
def sign = (votes > 0) ? 1 : (votes < 0 ? -1 : 0);
def order = Math.log(Math.max(Math.abs(votes), 1));
return (sign * order) - (age / 43200);
// Rounds to 7
return Math.round((sign * order + age / 43200) * 1000000) / 1000000;
"
;
}
...
...
This diff is collapsed.
Spec/Core/Feeds/Elastic/RepositorySpec.php
View file @
500115cd
...
...
@@ -93,7 +93,7 @@ class RepositorySpec extends ObjectBehavior
$this
->
client
->
request
(
Argument
::
that
(
function
(
$query
)
{
$query
=
$query
->
build
();
return
$query
[
'type'
]
===
'
user'
&&
in_array
(
'
guid'
,
$query
[
'body'
][
'_source'
],
true
);
return
$query
[
'type'
]
===
'
activity,object:image,object:video,object:blog'
&&
in_array
(
'owner_
guid'
,
$query
[
'body'
][
'_source'
],
true
);
}))
->
shouldBeCalled
()
->
willReturn
([
...
...
@@ -126,10 +126,10 @@ class RepositorySpec extends ObjectBehavior
$gen
=
$this
->
getList
(
$opts
);
$gen
->
current
()
->
getGuid
()
->
shouldReturn
(
'1'
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
100.0
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
log10
(
100.0
)
);
$gen
->
next
();
$gen
->
current
()
->
getGuid
()
->
shouldReturn
(
'2'
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
50.0
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
log10
(
50.0
)
);
}
public
function
it_should_query_a_list_of_group_guids
()
...
...
@@ -143,7 +143,7 @@ class RepositorySpec extends ObjectBehavior
$this
->
client
->
request
(
Argument
::
that
(
function
(
$query
)
{
$query
=
$query
->
build
();
return
$query
[
'type'
]
===
'
group'
&&
in_array
(
'
guid'
,
$query
[
'body'
][
'_source'
],
true
);
return
$query
[
'type'
]
===
'
activity,object:image,object:video,object:blog'
&&
in_array
(
'container_
guid'
,
$query
[
'body'
][
'_source'
],
true
);
}))
->
shouldBeCalled
()
->
willReturn
([
...
...
@@ -178,10 +178,10 @@ class RepositorySpec extends ObjectBehavior
$gen
=
$this
->
getList
(
$opts
);
$gen
->
current
()
->
getGuid
()
->
shouldReturn
(
'1'
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
100.0
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
log10
(
100
)
);
$gen
->
next
();
$gen
->
current
()
->
getGuid
()
->
shouldReturn
(
'2'
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
50.0
);
$gen
->
current
()
->
getScore
()
->
shouldReturn
(
log10
(
50
)
);
}
// Seems like yielded functions have issues with PHPSpec
...
...
This diff is collapsed.
Please
register
or
sign in
to comment