Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/db.py
Show First 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | def origin_intrinsic_metadata_search_fulltext(self, terms, *, limit, | ||||
tsquery_template = ' && '.join("plainto_tsquery('%s', %%s)" % regconfig | tsquery_template = ' && '.join("plainto_tsquery('%s', %%s)" % regconfig | ||||
for _ in terms) | for _ in terms) | ||||
tsquery_args = [(term,) for term in terms] | tsquery_args = [(term,) for term in terms] | ||||
keys = map(self._convert_key, self.origin_intrinsic_metadata_cols) | keys = map(self._convert_key, self.origin_intrinsic_metadata_cols) | ||||
query = ("SELECT {keys} FROM origin_intrinsic_metadata AS oim " | query = ("SELECT {keys} FROM origin_intrinsic_metadata AS oim " | ||||
"INNER JOIN indexer_configuration AS i " | "INNER JOIN indexer_configuration AS i " | ||||
"ON oim.indexer_configuration_id=i.id " | "ON oim.indexer_configuration_id=i.id " | ||||
"JOIN LATERAL (SELECT {tsquery_template}) AS s(tsq) ON true " | "JOIN LATERAL (SELECT {tsquery_template}) AS s(tsq) ON true " | ||||
"WHERE to_tsvector('{regconfig}', metadata) @@ tsq " | "WHERE oim.metadata_tsvector @@ tsq " | ||||
"ORDER BY ts_rank(oim.metadata_tsvector, tsq, 1) DESC " | "ORDER BY ts_rank(oim.metadata_tsvector, tsq, 1) DESC " | ||||
"LIMIT %s;" | "LIMIT %s;" | ||||
).format(keys=', '.join(keys), | ).format(keys=', '.join(keys), | ||||
regconfig=regconfig, | regconfig=regconfig, | ||||
tsquery_template=tsquery_template) | tsquery_template=tsquery_template) | ||||
cur.execute(query, tsquery_args + [limit]) | cur.execute(query, tsquery_args + [limit]) | ||||
yield from cur | yield from cur | ||||
Show All 25 Lines |