# Path: partycrasher/more_like_this.py
# class MoreLikeThis(MoreLikeThisSearcher):
#     """ Class to setup MLT search config. """
#     def __init__(self, index, config):
#         always_remove_fields = [r'^database_id',
#                          r'^buckets',
#                          r'force_bucket',
#                          r'stacktrace\.depth',
#                          r'^date',
#                          r'logdf']
#         filterer = CrashFilter(config.remove_fields+always_remove_fields,
#                                config.keep_fields)
#         rescore_filterer = CrashFilter(config.rescore_remove_fields+always_remove_fields,
#                                config.rescore_keep_fields)
#         super(MoreLikeThis,self).__init__(
#             index=index,
#             max_query_terms=config.max_query_terms,
#             terminate_after=config.terminate_after,
#             min_score=config.min_score,
#             filterer=filterer,
#             rescore_filterer=rescore_filterer,
#             rescore_window_size=config.rescore_window_size,
#             rescore_weight=config.rescore_weight,
#             search_weight=config.search_weight
#             )
# 
# Path: partycrasher/bucket.py
# class Buckets(object):
#     __slots__ = ('_od',)
#     
#     """Proxy for OrderedDict"""
#     def __init__(self, _initial_d=None, **kwargs):
#         self._od = dict()
#         for k, v in kwargs.items():
#             self._od[k] = v
#         if _initial_d is not None:
#             for k, v in _initial_d.items():
#                 self._od[k] = v
#         #self._od = OrderedDict(sorted(self._od))
#         
#     def __getattr__(self, a):
#         return getattr(self._od, a)
# 
#     def __setitem__(self, k, v):
#         if k == 'top_match':
#             if not (isinstance(v, TopMatch) or v is None):
#                 v = TopMatch(v)
#         else:
#             if not isinstance(k, Threshold):
#                 k = Threshold(k)
#             if not (isinstance(v, Bucket) or v is None):
#                 v = Bucket(v)
#             if v is not None:
#                 assert v['threshold'] == k
#         return self._od.__setitem__(k, v)
# 
#     def __getitem__(self, k):
#         return self._od.__getitem__(k)
# 
#     def __delitem__(self, k):
#         return self._od.__delitem__(k)
# 
#     def __eq__(self, other):
#         if isinstance(other, Buckets):
#             return self._od.__eq__(other._od)
#         else:
#             return self._od.__eq__(other)
# 
#     def __copy__(self):
#         new = Buckets()
#         new._od = self._od.__copy__()
#         return new
#     
#     def keys(self):
#         return self._od.keys()
# 
#     def iterkeys(self):
#         return self._od.iterkeys()
# 
#     def __iter__(self):
#         return self._od.__iter__()
#     
#     def __deepcopy__(self, memo):
#         for k, v in self._od.items():
#             assert not isinstance(k, Decimal)
#             assert not isinstance(v, Decimal)
#         new = self.__class__()
#         new._od = deepcopy(self._od, memo)
#         for k, v in new._od.items():
#             assert not isinstance(k, Decimal)
#             assert not isinstance(v, Decimal)
#         return new
# 
#     def jsonify(self):
#         d = OrderedDict()
#         for k, v in self._od.items():
#             k = text_type(k)
#             d[k] = v
#         return d
# 
#     def create(self):
#         for k, v in self._od.items():
#             if isinstance(k, Threshold):
#                 if v is None:
#                     self[k] = Bucket.new(k)


from partycrasher.more_like_this import MoreLikeThis
from partycrasher.bucket import Buckets
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


class Strategy(object):
    def __init__(self, config, index):
        self.config = config
        self.index = index
    
    def query(self, crash, explain):
        return self.searcher.query(crash, explain)
    
    def matching_buckets(self, *args, **kwargs):
        raise NotImplementedError() 

class MLT(Strategy):
    def __init__(self, *args, **kwargs):
        super(MLT, self).__init__(*args, **kwargs)
        self.searcher = MoreLikeThis(config=self.config, index=self.index)
        self.max_top_match_score = 0
        self.total_top_match_scores = 0
        self.total_matches = 0
    
    def matching_buckets(self, thresholds, search_result):
        matching_buckets = Buckets()
        if len(search_result.hits) > 0:
            similarity = search_result.top_match.score

# Path: partycrasher/more_like_this.py
# class MoreLikeThis(MoreLikeThisSearcher):
#     """ Class to setup MLT search config. """
#     def __init__(self, index, config):
#         always_remove_fields = [r'^database_id',
#                          r'^buckets',
#                          r'force_bucket',
#                          r'stacktrace\.depth',
#                          r'^date',
#                          r'logdf']
#         filterer = CrashFilter(config.remove_fields+always_remove_fields,
#                                config.keep_fields)
#         rescore_filterer = CrashFilter(config.rescore_remove_fields+always_remove_fields,
#                                config.rescore_keep_fields)
#         super(MoreLikeThis,self).__init__(
#             index=index,
#             max_query_terms=config.max_query_terms,
#             terminate_after=config.terminate_after,
#             min_score=config.min_score,
#             filterer=filterer,
#             rescore_filterer=rescore_filterer,
#             rescore_window_size=config.rescore_window_size,
#             rescore_weight=config.rescore_weight,
#             search_weight=config.search_weight
#             )
# 
# Path: partycrasher/bucket.py
# class Buckets(object):
#     __slots__ = ('_od',)
#     
#     """Proxy for OrderedDict"""
#     def __init__(self, _initial_d=None, **kwargs):
#         self._od = dict()
#         for k, v in kwargs.items():
#             self._od[k] = v
#         if _initial_d is not None:
#             for k, v in _initial_d.items():
#                 self._od[k] = v
#         #self._od = OrderedDict(sorted(self._od))
#         
#     def __getattr__(self, a):
#         return getattr(self._od, a)
# 
#     def __setitem__(self, k, v):
#         if k == 'top_match':
#             if not (isinstance(v, TopMatch) or v is None):
#                 v = TopMatch(v)
#         else:
#             if not isinstance(k, Threshold):
#                 k = Threshold(k)
#             if not (isinstance(v, Bucket) or v is None):
#                 v = Bucket(v)
#             if v is not None:
#                 assert v['threshold'] == k
#         return self._od.__setitem__(k, v)
# 
#     def __getitem__(self, k):
#         return self._od.__getitem__(k)
# 
#     def __delitem__(self, k):
#         return self._od.__delitem__(k)
# 
#     def __eq__(self, other):
#         if isinstance(other, Buckets):
#             return self._od.__eq__(other._od)
#         else:
#             return self._od.__eq__(other)
# 
#     def __copy__(self):
#         new = Buckets()
#         new._od = self._od.__copy__()
#         return new
#     
#     def keys(self):
#         return self._od.keys()
# 
#     def iterkeys(self):
#         return self._od.iterkeys()
# 
#     def __iter__(self):
#         return self._od.__iter__()
#     
#     def __deepcopy__(self, memo):
#         for k, v in self._od.items():
#             assert not isinstance(k, Decimal)
#             assert not isinstance(v, Decimal)
#         new = self.__class__()
#         new._od = deepcopy(self._od, memo)
#         for k, v in new._od.items():
#             assert not isinstance(k, Decimal)
#             assert not isinstance(v, Decimal)
#         return new
# 
#     def jsonify(self):
#         d = OrderedDict()
#         for k, v in self._od.items():
#             k = text_type(k)
#             d[k] = v
#         return d
# 
#     def create(self):
#         for k, v in self._od.items():
#             if isinstance(k, Threshold):
#                 if v is None:
#                     self[k] = Bucket.new(k)


# Path: partycrasher/strategy.py
from partycrasher.more_like_this import MoreLikeThis
from partycrasher.bucket import Buckets

#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


class Strategy(object):
    def __init__(self, config, index):
        self.config = config
        self.index = index
    
    def query(self, crash, explain):
        return self.searcher.query(crash, explain)
    
    def matching_buckets(self, *args, **kwargs):
        raise NotImplementedError() 

class MLT(Strategy):
    def __init__(self, *args, **kwargs):
        super(MLT, self).__init__(*args, **kwargs)
        self.searcher = MoreLikeThis(config=self.config, index=self.index)
        self.max_top_match_score = 0
        self.total_top_match_scores = 0
        self.total_matches = 0
    
    def matching_buckets(self, thresholds, search_result):
        matching_buckets = Buckets()
        if len(search_result.hits) > 0:
            similarity = search_result.top_match.score

            thresholds = sorted(thresholds)