Esempio n. 1
0
    def __generate_conreq_rank(self, result, clean_query):
        """Determines string similarity and combined with a weight of the original rank"""
        try:
            clean_title = clean_string(result["title"])

            # Multiplier if whole substring was found within the search result
            if clean_title.find(clean_query) != -1:
                query_substring_multiplier = 0.1
            else:
                query_substring_multiplier = 1

            # Generate similarity rank
            result["conreqSimilarityRank"] = (
                # Round the values to look pretty
                self.__round(
                    # String similarity between the query and result
                    (
                        self.__damerau.distance(clean_query, clean_title)
                        # Use sonarr/radarr's original rank as a weight/bias
                        * (result["arrOriginalRank"] / 10))
                    # Bias towards full substring matches
                    * query_substring_multiplier) + 1)

        except:
            log.handler("Failed to generate conreq rank!", log.ERROR, _logger)
            try:
                result["conreqSimilarityRank"] = result["arrOriginalRank"]
            except:
                result["conreqSimilarityRank"] = 1
Esempio n. 2
0
def generate_cache_key(cache_name, cache_args, cache_kwargs, key):
    """Generates a key to be used with django caching"""
    return clean_string(
        cache_name
        + "_args"
        + str(cache_args)
        + "_kwargs"
        + str(cache_kwargs)
        + "_key"
        + str(key)
    )
Esempio n. 3
0
    def __set_conreq_rank(self, query, results):
        # Determine string similarity and combined with a weight of the original rank
        clean_query = clean_string(query)
        thread_list = []
        for result in results:
            thread = Thread(target=self.__generate_conreq_rank,
                            args=[result, clean_query])
            thread.start()
            thread_list.append(thread)

        # Wait for computation to complete
        for thread in thread_list:
            thread.join()

        # Sort them by the new ranking metric
        return sorted(results, key=lambda i: i["conreqSimilarityRank"])