Commit 5508a0eb authored by sim's avatar sim

Use indexed fulltext search in notebook

parent bd3416e8
...@@ -15,7 +15,7 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gargantext.settings') ...@@ -15,7 +15,7 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gargantext.settings')
django.setup() django.setup()
from gargantext.constants import QUERY_SIZE_N_MAX, get_resource, get_resource_by_name from gargantext.constants import QUERY_SIZE_N_MAX, get_resource, get_resource_by_name
from gargantext.models import ProjectNode, DocumentNode from gargantext.models import Node, ProjectNode, DocumentNode
from gargantext.util.db import session, get_engine from gargantext.util.db import session, get_engine
from collections import Counter from collections import Counter
import importlib import importlib
...@@ -53,15 +53,11 @@ def scan_hal(request): ...@@ -53,15 +53,11 @@ def scan_hal(request):
return hal.scan_results(request) return hal.scan_results(request)
def scan_gargantext(corpus_id, lang, request): def scan_gargantext(corpus_id, request):
connection = get_engine().connect() return (session.query(DocumentNode)
# TODO add some sugar the request (ideally request should be the same for hal and garg) .filter_by(parent_id=corpus_id)
query = """select count(n.id) from nodes n .filter(Node.title_abstract.match(request))
where to_tsvector('%s', hyperdata ->> 'abstract' || 'title') .count())
@@ to_tsquery('%s')
AND n.parent_id = %s;""" % (lang, request, corpus_id)
return [i for i in connection.execute(query)][0][0]
connection.close()
def myProject_fromUrl(url): def myProject_fromUrl(url):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment