Esempio n. 1
0
    def listing(self,
                system,
                file_path,
                user_context=None,
                offset=None,
                limit=None):
        """Perform the search and output in a serializable format."""

        ngram_query = Q("query_string",
                        query=self.query_string,
                        fields=["name"],
                        minimum_should_match='80%',
                        default_operator='or')

        match_query = Q("query_string",
                        query=self.query_string,
                        fields=["name._exact", "name._pattern"],
                        default_operator='and')

        search = IndexedFile.search()
        search = search.filter("nested",
                               path="permissions",
                               query=Q("term",
                                       permissions__username=user_context))
        search = search.query(ngram_query | match_query)

        search = search.query(
            Q('bool',
              must_not=[Q({'prefix': {
                  'path._exact': '/' + user_context
              }})]))
        search = search.filter("term", system=system)
        search = search.query(
            Q('bool',
              must_not=[
                  Q({
                      'prefix': {
                          'path._exact': '{}/.Trash'.format(user_context)
                      }
                  })
              ]))
        res = search.execute()

        children = []
        if res.hits.total.value:
            children = [o.to_dict() for o in search[offset:limit]]

        result = {
            'trail': [{
                'name': '$SEARCHSHARED',
                'path': '/$SEARCH'
            }],
            'name': '$SEARCHSHARED',
            'path': '/$SEARCHSHARED',
            'system': system,
            'type': 'dir',
            'children': children,
            'permissions': 'READ'
        }
        return result
Esempio n. 2
0
def home(request):
    client = Elasticsearch()
    title = request.GET.get('title')
    author = request.GET.get('author')
    paginate_by = 10

    try:
        queries = []

        if title:
            queries.append(Q(
                'match',
                title=title,
            ))
        if author:
            queries.append(Q(
                'match',
                contributor_author=author,
            ))

            reduce(operator.iand, queries)

        countval1 = Advsearch.count()
        Advsearch = Advsearch[0:countval1]
        results = Advsearch.execute()

    except Exception as c:
        Advsearch = ''
        countval1 = 0

    q = request.GET.get('q', '')
    q = q.replace('<', '')
    q = q.replace('>', '')

    try:
        if (q != '' and q is not None):
            search = searchDocument.search().query(
                "multi_match",
                query=q,
                fields=['title', 'description_abstract', 'contributor_author'])
            search = search.highlight_options(order='description_abstract')
            search = search.highlight('title')
            #blogs = search.objects.filter(title__icontains=q).order_by('-created')

        countval = search.count()
        search = search[0:countval]
        search = search.highlight('description_abstract')
        results = search.execute()

    except:
        search = ''
        results = ''
        countval = countval1
        blogs = ''

    paginator = Paginator(SearchResults(search), 10)
    page_number = request.GET.get("page")

    try:
        page = paginator.get_page(page_number)
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)
    except Exception as c:
        page = ''

    context = {
        'search': page,
        'Advsearch': Advsearch,
        'countval': countval,
        'countval1': countval1,
        'results': results,
        'q': q,
        #'blogs': blogs
    }
    if request.user.is_authenticated:
        term = History.objects.create(search_term=q,
                                      username=User.get_username(request.user))
        term.save()
    else:
        term = History.objects.create(search_term=q, username='******')
        term.save()

    if request.user.is_authenticated:
        if request.method == 'POST':
            u_form = Searchsave(request.POST)
            if u_form.is_valid():
                u_form.save()

    return render(request, 'home/index.html', context)
Esempio n. 3
0
def home(request):
    client = Elasticsearch()
    title = request.GET.get('title')
    author = request.GET.get('author')
    paginate_by = 10

    try:
        queries = []

        if title:
            queries.append(Q(
                'match',
                title=title,
            ))
        if author:
            queries.append(Q(
                'match',
                contributor_author=author,
            ))

        Advsearch = searchDocument.search().query(
            reduce(operator.iand, queries))

        countval1 = Advsearch.count()
        Advsearch = Advsearch[0:countval1]
        results = Advsearch.execute()

    except Exception as c:
        Advsearch = ''
        countval1 = 0

    q = request.GET.get('q')

    try:
        if (q != '' and q is not None):
            search = searchDocument.search().query(
                "multi_match",
                query=q,
                fields=['title', 'description_abstract', 'contributor_author'])
            search = search.highlight_options(order='description_abstract')
            search = search.highlight('title')

        countval = search.count()
        search = search[0:countval]
        search = search.highlight('description_abstract')
        results = search.execute()

    except:
        search = ''
        results = ''
        countval = countval1

    context = {
        'search': search,
        'Advsearch': Advsearch,
        'countval': countval,
        'countval1': countval1,
        'results': results
    }

    return render(request, 'home/index.html', context)