Ejemplo n.º 1
0
def search_index_view(request):
    context = {'indexes': OrderedDict()}

    '''
    todo
    DONE reindex selected indexes in background
    . show when indexer is working
    . lock form (if working)
    . show last time indexer started (if working)
    . ajaxify
    . vue.js?
    '''

    from digipal.views.faceted_search import faceted_search
    from digipal.utils import get_all_files_under
    from datetime import datetime
    from digipal.views.faceted_search.search_indexer import SearchIndexer

    indexer = SearchIndexer()

    content_types = faceted_search.get_types(True)

    # process request
    action = request.POST.get('action', '')
    reindexes = []

    if action == 'cancel':
        context['indexing'] = indexer.read_state()
        if context['indexing']:
            import signal
            pid = context['indexing']['pid']
            # kill process
            try:
                res = os.kill(pid, signal.SIGKILL)
            except OSError, e:
                # Process doesn't exist
                if e.errno == 3:
                    pass
            # reset state
            indexer.clear_state()
Ejemplo n.º 2
0
def search_index_view(request):
    context = {'indexes': OrderedDict()}
    '''
    todo
    DONE reindex selected indexes in background
    . show when indexer is working
    . lock form (if working)
    . show last time indexer started (if working)
    . ajaxify
    . vue.js?
    '''

    from digipal.views.faceted_search import faceted_search
    from digipal.utils import get_all_files_under
    from datetime import datetime
    from digipal.views.faceted_search.search_indexer import SearchIndexer

    indexer = SearchIndexer()

    content_types = faceted_search.get_types(True)

    # process request
    action = request.POST.get('action', '')
    reindexes = []

    if action == 'cancel':
        context['indexing'] = indexer.read_state()
        if context['indexing']:
            import signal
            pid = context['indexing']['pid']
            # kill process
            try:
                res = os.kill(pid, signal.SIGKILL)
            except OSError, e:
                # Process doesn't exist
                if e.errno == 3:
                    pass
            # reset state
            indexer.clear_state()
Ejemplo n.º 3
0
def search_index_view(request):
    context = {"indexes": SortedDict()}

    """
    todo
    DONE reindex selected indexes in background
    . show when indexer is working
    . lock form (if working)
    . show last time indexer started (if working)
    . ajaxify
    . vue.js?
    """

    from digipal.views.faceted_search import faceted_search
    from digipal.utils import get_all_files_under
    from datetime import datetime
    from digipal.views.faceted_search.search_indexer import SearchIndexer

    indexer = SearchIndexer()

    content_types = faceted_search.get_types(True)

    # process request
    action = request.POST.get("action", "")
    reindexes = []
    if action == "reindex":
        for ct in content_types:
            if request.POST.get("select-%s" % ct.key):
                reindexes.append(ct.key)

        if reindexes:
            dputils.call_management_command("dpsearch", "index_facets", **{"if": ",".join(reindexes)})
            context["indexing"] = indexer.get_state_initial(reindexes)
    if not "indexing" in context:
        context["indexing"] = indexer.read_state()

    context["running"] = context["indexing"] and context["indexing"]["progress"] < 1.0
    now = datetime.now()
    if context["indexing"] and (
        not context["running"] and ((now - context["indexing"]["updated"]).total_seconds() > (60 * 10))
    ):
        context["indexing"] = None

    # read the index stats
    for ct in content_types:
        info = {"date": 0, "size": 0}
        context["indexes"][ct.key] = {
            "object": ct,
            "info": info,
            "indexing": context["indexing"]["indexes"].get(ct.key, None) if context["indexing"] else None,
        }

        for afile in get_all_files_under(ct.get_whoosh_index_path(), file_types="f"):
            info["size"] += os.path.getsize(afile)
            info["date"] = max(info["date"], os.path.getmtime(afile))

        info["date"] = datetime.fromtimestamp(info["date"])
        info["size"] = int(info["size"])

    context["title"] = "Search Indexer"

    template = "search/search_index.html"
    if request.is_ajax():
        template = "search/search_index_fragment.html"

    ret = render_to_response(template, context, context_instance=RequestContext(request))
    return ret
Ejemplo n.º 4
0
 def recreate_index(self, index_name, schema):
     ret = SearchIndexer.recreate_whoosh_index(settings.SEARCH_INDEX_PATH, index_name, schema)
     return ret
Ejemplo n.º 5
0
 def index_facets(self, options):
     indexer = SearchIndexer()
     indexer.build_indexes(self.get_filtered_indexes())
Ejemplo n.º 6
0
 def recreate_index(self, index_name, schema):
     ret = SearchIndexer.recreate_whoosh_index(settings.SEARCH_INDEX_PATH,
                                               index_name, schema)
     return ret
Ejemplo n.º 7
0
 def index_facets(self, options):
     indexer = SearchIndexer()
     indexer.build_indexes(self.get_filtered_indexes())