• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python backends.get_search_backend函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wagtail.wagtailsearch.backends.get_search_backend函数的典型用法代码示例。如果您正苦于以下问题:Python get_search_backend函数的具体用法?Python get_search_backend怎么用?Python get_search_backend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_search_backend函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_backend_loader

    def test_backend_loader(self):
        # Test DB backend import
        db = get_search_backend(backend='wagtail.wagtailsearch.backends.db.DBSearch')
        self.assertIsInstance(db, DBSearch)

        # Test Elastic search backend import
        elasticsearch = get_search_backend(backend='wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch')
        self.assertIsInstance(elasticsearch, ElasticSearch)

        # Test loading a non existant backend
        self.assertRaises(InvalidSearchBackendError, get_search_backend, backend='wagtail.wagtailsearch.backends.doesntexist.DoesntExist')

        # Test something that isn't a backend
        self.assertRaises(InvalidSearchBackendError, get_search_backend, backend="I'm not a backend!")
开发者ID:AppDevy,项目名称:wagtail,代码行数:14,代码来源:tests.py


示例2: update_backend

    def update_backend(self, backend_name, object_list):
        # Print info
        self.stdout.write("Updating backend: " + backend_name)

        # Get backend
        backend = get_search_backend(backend_name)

        # Reset the index
        self.stdout.write(backend_name + ": Reseting index")
        backend.reset_index()

        for model, queryset in object_list:
            self.stdout.write(backend_name + ": Indexing model '%s.%s'" % (
                model._meta.app_label,
                model.__name__,
            ))

            # Add type
            backend.add_type(model)

            # Add objects
            backend.add_bulk(model, queryset)

        # Refresh index
        self.stdout.write(backend_name + ": Refreshing index")
        backend.refresh_index()
开发者ID:AustinBurns,项目名称:wagtail,代码行数:26,代码来源:update_index.py


示例3: search

    def search(
        cls,
        query_string,
        show_unpublished=False,
        search_title_only=False,
        extra_filters={},
        prefetch_related=[],
        path=None,
    ):
        # Filters
        filters = extra_filters.copy()
        if not show_unpublished:
            filters["live"] = True

        # Path
        if path:
            filters["path__startswith"] = path

        # Fields
        fields = None
        if search_title_only:
            fields = ["title"]

        # Search
        s = get_search_backend()
        return s.search(query_string, cls, fields=fields, filters=filters, prefetch_related=prefetch_related)
开发者ID:precise54,项目名称:wagtail,代码行数:26,代码来源:models.py


示例4: setUp

    def setUp(self):
        self.backend = get_search_backend('elasticsearch')
        self.backend.rebuilder_class = self.backend.atomic_rebuilder_class
        self.es = self.backend.es
        self.rebuilder = self.backend.get_rebuilder()

        self.backend.reset_index()
开发者ID:Anlim,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py


示例5: search

def search(request):
    do_json = 'json' in request.GET
    search_query = request.GET.get('query', None)
    page = request.GET.get('page', 1)

    # Search
    if search_query:
        page_alias_content_type = ContentType.objects.get_for_model(PageAlias)

        search_results = (
            Page.objects.live()
            # exclude root and home pages
            .filter(depth__gt=2)
            # exclude PageAlias pages
            .exclude(content_type=page_alias_content_type)
            .search(search_query)
        )

        query = Query.get(search_query)

        # log the query so Wagtail can suggest promoted results
        query.add_hit()

        # promoted search results
        promoted_page_ids = [
            pick.page.id for pick in query.editors_picks.all()
        ]
        promoted_results = Page.objects.filter(pk__in=promoted_page_ids)

        # search Person snippets
        search_backend = get_search_backend()
        people_results = search_backend.search(
            search_query, Person.objects.all()
        )
    else:
        search_results = Page.objects.none()
        promoted_results = Page.objects.none()
        people_results = Person.objects.none()

    # Pagination
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    response = {
        'search_query': search_query,
        'search_results': search_results,
        'promoted_results': promoted_results,
        'people_results': people_results,
    }

    if do_json:
        return JsonResponse(get_results_json(response))
    else:
        return render(request, 'search/search.html', response)
开发者ID:ghostwords,项目名称:localore,代码行数:59,代码来源:views.py


示例6: search

 def search(self, query_string, fields=None,
            operator=None, order_by_relevance=True, backend='default'):
     """
     This runs a search query on all the items in the QuerySet
     """
     search_backend = get_search_backend(backend)
     return search_backend.search(query_string, self, fields=fields,
                                  operator=operator, order_by_relevance=order_by_relevance)
开发者ID:AdamBolfik,项目名称:wagtail,代码行数:8,代码来源:queryset.py


示例7: handle

    def handle(self, **options):
        # Print info
        self.stdout.write("Getting object list")

        # Get list of indexed models
        indexed_models = [model for model in models.get_models() if issubclass(model, Indexed)]

        # Object set
        object_set = {}

        # Add all objects to object set and detect any duplicates
        # Duplicates are caused when both a model and a derived model are indexed
        # Eg, if BlogPost inherits from Page and both of these models are indexed
        # If we were to add all objects from both models into the index, all the BlogPosts will have two entries
        for model in indexed_models:
            # Get toplevel content type
            toplevel_content_type = model.indexed_get_toplevel_content_type()

            # Loop through objects
            for obj in model.get_indexed_objects():
                # Get key for this object
                key = toplevel_content_type + ':' + str(obj.pk)

                # Check if this key already exists
                if key in object_set:
                    # Conflict, work out who should get this space
                    # The object with the longest content type string gets the space
                    # Eg, "wagtailcore.Page-myapp.BlogPost" kicks out "wagtailcore.Page"
                    if len(obj.indexed_get_content_type()) > len(object_set[key].indexed_get_content_type()):
                        # Take the spot
                        object_set[key] = obj
                else:
                    # Space free, take it
                    object_set[key] = obj

        # Search backend
        if 'backend' in options:
            s = options['backend']
        else:
            s = get_search_backend()

        # Reset the index
        self.stdout.write("Reseting index")
        s.reset_index()

        # Add types
        self.stdout.write("Adding types")
        for model in indexed_models:
            s.add_type(model)

        # Add objects to index
        self.stdout.write("Adding objects")
        for result in s.add_bulk(object_set.values()):
            self.stdout.write(result[0] + ' ' + str(result[1]))

        # Refresh index
        self.stdout.write("Refreshing index")
        s.refresh_index()
开发者ID:Gavryush,项目名称:wagtail,代码行数:58,代码来源:update_index.py


示例8: find_backend

def find_backend(cls):
    if not hasattr(settings, 'WAGTAILSEARCH_BACKENDS'):
        if cls == DBSearch:
            return 'default'
        else:
            return

    for backend in settings.WAGTAILSEARCH_BACKENDS.keys():
        if isinstance(get_search_backend(backend), cls):
            return backend
开发者ID:AppDevy,项目名称:wagtail,代码行数:10,代码来源:tests.py


示例9: list

def list(request, app_label, model_name):
    model = get_snippet_model_from_url_params(app_label, model_name)

    permissions = [
        get_permission_name(action, model)
        for action in ['add', 'change', 'delete']
    ]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    items = model.objects.all()

    # Preserve the snippet's model-level ordering if specified, but fall back on PK if not
    # (to ensure pagination is consistent)
    if not items.ordered:
        items = items.order_by('pk')

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and 'q' in request.GET:
        search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': model._meta.verbose_name_plural
        })

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': model._meta.verbose_name_plural
        })

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = 'wagtailsnippets/snippets/results.html'
    else:
        template = 'wagtailsnippets/snippets/type_index.html'

    return render(request, template, {
        'model_opts': model._meta,
        'items': paginated_items,
        'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
        'is_searchable': is_searchable,
        'search_form': search_form,
        'is_searching': is_searching,
        'query_string': search_query,
    })
开发者ID:kapito,项目名称:wagtail,代码行数:55,代码来源:snippets.py


示例10: choose

def choose(request, app_label, model_name):
    model = get_snippet_model_from_url_params(app_label, model_name)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and "q" in request.GET:
        search_form = SearchForm(
            request.GET, placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name}
        )

        if search_form.is_valid():
            search_query = search_form.cleaned_data["q"]

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(
            placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name}
        )

    # Pagination
    paginator, paginated_items = paginate(request, items, per_page=25)

    # If paginating or searching, render "results.html"
    if request.GET.get("results", None) == "true":
        return render(
            request,
            "wagtailsnippets/chooser/results.html",
            {
                "model_opts": model._meta,
                "items": paginated_items,
                "query_string": search_query,
                "is_searching": is_searching,
            },
        )

    return render_modal_workflow(
        request,
        "wagtailsnippets/chooser/choose.html",
        "wagtailsnippets/chooser/choose.js",
        {
            "model_opts": model._meta,
            "items": paginated_items,
            "is_searchable": is_searchable,
            "search_form": search_form,
            "query_string": search_query,
            "is_searching": is_searching,
        },
    )
开发者ID:XLeonardo,项目名称:wagtail,代码行数:55,代码来源:chooser.py


示例11: list

def list(request, content_type_app_name, content_type_model_name):
    content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
    model = content_type.model_class()

    permissions = [
        get_permission_name(action, model)
        for action in ['add', 'change', 'delete']
    ]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and 'q' in request.GET:
        search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': snippet_type_name_plural
        })

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': snippet_type_name_plural
        })

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = 'wagtailsnippets/snippets/results.html'
    else:
        template = 'wagtailsnippets/snippets/type_index.html'

    return render(request, template, {
        'content_type': content_type,
        'snippet_type_name': snippet_type_name,
        'snippet_type_name_plural': snippet_type_name_plural,
        'items': paginated_items,
        'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
        'is_searchable': is_searchable,
        'search_form': search_form,
        'is_searching': is_searching,
        'query_string': search_query,
    })
开发者ID:Tivix,项目名称:wagtail,代码行数:55,代码来源:snippets.py


示例12: setUp

    def setUp(self):
        # Search WAGTAILSEARCH_BACKENDS for an entry that uses the given backend path
        for backend_name, backend_conf in settings.WAGTAILSEARCH_BACKENDS.items():
            if backend_conf['BACKEND'] == self.backend_path:
                self.backend = get_search_backend(backend_name)
                break
        else:
            # no conf entry found - skip tests for this backend
            raise unittest.SkipTest("No WAGTAILSEARCH_BACKENDS entry for the backend %s" % self.backend_path)

        self.load_test_data()
开发者ID:Gavryush,项目名称:wagtail,代码行数:11,代码来源:test_backends.py


示例13: choose

def choose(request, content_type_app_name, content_type_model_name):
    content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
    model = content_type.model_class()
    snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and 'q' in request.GET:
        search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': snippet_type_name_plural
        })

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': snippet_type_name_plural
        })

    # Pagination
    paginator, paginated_items = paginate(request, items, per_page=25)

    # If paginating or searching, render "results.html"
    if request.GET.get('results', None) == 'true':
        return render(request, "wagtailsnippets/chooser/results.html", {
            'content_type': content_type,
            'snippet_type_name': snippet_type_name,
            'items': paginated_items,
            'query_string': search_query,
            'is_searching': is_searching,
        })

    return render_modal_workflow(
        request,
        'wagtailsnippets/chooser/choose.html', 'wagtailsnippets/chooser/choose.js',
        {
            'content_type': content_type,
            'snippet_type_name': snippet_type_name,
            'items': paginated_items,
            'is_searchable': is_searchable,
            'search_form': search_form,
            'query_string': search_query,
            'is_searching': is_searching,
        }
    )
开发者ID:Tivix,项目名称:wagtail,代码行数:54,代码来源:chooser.py


示例14: list

def list(request, app_label, model_name):
    model = get_snippet_model_from_url_params(app_label, model_name)

    permissions = [get_permission_name(action, model) for action in ["add", "change", "delete"]]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and "q" in request.GET:
        search_form = SearchForm(
            request.GET,
            placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name_plural},
        )

        if search_form.is_valid():
            search_query = search_form.cleaned_data["q"]

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(
            placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name_plural}
        )

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = "wagtailsnippets/snippets/results.html"
    else:
        template = "wagtailsnippets/snippets/type_index.html"

    return render(
        request,
        template,
        {
            "model_opts": model._meta,
            "items": paginated_items,
            "can_add_snippet": request.user.has_perm(get_permission_name("add", model)),
            "is_searchable": is_searchable,
            "search_form": search_form,
            "is_searching": is_searching,
            "query_string": search_query,
        },
    )
开发者ID:qjardon,项目名称:wagtail,代码行数:52,代码来源:snippets.py


示例15: get_elasticsearch_backend

    def get_elasticsearch_backend(self):
        from django.conf import settings
        from wagtail.wagtailsearch.backends import get_search_backend

        backend_path = 'wagtail.wagtailsearch.backends.elasticsearch'

        # Search WAGTAILSEARCH_BACKENDS for an entry that uses the given backend path
        for backend_name, backend_conf in settings.WAGTAILSEARCH_BACKENDS.items():
            if backend_conf['BACKEND'] == backend_path:
                return get_search_backend(backend_name)
        else:
            # no conf entry found - skip tests for this backend
            raise unittest.SkipTest("No WAGTAILSEARCH_BACKENDS entry for the backend %s" % backend_path)
开发者ID:davecranwell,项目名称:wagtail,代码行数:13,代码来源:tests.py


示例16: dosearch

        def dosearch(query_string, **kwargs):
            # Get backend
            if 'backend' in kwargs:
                backend = kwargs['backend']
                del kwargs['backend']
            else:
                backend = 'default'

            # Build search kwargs
            search_kwargs = dict(model=cls, fields=self.fields, filters=self.filters)
            search_kwargs.update(kwargs)

            # Run search
            return get_search_backend(backend=backend).search(query_string, **search_kwargs)
开发者ID:AppDevy,项目名称:wagtail,代码行数:14,代码来源:searcher.py


示例17: update_backend

    def update_backend(self, backend_name, object_list):
        # Print info
        self.stdout.write("Updating backend: " + backend_name)

        # Get backend
        backend = get_search_backend(backend_name)

        # Activate backend language
        cur_language = translation.get_language()
        backend_language = getattr(backend, 'language_code', None)
        if backend_language is not None:
            translation.activate(backend_language)

        # Get rebuilder
        rebuilder = backend.get_rebuilder()

        if not rebuilder:
            self.stdout.write(backend_name + ": Backend doesn't support rebuild. Skipping")
            return

        # Start rebuild
        self.stdout.write(backend_name + ": Starting rebuild")
        index = rebuilder.start()

        for model, queryset in object_list:
            self.stdout.write(backend_name + ": Indexing model '%s.%s'" % (
                model._meta.app_label,
                model.__name__,
            ))

            # Add model
            index.add_model(model)

            # Add items (1000 at a time)
            count = 0
            for chunk in self.print_iter_progress(self.queryset_chunks(queryset)):
                index.add_items(model, chunk)
                count += len(chunk)

            self.stdout.write("Indexed %d %s" % (
                count, model._meta.verbose_name_plural))
            self.print_newline()

        # Finish rebuild
        self.stdout.write(backend_name + ": Finishing rebuild")
        rebuilder.finish()

        # Return to Original Thread Language
        if backend_language is not None:
            translation.activate(cur_language)
开发者ID:razisayyed,项目名称:wagtail,代码行数:50,代码来源:update_index.py


示例18: test_import_old_name

    def test_import_old_name(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            db = get_search_backend(backend="wagtail.wagtailsearch.backends.db.DBSearch")

        self.assertIsInstance(db, DatabaseSearchBackend)

        self.assertEqual(len(w), 1)
        self.assertIs(w[0].category, RemovedInWagtail18Warning)
        self.assertEqual(
            str(w[0].message),
            "The 'wagtail.wagtailsearch.backends.db.DBSearch' search backend path has "
            "changed to 'wagtail.wagtailsearch.backends.db'. Please update the "
            "WAGTAILSEARCH_BACKENDS setting to use the new path.",
        )
开发者ID:kurtrwall,项目名称:wagtail,代码行数:16,代码来源:test_backends.py


示例19: setUp

    def setUp(self):
        s = get_search_backend()

        # Stick some documents into the index
        testa = models.SearchTest()
        testa.title = "Hello World"
        testa.save()
        s.add(testa)

        testb = models.SearchTest()
        testb.title = "Hello"
        testb.save()
        s.add(testb)

        testc = models.SearchTestChild()
        testc.title = "Hello"
        testc.save()
        s.add(testc)
开发者ID:AppDevy,项目名称:wagtail,代码行数:18,代码来源:tests.py


示例20: choose

def choose(request):
    items = Poll.objects.all()

    # Search
    is_searching = False
    search_query = None
    if 'q' in request.GET:
        search_form = AdminSearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': 'Polls'
        })

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = AdminSearchForm()

    # Pagination
    paginator, paginated_items = paginate(request, items, per_page=25)

    # If paginating or searching, render "results.html"
    if request.GET.get('results', None) == 'true':
        return render(request, "wagtailpolls/search_results.html", {
            'items': paginated_items,
            'query_string': search_query,
            'is_searching': is_searching,
        })

    return render_modal_workflow(
        request,
        'wagtailpolls/choose.html', 'wagtailpolls/choose.js',
        {
            'snippet_type_name': 'Poll',
            'items': paginated_items,
            'is_searchable': True,
            'search_form': search_form,
            'query_string': search_query,
            'is_searching': is_searching,
        }
    )
开发者ID:takeflight,项目名称:wagtailpolls,代码行数:44,代码来源:chooser.py



注:本文中的wagtail.wagtailsearch.backends.get_search_backend函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python backends.get_search_backends函数代码示例发布时间:2022-05-26
下一篇:
Python serve.generate_signature函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap