Commit d2a9c270 authored by Mark Harding's avatar Mark Harding
Browse files

(feat): fallback to over 1year and include more than just hashtags

parent b579cbda
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,8 @@ class feeds implements Interfaces\Api
        '12h' => '7d',
        '12h' => '7d',
        '24h' => '7d',
        '24h' => '7d',
        '7d' => '30d',
        '7d' => '30d',
        '30d' => '1y'
        '30d' => '1y',
        '1y' => 'all'
    ];
    ];


    /**
    /**
@@ -221,6 +222,7 @@ class feeds implements Interfaces\Api
                $from = $now - $periodsInSecs[$period];
                $from = $now - $periodsInSecs[$period];
                $opts['from_timestamp'] = $from * 1000;
                $opts['from_timestamp'] = $from * 1000;
                $opts['period'] = static::PERIOD_FALLBACK[$period];
                $opts['period'] = static::PERIOD_FALLBACK[$period];
                $opts['limit'] = $limit - $entities->count();


                if (!$fallbackAt) {
                if (!$fallbackAt) {
                    $fallbackAt = $from;
                    $fallbackAt = $from;
+14 −17
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ class Repository
        '7d' => 604800,
        '7d' => 604800,
        '30d' => 2592000,
        '30d' => 2592000,
        '1y' => 31536000,
        '1y' => 31536000,
        'all' => -1,
    ];
    ];


    /** @var ElasticsearchClient */
    /** @var ElasticsearchClient */
@@ -265,7 +266,7 @@ class Repository
        $timestampUpperBounds = []; // LTE
        $timestampUpperBounds = []; // LTE
        $timestampLowerBounds = []; // GT
        $timestampLowerBounds = []; // GT


        if ($algorithm->isTimestampConstrain()) {
        if ($algorithm->isTimestampConstrain() && static::PERIODS[$opts['period']] > -1) {
            $timestampLowerBounds[] = (time() - static::PERIODS[$opts['period']]) * 1000;
            $timestampLowerBounds[] = (time() - static::PERIODS[$opts['period']]) * 1000;
        }
        }


@@ -323,23 +324,19 @@ class Repository
                ];
                ];
            }
            }
        } elseif ($opts['hashtags']) {
        } elseif ($opts['hashtags']) {
            if ($opts['filter_hashtags'] || $algorithm instanceof SortingAlgorithms\Chronological) {
            if (!isset($body['query']['function_score']['query']['bool']['must'])) {
            if (!isset($body['query']['function_score']['query']['bool']['must'])) {
                $body['query']['function_score']['query']['bool']['must'] = [];
                $body['query']['function_score']['query']['bool']['must'] = [];
            }
            }


            $body['query']['function_score']['query']['bool']['must'][] = [
            $body['query']['function_score']['query']['bool']['must'][] = [
                    'terms' => [
                'multi_match' => [
                        'tags' => $opts['hashtags'],
                    'query' => implode(' ', $opts['hashtags']),
                    ],
                    'fields' => ['name^2', 'title^12', 'message^12', 'description^12', 'brief_description^8', 'username^8', 'tags^64'],
                ];
                    'operator' => 'or',
            } else {
                    'minimum_should_match' => 1,
                $body['query']['function_score']['query']['bool']['must'][] = [
                    'terms' => [
                        'tags' => $opts['hashtags'],
                ],
                ],
            ];
            ];
            }
            $body['query']['function_score']['boost_mode'] = 'replace';
        }
        }


        if ($opts['exclude']) {
        if ($opts['exclude']) {