0

Currently, the system I work on (python 2.7 / django 1.6 / dojo toolkit) has a textual search feature inside .pdf files. It's a heavy search and the return is total: it returns all the records that matched the search only when it finishes browsing all the records.

Exemple.:

views.py

def search_document(request):
    """check permission and logic to show the grid """
    
    varis = {
        'url2': request.app_root + 'mod/document',
        'url': request.app_root + 'mod/search-document-json',
        'query': query
    }

    return render_to_response('mod/search_document_grid.html', RequestContext(request, varis))

def search_document_json(request, query=''):
    
    # Sort
    # srt logic (no problem here)

    # Pagination
    # pagination logic (no problem here)

    # Searching for docs in database
    # query database logic (no problem here)

    documents = Document.objects.filter(QQ).order_by(srt).iterator()
    list_docs = []

    for doc in documents:
        if doc.file.endswith('.pdf'):
            # PDFMiner stuff (no problem here)

            p = re.compile(query, re.IGNORECASE)
            m = p.search(text)

            if m:
                list_docs.append(doc)

        qtr = len(list_docs)

    varis = {'lista': lista[ini:fim]}
    templ = get_template('mod/search_document.json')


    resp = HttpResponse(templ.render(RequestContext(request, varis)), content_type="application/json")

    resp['Content-Range'] = rg
    return resp

urls.py

    url(r'^search-document/$', search_document, name='search_document'),
    url(r'^search-document-json/(?P<query>.*)$', search_document_json, name='search_document_json'),

search_document_grid.html


  require([
        "dojo/cookie",
        "dojo/aspect",
        "dojo/store/JsonRest",
        "dojo/store/Memory",
        "dojo/store/Cache",
        "dojox/grid/EnhancedGrid",
        "dojox/grid/enhanced/plugins/Cookie",
        "dojo/data/ObjectStore",
        "dojo/_base/xhr",
        "dojo/query",
        "dojo/domReady!"
    ], function(cookie, aspect, JsonRest, Memory, Cache, EnhancedGrid, Cookie, ObjectStore, xhr, query){
        var myStore = Cache(JsonRest({target:"{{url}}/{{query|urlencode}}"}), Memory());
        var dataStore = new ObjectStore({ objectStore: myStore });
        var grid = new dojox.grid.EnhancedGrid({
            {% block gridoptions %}
            store: dataStore,
            rowsPerPage: 100,
            keepRows: 200,
            structure: {
                defaultCell: { cellClasses: "normal" },
                cells: [
                    {% block cells %}
                        { name: "Name", field: "name", width: "300px"},
                        { name: "Code", field: "code", width: "100px"},
                        { name: "Version", field: "version", width: "60px"},
                        { name: "Date", field: "date_pub", width: "80px"},
                        { name: "Description", field: "description", width: "400px"},
                       "100px"}
                    {% endblock cells %}
                ]
            },
            {% endblock %}
        }, "grid_1");
        grid.startup();

I would like to return to the grid as the records match. What should be the logic to be used? Tool? Ajax? Jquery? Websockets(*edit2)?!?

edit: At the moment I found a document that fits my query I want that the document go to the grid as the query still working

edit2: As I still don't get what to do I'm thinking about change the entire project. From the day I asked this I still searching and found the new version of Django (3.1) that supports async methods, websockets, etc. This is the correct way? Anyone can help?

  • https://stackoverflow.com/questions/17098675/searching-text-in-a-pdf-using-python – react_or_angluar Nov 24 '20 at 00:13
  • @quantumPuter the search feature is already working (btw I'm using PDFminer). What I really need is a way to return the result one by one as they are found. – Rafael Pinheiro Nov 24 '20 at 00:17
  • So, is this mostly a jQuery and AJAX question? How do you want to display the data? All you've said is "return to the screen as the records match" Try modifying this fiddle and see if you can't get somewhere. http://jsfiddle.net/3JQDz/ – react_or_angluar Nov 24 '20 at 00:27
  • For your display and jQuery questions, you might get some ideas here https://stackoverflow.com/questions/13977566/dynamic-hover-details-with-data-from-text-file – react_or_angluar Nov 24 '20 at 00:36
  • @quantumPuter as the title say: "how to return partial result of a search to a GRID?". Maybe I can describe a little better: Its not only a jquery matter. In the moment I found a document that fits my query I want that the document go to the grid as the query still working. – Rafael Pinheiro Nov 24 '20 at 15:06
  • [realtime stores dojo](https://dojotoolkit.org/documentation/tutorials/1.10/realtime_stores/) I think this is exactly what I need but I’m still trying – Rafael Pinheiro Nov 25 '20 at 21:19

0 Answers0