当前位置: 首页>>代码示例>>Python>>正文


Python watson.search函数代码示例

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


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

示例1: testSearchEmailParts

 def testSearchEmailParts(self):
     with watson.update_index():
         self.test11.content = "[email protected]"
         self.test11.save()
     self.assertEqual(watson.search("fooo").count(), 1)
     self.assertEqual(watson.search("baar.com").count(), 1)
     self.assertEqual(watson.search("[email protected]").count(), 1)
开发者ID:bfitzsimmons,项目名称:django-watson,代码行数:7,代码来源:tests.py

示例2: search

def search(request):
    if request.GET['q']:
        name="All Sections"
        section="all"
        query=request.GET['q']
        if 'section' in request.GET:
            section=request.GET['section']
            if section=="all":
                results=watson.search(query)
            else:
                sec=[]
                model=get_model(section)
                name=get_name(section)
                sec.append(model)
                results=watson.search(query,models=tuple(sec))
        else:
            results=watson.search(query)
    else:
        return HttpResponseRedirect(reverse('home'))
    length=len(results)
    paginator = Paginator(results,10)
    page = request.GET.get('page')
    try:
        obj=paginator.page(page)
    except:
        obj=paginator.page(1)
    context = {'name':name,'obj':obj,'section':section,'length':length,'range':range(1,obj.paginator.num_pages+1),'query':query}
    return render(request,'search.html',context)
开发者ID:jeanconn,项目名称:astropython,代码行数:28,代码来源:views.py

示例3: search_idb

def search_idb(request):

	query = request.GET.get('q', '') #returns string of args from search
	q_list = []

	search_results = watson.search(query) #AND search
	q_list.append(search_results)

	arg_list = query.split() #split on whitespace to get search terms

	
	if len(arg_list) > 1: #OR search for each individual term
		for search_term in arg_list:
			more_results = (watson.search(search_term))
			q_list.append(more_results)
	

	list_of_models = []
	for item in q_list:
		for result in item:
			if result not in list_of_models:
				list_of_models.append(result)

	count = len(list_of_models)
	context = RequestContext(request, {'query': query, 'count': count,'results': search_results, 'list': list_of_models})

	t = loader.get_template('watson/search.html')
	return HttpResponse(t.render(context))
开发者ID:DimosGu,项目名称:cs373-idb,代码行数:28,代码来源:views.py

示例4: search

def search(request):
    if request.GET['q']:
        name="All Sections"
        section="all"
        query=request.GET['q']
        if 'section' in request.GET:
            section=request.GET['section']
            if section=="all":
                results=watson.search(query)
            elif section=="tl":
                name="Teach and Learn"
                results=watson.search(query,models=tuple([Tutorial,EducationalResource,Wiki,Snippet]))
            elif section=="forum":
                name="Forum"
                results=watson.search(query,models=tuple([Announcement,Event,Blog,News]))
            else:
                sec=[]
                model=get_model(section)
                name=get_name(section)
                sec.append(model)
                results=watson.search(query,models=tuple(sec))
        else:
            results=watson.search(query)
    else:
        return HttpResponseRedirect(reverse('home'))
    length=len(results)
    paginator = Paginator(results,15)
    page = request.GET.get('page')
    try:
        obj=paginator.page(page)
    except:
        obj=paginator.page(1)
    context = {'name':name,'obj':obj,'section':section,'length':length,'range':range(1,obj.paginator.num_pages+1),'query':query}
    return render(request,'search.html',context)
开发者ID:hamogu,项目名称:astropython.org,代码行数:34,代码来源:views.py

示例5: get_search_results

def get_search_results(query, slug):
    if slug not in SEARCH_PARAMS:
        raise Http404('Invalid search slug.')
    models = SEARCH_PARAMS[slug]
    object_list = list(watson.search(query, models=models))
    # Perform the search with the rest of the models:
    if models:
        object_list += list(watson.search(query, exclude=models))
    return object_list
开发者ID:us-ignite,项目名称:us_ignite,代码行数:9,代码来源:views.py

示例6: 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="fooo")
     # Test that no update has happened.
     self.assertEqual(watson.search("fooo").count(), 0)
     # Run the rebuild command.
     call_command("buildwatson", verbosity=0)
     # Test that the update is now applies.
     self.assertEqual(watson.search("fooo").count(), 1)
开发者ID:daposta,项目名称:django-watson,代码行数:9,代码来源:tests.py

示例7: search

def search(request):
    context = RequestContext(request)

    query = ""
    query_words = []

    if ('q' in request.GET) and request.GET['q'].strip():
        query = request.GET['q']

    query_items = query.split()

    and_search = watson.search(query, ranking=True)

    for a in and_search:
        print(a.url)
        print(a)

    results = list(and_search)

    for item in query_items:
        or_search = list(watson.search(item, ranking=True))
        for o in or_search:
            if not o in results:
                results.append(o)


    snippets = []

    for i in range(0, len(results)):
        final_sentence = ""
        sentences = splitParagraph(results[i].content)

        for s in list(sentences):
            if(s.lower().find(query.lower()) != -1):
                sentences.remove(s)
                s = s.lower().replace(query.lower(), "<B class='search_term'>"+query.lower()+"</B>")
                final_sentence += " " + s
                break

        for q_item in query_items:
            for s in list(sentences):
                if(s.lower().find(query.lower()) != -1):
                    sentences.remove(s)
                    s = s.lower().replace(query.lower(), "<B class='search_term'>"+query.lower()+"</B>")
                    final_sentence += " " + s
                    break

        final_sentence += " "
        snippets.append(final_sentence)

    zipped = None
    if len(results) > 0:
        zipped = zip(results, snippets)
    length_results = len(results)

    return render_to_response('search.html', {"query": query, "length_results": length_results, "results": zipped}, context)
开发者ID:Charoenworawat,项目名称:CopaDatabase,代码行数:56,代码来源:views.py

示例8: testBuildWatsonCommand

 def testBuildWatsonCommand(self):
     # This update won't take affect, because no search context is active.
     self.test11.title = "fooo"
     self.test11.save()
     # Test that no update has happened.
     self.assertEqual(watson.search("fooo").count(), 0)
     # Run the rebuild command.
     call_command("buildwatson", verbosity=0)
     # Test that the update is now applies.
     self.assertEqual(watson.search("fooo").count(), 1)
开发者ID:bfitzsimmons,项目名称:django-watson,代码行数:10,代码来源:tests.py

示例9: 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:mhahn,项目名称:django-watson,代码行数:10,代码来源:tests.py

示例10: 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:mhahn,项目名称:django-watson,代码行数:10,代码来源:tests.py

示例11: 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:mhahn,项目名称:django-watson,代码行数:11,代码来源:tests.py

示例12: search

def search(request):
    context = RequestContext(request)
    query = ""
    query_words = []
    if ('q' in request.GET) and request.GET['q'].strip():
        query = request.GET['q']
    
    query_words = query.split()
    
    and_results = watson.search(query, ranking=True)
    results = list(and_results)

    for wd in query_words:
        or_results = list(watson.search(wd, ranking=True))
        for r in or_results:
            if not r in results:
                results.append(r)
    
    snippets = []
    
    
    for i in range(0, len(results)):
        final_sentence = ""

        sentences = splitParagraph(results[i].content)

        #First highlight terms in sentences matching the phrase
        for s in list(sentences):
            if(s.lower().find(query.lower()) != -1):
                sentences.remove(s)
                s = s.lower().replace(query.lower(), "<B class='search_term'>"+query.lower()+"</B>")
                final_sentence += "..." + s
                break

        #Then highlight the separate words of a query separately
        for q_wd in query_words:
            for s in list(sentences):
                if (s.lower().find(q_wd.lower()) != -1):
                    sentences.remove(s)
                    s = s.lower().replace(q_wd.lower(), "<B class='search_term'>"+q_wd.lower()+"</B>")
                    final_sentence += "..." + s
                    break

        final_sentence += "..."
        snippets.append(final_sentence)

    zipped = None
    if len(results) > 0:
        zipped = zip(results, snippets)
    length_results = len(results)

    return render_to_response('mythos/search.html', {"query": query, "length_results": length_results, "results": zipped}, context)
开发者ID:ses110,项目名称:cs373-idb,代码行数:52,代码来源:views.py

示例13: tag_search

def tag_search(request, klass, template):
    """Search subset of models with the given tag.

    Usess ``watson`` for the full-text search.
    """
    # Generate a queryset from a model, manager or queryset:
    form = SearchForm(request.GET)
    page_no = pagination.get_page_no(request.GET)
    if form.is_valid():
        queryset = get_queryset(klass)
        object_list = watson.search(
            form.cleaned_data['q'], models=(queryset, ))
        pagination_qs = '&%s' % urlencode({'q': form.cleaned_data['q']})
    else:
        object_list = []
        pagination_qs = ''
    page = pagination.get_page(object_list, page_no)
    page.object_list_top = [o.object for o in page.object_list_top]
    page.object_list_bottom = [o.object for o in page.object_list_bottom]
    context = {
        'page': page,
        'form': form,
        'pagination_qs': pagination_qs,
    }
    return TemplateResponse(request, template, context)
开发者ID:jendc123,项目名称:us_ignite,代码行数:25,代码来源:filters.py

示例14: 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:mhahn,项目名称:django-watson,代码行数:7,代码来源:tests.py

示例15: 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:mhahn,项目名称:django-watson,代码行数:7,代码来源:tests.py


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