def test_hashing(read_asset, config_injector): config_injector({ 'elasticsearch': { 'host': 'localhost', 'port': 9200, 'index': 'szurubooru_test', }, }) image_hash.purge() image_hash.add_image('test', read_asset('jpeg.jpg')) paths = image_hash.get_all_paths() results_exact = image_hash.search_by_image(read_asset('jpeg.jpg')) results_similar = image_hash.search_by_image( read_asset('jpeg-similar.jpg')) assert len(paths) == 1 assert len(results_exact) == 1 assert len(results_similar) == 1 assert results_exact[0].path == 'test' assert results_exact[0].score == 63 assert results_exact[0].distance == 0 assert results_similar[0].path == 'test' assert results_similar[0].score == 17 assert abs(results_similar[0].distance - 0.20599895341812172) < 1e-8
def test_hashing(read_asset, config_injector): config_injector({ 'elasticsearch': { 'host': 'localhost', 'port': 9200, 'index': 'szurubooru_test', 'user': '******', 'pass': None, }, }) if not image_hash.get_session().ping(): pytest.xfail('Unable to connect to ElasticSearch, ' 'perhaps it is not available for this test?') image_hash.purge() image_hash.add_image('test', read_asset('jpeg.jpg')) paths = image_hash.get_all_paths() results_exact = image_hash.search_by_image(read_asset('jpeg.jpg')) results_similar = image_hash.search_by_image( read_asset('jpeg-similar.jpg')) assert len(paths) == 1 assert len(results_exact) == 1 assert len(results_similar) == 1 assert results_exact[0].path == 'test' assert results_exact[0].score == 63 assert results_exact[0].distance == 0 assert results_similar[0].path == 'test' assert results_similar[0].score == 17 assert abs(results_similar[0].distance - 0.20599895341812172) < 1e-8
def populate_reverse_search() -> None: excluded_post_ids = image_hash.get_all_paths() post_ids_to_hash = (db.session.query(model.Post.post_id).filter( (model.Post.type == model.Post.TYPE_IMAGE) | (model.Post.type == model.Post.TYPE_ANIMATION)).filter( ~model.Post.post_id.in_(excluded_post_ids)).order_by( model.Post.post_id.asc()).all()) for post_ids_chunk in util.chunks(post_ids_to_hash, 100): posts_chunk = (db.session.query(model.Post).filter( model.Post.post_id.in_(post_ids_chunk)).all()) for post in posts_chunk: content_path = get_post_content_path(post) if files.has(content_path): image_hash.add_image(post.post_id, files.get(content_path))
def populate_reverse_search(): excluded_post_ids = image_hash.get_all_paths() post_ids_to_hash = (db.session .query(db.Post.post_id) .filter( (db.Post.type == db.Post.TYPE_IMAGE) | (db.Post.type == db.Post.TYPE_ANIMATION)) .filter(~db.Post.post_id.in_(excluded_post_ids)) .order_by(db.Post.post_id.asc()) .all()) for post_ids_chunk in util.chunks(post_ids_to_hash, 100): posts_chunk = (db.session .query(db.Post) .filter(db.Post.post_id.in_(post_ids_chunk)) .all()) for post in posts_chunk: content_path = get_post_content_path(post) if files.has(content_path): image_hash.add_image(post.post_id, files.get(content_path))