def _percolate_query(index, doc_type, percolator_doc_type, document): """Get results for a percolate query.""" index = _build_percolator_index_name(index) if ES_VERSION[0] in (2, 5): results = current_search_client.percolate(index=index, doc_type=doc_type, allow_no_indices=True, ignore_unavailable=True, body={'doc': document}) return results['matches'] elif ES_VERSION[0] in (6, 7): es_client_params = dict(index=index, doc_type=percolator_doc_type, allow_no_indices=True, ignore_unavailable=True, body={ 'query': { 'percolate': { 'field': 'query', 'document_type': percolator_doc_type, 'document': document, } } }) if ES_VERSION[0] == 7: es_client_params.pop('doc_type') results = current_search_client.search(**es_client_params) return results['hits']['hits']
def get_record_sets(record): """Find matching sets.""" # get lists of sets with search_pattern equals to None but already in the # set list inside the record record_sets = set(record.get('_oai', {}).get('sets', [])) for spec in _build_cache(): if spec in record_sets: yield spec # get list of sets that match using percolator index, doc_type = RecordIndexer().record_to_index(record) body = {"doc": record.dumps()} results = current_search_client.percolate(index=index, doc_type=doc_type, allow_no_indices=True, ignore_unavailable=True, body=body) prefix = 'oaiset-' prefix_len = len(prefix) for match in results['matches']: set_name = match['_id'] if set_name.startswith(prefix): name = set_name[prefix_len:] yield name raise StopIteration
def _percolate_query(index, doc_type, percolator_doc_type, document): """Get results for a percolate query.""" if ES_VERSION[0] in (2, 5): results = current_search_client.percolate(index=index, doc_type=doc_type, allow_no_indices=True, ignore_unavailable=True, body={'doc': document}) return results['matches'] elif ES_VERSION[0] == 6: results = current_search_client.search(index=index, doc_type=percolator_doc_type, allow_no_indices=True, ignore_unavailable=True, body={ 'query': { 'percolate': { 'field': 'query', 'document_type': percolator_doc_type, 'document': document, } } }) return results['hits']['hits']
def _percolate_query(index, doc_type, percolator_doc_type, document): """Get results for a percolate query.""" if ES_VERSION[0] in (2, 5): results = current_search_client.percolate( index=index, doc_type=doc_type, allow_no_indices=True, ignore_unavailable=True, body={'doc': document} ) return results['matches'] elif ES_VERSION[0] == 6: results = current_search_client.search( index=index, doc_type=percolator_doc_type, allow_no_indices=True, ignore_unavailable=True, body={ 'query': { 'percolate': { 'field': 'query', 'document_type': percolator_doc_type, 'document': document, } } } ) return results['hits']['hits']
def _find_matching_collections_externally(collections, record): """Find matching collections with percolator engine. :param collections: set of collections where search :param record: record to match """ index, doc_type = RecordIndexer().record_to_index(record) body = {"doc": record.dumps()} results = current_search_client.percolate( index=index, doc_type=doc_type, allow_no_indices=True, ignore_unavailable=True, body=body ) prefix_len = len('collection-') for match in results['matches']: collection_name = match['_id'] if collection_name.startswith('collection-'): name = collection_name[prefix_len:] if name in collections: yield collections[name]['ancestors'] raise StopIteration