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

Python search.search函数代码示例

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

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



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

示例1: testUnpublishedModelsNotFound

 def testUnpublishedModelsNotFound(self):
     # Make sure that there are four to find!
     self.assertEqual(watson.search("tItle Content Description").count(), 4)
     # Unpublish two objects.
     self.test11.is_published = False
     self.test11.save()
     self.test21.is_published = False
     self.test21.save()
     # This should return 4, but two of them are unpublished.
     self.assertEqual(watson.search("tItle Content Description").count(), 2)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:10,代码来源:tests.py


示例2: test_pagesearchadapter_get_live_queryset

    def test_pagesearchadapter_get_live_queryset(self):
        self.assertEqual(len(search.search("Homepage", models=(Page,))), 1)

        with publication_manager.select_published(True):
            self.assertEqual(len(search.search("Homepage", models=(Page,))), 1)

            self.homepage.is_online = False
            self.homepage.save()

            self.assertEqual(len(search.search("Homepage", models=(Page,))), 0)
开发者ID:onespacemedia,项目名称:cms,代码行数:10,代码来源:test_models.py


示例3: testNestedUpdateInSkipContext

 def testNestedUpdateInSkipContext(self):
     with watson.skip_index_update():
         self.test21.title = "baar"
         self.test21.save()
         with watson.update_index():
             self.test11.title = "fooo"
             self.test11.save()
     # We should get "fooo", but not "baar"
     self.assertEqual(watson.search("fooo").count(), 1)
     self.assertEqual(watson.search("baar").count(), 0)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:10,代码来源:tests.py


示例4: testUpdateSearchIndex

 def testUpdateSearchIndex(self):
     # Update a model and make sure that the search results match.
     self.test11.title = "fooo"
     self.test11.save()
     # Test a search that should get one model.
     exact_search = watson.search("fooo")
     self.assertEqual(len(exact_search), 1)
     self.assertEqual(exact_search[0].title, "fooo")
     # Delete a model and make sure that the search results match.
     self.test11.delete()
     self.assertEqual(watson.search("fooo").count(), 0)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:11,代码来源:tests.py


示例5: testBuildWatsonCommand

 def testBuildWatsonCommand(self):
     # Hack a change into the model using a bulk update, which doesn't send signals.
     WatsonTestModel1.objects.filter(id=self.test11.id).update(title="fooo1")
     WatsonTestModel2.objects.filter(id=self.test21.id).update(title="fooo2")
     # Test that no update has happened.
     self.assertEqual(watson.search("fooo1").count(), 0)
     self.assertEqual(watson.search("fooo2").count(), 0)
     # Run the rebuild command.
     call_command("buildwatson", verbosity=0)
     # Test that the update is now applied.
     self.assertEqual(watson.search("fooo1").count(), 1)
     self.assertEqual(watson.search("fooo2").count(), 1)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:12,代码来源:tests.py


示例6: testSearchWithApostrophe

 def testSearchWithApostrophe(self):
     WatsonTestModel1.objects.create(
         title="title model1 instance12",
         content="content model1 instance13 d'Argent",
         description="description model1 instance13",
     )
     self.assertEqual(watson.search("d'Argent").count(), 1)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:7,代码来源:tests.py


示例7: search

def search(request):
    """ Takes in http request and a user-entered search string, returns the search_results html
        with the objects found by the search available to that template.
    """
    search_str = request.GET["user_search"]
    search_results = watson.search(search_str)
    # Show 18 movies per page
    paginator = Paginator(search_results, 24)

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

    try:
        results = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        results = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        results = paginator.page(paginator.num_pages)

    template = loader.get_template('movies/search_results.html')

    context = {
        'results': results,
        'search_str': search_str,
    }

    return HttpResponse(template.render(context, request))
开发者ID:annihilatrix,项目名称:HorrorShow,代码行数:28,代码来源:views.py


示例8: testSearchWithAccent

 def testSearchWithAccent(self):
     WatsonTestModel1.objects.create(
         title="title model1 instance12",
         content="content model1 instance13 café",
         description="description model1 instance13",
     )
     self.assertEqual(watson.search("café").count(), 1)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:7,代码来源:tests.py


示例9: testExcludedModelQuerySet

 def testExcludedModelQuerySet(self):
     # Test a search that should get all models.
     self.assertEqual(watson.search("TITLE", exclude=(WatsonTestModel1.objects.filter(title__icontains="FOOO"), WatsonTestModel2.objects.filter(title__icontains="FOOO"),)).count(), 4)
     # Test a search that should get two models.
     self.assertEqual(watson.search("MODEL1", exclude=(WatsonTestModel1.objects.filter(
         title__icontains = "INSTANCE21",
         description__icontains = "INSTANCE22",
     ),)).count(), 2)
     self.assertEqual(watson.search("MODEL2", exclude=(WatsonTestModel2.objects.filter(
         title__icontains = "INSTANCE11",
         description__icontains = "INSTANCE12",
     ),)).count(), 2)
     # Test a search that should get one model.
     self.assertEqual(watson.search("INSTANCE11", exclude=(WatsonTestModel1.objects.filter(
         title__icontains = "MODEL2",
     ),)).count(), 1)
     self.assertEqual(watson.search("INSTANCE21", exclude=(WatsonTestModel2.objects.filter(
         title__icontains = "MODEL1",
     ),)).count(), 1)
     # Test a search that should get no models.
     self.assertEqual(watson.search("INSTANCE11", exclude=(WatsonTestModel1.objects.filter(
         title__icontains = "MODEL1",
     ),)).count(), 0)
     self.assertEqual(watson.search("INSTANCE21", exclude=(WatsonTestModel2.objects.filter(
         title__icontains = "MODEL2",
     ),)).count(), 0)
开发者ID:pombredanne,项目名称:django-watson,代码行数:26,代码来源:tests.py


示例10: testSearchWithLeadingApostrophe

 def testSearchWithLeadingApostrophe(self):
     WatsonTestModel1.objects.create(
         title="title model1 instance12",
         content="'content model1 instance13",
         description="description model1 instance13",
     )
     self.assertTrue(
         watson.search("'content").exists()
     )  # Some database engines ignore leading apostrophes, some count them.
开发者ID:dzbrozek,项目名称:django-watson,代码行数:9,代码来源:tests.py


示例11: testCanOverridePublication

 def testCanOverridePublication(self):
     # Unpublish two objects.
     self.test11.is_published = False
     self.test11.save()
     # This should still return 4, since we're overriding the publication.
     self.assertEqual(watson.search(
         "tItle Content Description",
         models=(WatsonTestModel2, WatsonTestModel1._base_manager.all(),)
     ).count(), 4)
开发者ID:etianen,项目名称:django-watson,代码行数:9,代码来源:tests.py


示例12: testSearchIndexUpdateAbandonedOnError

 def testSearchIndexUpdateAbandonedOnError(self):
     try:
         with watson.update_index():
             self.test11.title = "fooo"
             self.test11.save()
             raise Exception("Foo")
     except:
         pass
     # Test a search that should get not model.
     self.assertEqual(watson.search("fooo").count(), 0)
开发者ID:dzbrozek,项目名称:django-watson,代码行数:10,代码来源:tests.py


示例13: search

def search(request):
    context = {}
    q = ""
    try:
        if request.POST:
            q = request.POST['q']
        else:
            q = request.GET['q']
    except MultiValueDictKeyError:
        pass
    context['query'] = q
    context['search_entry_list'] = watson.search(q)
    return render(request, 'search.html', context)
开发者ID:WPI-LNL,项目名称:lnldb,代码行数:13,代码来源:views.py


示例14: testKitchenSink

 def testKitchenSink(self):
     """For sanity, let's just test everything together in one giant search of doom!"""
     self.assertEqual(watson.search(
         "INSTANCE11",
         models = (
             WatsonTestModel1.objects.filter(title__icontains="INSTANCE11"),
             WatsonTestModel2.objects.filter(title__icontains="TITLE"),
         ),
         exclude = (
             WatsonTestModel1.objects.filter(title__icontains="MODEL2"),
             WatsonTestModel2.objects.filter(title__icontains="MODEL1"),
         )
     ).get().title, "title model1 instance11")
开发者ID:pombredanne,项目名称:django-watson,代码行数:13,代码来源:tests.py


示例15: post

    def post(self, request):
        """Returns a Json response of a search query

        Args:
            request (object): HTTPRequest

        Returns:
            object: JsonResponse
        """
        # get query out of request
        query = request.POST['query']
        # search for the query in the database
        search_res = watson.search(query)
        # no search results
        if search_res.count() < 1:
            response = JsonResponse({'search_res': []})
        # search results
        else:
            # list of the search results
            search_res_list = []
            # go through all search results and add them to the list
            for sres in search_res:
                # set the sres to the real result
                sres = sres.object
                # result dict
                res = {}
                # set the values of the res to the sres
                res['name'] = sres.name
                res['overview'] = sres.overview
                res['year'] = (sres.first_air_date.year if
                               sres.first_air_date else None)
                res['genres'] = sres.get_genre_list()
                # try to get the poster url
                try:
                    res['poster'] = sres.poster_large.url
                # no poster is present
                except ValueError:
                    res['poster'] = False
                # url of the series
                res['url'] = sres.get_absolute_url()
                # add the result dict to the search result list
                search_res_list.append(res)
            response = JsonResponse({'search_res': search_res_list})
        return response
开发者ID:tellylog,项目名称:tellylog,代码行数:44,代码来源:views.py


示例16: testBuildWatsonForModelCommand

 def testBuildWatsonForModelCommand(self):
     # Hack a change into the model using a bulk update, which doesn't send signals.
     WatsonTestModel1.objects.filter(id=self.test11.id).update(title="fooo1_selective")
     WatsonTestModel2.objects.filter(id=self.test21.id).update(title="fooo2_selective")
     WatsonTestModel3.objects.filter(id=self.test31.id).update(title="fooo3_selective")
     # Test that no update has happened.
     self.assertEqual(watson.search("fooo1_selective").count(), 0)
     self.assertEqual(watson.search("fooo2_selective").count(), 0)
     self.assertEqual(watson.search("fooo3_selective").count(), 0)
     # Run the rebuild command.
     call_command("buildwatson", "test_watson.WatsonTestModel1", verbosity=0)
     # Test that the update is now applied to selected model.
     self.assertEqual(watson.search("fooo1_selective").count(), 1)
     self.assertEqual(watson.search("fooo2_selective").count(), 0)
     self.assertEqual(watson.search("fooo3_selective").count(), 0)
     call_command(
         "buildwatson",
         "test_watson.WatsonTestModel1", "test_watson.WatsonTestModel2", "test_watson.WatsonTestModel3",
         verbosity=0,
     )
     # Test that the update is now applied to multiple selected models.
     self.assertEqual(watson.search("fooo1_selective").count(), 1)
     self.assertEqual(watson.search("fooo2_selective").count(), 1)
     self.assertEqual(watson.search("fooo3_selective").count(), 1)
开发者ID:etianen,项目名称:django-watson,代码行数:24,代码来源:tests.py


示例17: testSearchWithSpecialChars

    def testSearchWithSpecialChars(self):
        WatsonTestModel1.objects.all().delete()

        x = WatsonTestModel1.objects.create(
            title="title model1 instance12",
            content="content model1 instance13 d'Argent",
            description="description model1 instance13",
        )
        self.assertEqual(watson.search("d'Argent").count(), 1)
        x.delete()

        x = WatsonTestModel1.objects.create(
            title="title model1 instance12",
            content="'content model1 instance13",
            description="description model1 instance13",
        )
        # Some database engines ignore leading apostrophes, some count them.
        self.assertTrue(watson.search("'content").exists())
        x.delete()

        x = WatsonTestModel1.objects.create(
            title="title model1 instance12",
            content="content model1 instance13 d'Argent",
            description="description abcd&efgh",
        )
        self.assertEqual(watson.search("abcd&efgh").count(), 1)
        x.delete()

        x = WatsonTestModel1.objects.create(
            title="title model1 instance12",
            content="content model1 instance13 d'Argent",
            description="description abcd.efgh",
        )
        self.assertEqual(watson.search("abcd.efgh").count(), 1)
        x.delete()

        x = WatsonTestModel1.objects.create(
            title="title model1 instance12",
            content="content model1 instance13 d'Argent",
            description="description abcd,efgh",
        )
        self.assertEqual(watson.search("abcd,efgh").count(), 1)
        x.delete()

        x = WatsonTestModel1.objects.create(
            title="title model1 instance12",
            content="content model1 instance13 d'Argent",
            description="description [email protected]",
        )
        self.assertEqual(watson.search("[email protected]").count(), 1)
        x.delete()
开发者ID:pombredanne,项目名称:django-watson,代码行数:51,代码来源:tests.py


示例18: testReferencingWatsonRankInAnnotations

    def testReferencingWatsonRankInAnnotations(self):
        """We should be able to reference watson_rank from annotate expressions"""
        entries = watson.search("model1").annotate(
            relevant=Case(
                When(watson_rank__gt=1.0, then=Value(1)),
                default_value=Value(0),
                output_field=IntegerField()
            )
        )

        # watson_rank does not return the same value across backends, so we
        # can't hard code what those will be. In some cases (e.g. the regex
        # backend) all ranking is hard coded to 1.0. That doesn't matter - we
        # just want to make sure that Django is able to construct a valid query
        for entry in entries:
            if entry.watson_rank > 1.0:
                self.assertTrue(entry.relevant)
            else:
                self.assertFalse(entry.relevant)
开发者ID:etianen,项目名称:django-watson,代码行数:19,代码来源:tests.py


示例19: search

def search(request):
    out = {}
    search_text = request.GET.get('search', '')
    search_results = watson.search(search_text)
    search_results_count = search_results.count()
    page_number = request.GET.get('page', 1)
    start = (int(page_number) - 1) * 10
    out.update({'current_page_number': int(page_number)})
    all_page_count = search_results.count() / 10 + 1
    if search_results.count() % 10:
        all_page_count += 1
    search_results = search_results[start:start+10]
    out.update({'all_page_number': range(1, all_page_count)})
    out.update({'menu_active_item': 'search'})
    out.update({'search_results': search_results})
    out.update({'search_results_count': search_results_count})
    out.update({'search_text': search_text})
    out.update({'title': u'Поиск'})
    return render(request, 'search.html', out)
开发者ID:callisto1337,项目名称:zavod,代码行数:19,代码来源:views.py


示例20: search

def search(user_id, search_term, before=None, after=None):
    """Offload the expensive part of search to avoid blocking the web interface"""
    if not search_term:
        return {
            "results": [],
            "has_next": False
        }

    if before and after:
        raise ValueError("You can't do this.")

    email_subquery = models.Email.objects.viewable(user_id)
    inbox_subquery = models.Inbox.objects.viewable(user_id)
    search_qs = watson_search.search(search_term, models=(email_subquery, inbox_subquery))

    page_kwargs = {
        "after": after,
        "before": before,
    }
    if before:
        page_kwargs["last"] = SEARCH_PAGE_SIZE
    else:
        page_kwargs["first"] = SEARCH_PAGE_SIZE

    paginator = CursorPaginator(search_qs, ordering=('-watson_rank', '-id'))

    page = paginator.page(**page_kwargs)
    results = {
        "results": [p.id for p in page],
        "has_next": page.has_next,
        "has_previous": page.has_previous,
    }

    if len(results["results"]) > 0:
        results["last"] = paginator.cursor(page[-1])
        results["first"] = paginator.cursor(page[0])

    key = create_search_cache_key(user_id, search_term, before, after)
    cache.set(key, results, SEARCH_TIMEOUT)

    return results
开发者ID:Inboxen,项目名称:Inboxen,代码行数:41,代码来源:tasks.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python wave.open函数代码示例发布时间:2022-05-26
下一篇:
Python models.has_int_pk函数代码示例发布时间: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