def similarity_query(self, query_item, distance_metric='jaccard', threshold = 0.1):

        # Get Candidate Pairs
        candidates = self._min_hash.candidate_query(query_item)

        # Output warning if candidates too high
        n_pairs = len(candidates)
        if (n_pairs > 5000):
            print 'Warning: %d candidates returned from MinHash' % n_pairs

        # Now process all the candidates events pairs and explicity
        # compute similarities based on the specified distance metric
        matches = []
        for target in candidates:

            # Compute Levenshtein Distance between source and target
            if (distance_metric == 'levenshtein'):
                sim = self.l_sim(query_item, self._get_row(target))
                if (sim > threshold):
                    matches.append((sim, target))

            # Compute a Jaccard Distance
            elif (distance_metric == 'jaccard'):
                sim = self.jaccard_sim(query_item, self._get_row(target))
                if (sim > threshold):
                    matches.append((sim, target))

            # Catch unknown distance metric
            else:
                print 'Unknown distance metric', distance_metric
                raise NotImplementedError
        if (n_pairs > 5000):
            print 'LSH: %s matches out of %s candidates (adjust parameters if needed)' % (len(matches), n_pairs)

        # Return the matches list
        return matches
Use Banded LSH to reduce the number of candidates.
dataset/ETHPy150Open ClickSecurity/data_hacking/data_hacking/lsh_sims/lsh_sims.py/LSHSimilarities.similarity_query