def test_spelling(self):
        # Stow.
        from django.conf import settings
        old = settings.HAYSTACK_CONNECTIONS['default'].get(
            'INCLUDE_SPELLING', None)

        settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = True

        sv = SearchView()
        sv.query = 'Nothing'
        sv.results = []
        sv.build_page = lambda: (None, None)
        sv.create_response()
        context = sv.get_context()

        self.assertIn('suggestion',
                      context,
                      msg='Spelling suggestions should be present even if'
                      ' no results were returned')
        self.assertEqual(context['suggestion'], None)

        # Restore
        settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = old

        if old is None:
            del settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING']
Example #2
0
def search_concepts(request):
	"""
	Concepts search
	"""
	from haystack.views import SearchView
	state = "search"
	return SearchView(template='search/search.html')(request)
 def test_view_suggestion(self):
     view = SearchView(template='test_suggestion.html',
                       searchqueryset=SearchQuerySet('whoosh'))
     mock = HttpRequest()
     mock.GET['q'] = 'exampl'
     resp = view(mock)
     self.assertEqual(resp.content, b'Suggestion: example')
Example #4
0
 def test_view_suggestion(self):
     view = SearchView(template="test_suggestion.html",
                       searchqueryset=SearchQuerySet("whoosh"))
     mock = HttpRequest()
     mock.GET["q"] = "exampl"
     resp = view(mock)
     self.assertEqual(resp.content, b"Suggestion: example")
Example #5
0
    def test_spelling(self):
        # Stow.
        from django.conf import settings

        old = settings.HAYSTACK_CONNECTIONS["default"].get(
            "INCLUDE_SPELLING", None)

        settings.HAYSTACK_CONNECTIONS["default"]["INCLUDE_SPELLING"] = True

        sv = SearchView()
        sv.query = "Nothing"
        sv.results = []
        sv.build_page = lambda: (None, None)
        sv.create_response()
        context = sv.get_context()

        self.assertIn(
            "suggestion",
            context,
            msg="Spelling suggestions should be present even if"
            " no results were returned",
        )
        self.assertEqual(context["suggestion"], None)

        # Restore
        settings.HAYSTACK_CONNECTIONS["default"]["INCLUDE_SPELLING"] = old

        if old is None:
            del settings.HAYSTACK_CONNECTIONS["default"]["INCLUDE_SPELLING"]
 def test_initial_data(self):
     sv = SearchView(form_class=InitialedSearchForm)
     sv.request = HttpRequest()
     form = sv.build_form()
     self.assertTrue(isinstance(form, InitialedSearchForm))
     self.assertEqual(form.fields['q'].initial, 'Search for...')
     para = form.as_p()
     self.assertTrue(u'<label for="id_q">Search:</label>' in para)
     self.assertTrue(u'value="Search for..."' in para)
Example #7
0
def index(request):
    if (request.GET.get("q", None) != None):
        return SearchView(template="books/index.html")(request)

    rand_books = Book.objects.all().order_by("?")[:10]
    return render(request, 'books/index.html', {
        'books': rand_books,
        'form': SearchForm()
    })
Example #8
0
 def test_initial_data(self):
     sv = SearchView(form_class=InitialedSearchForm)
     sv.request = HttpRequest()
     form = sv.build_form()
     self.assert_(isinstance(form, InitialedSearchForm))
     self.assertEqual(form.fields['q'].initial, 'Search for...')
     self.assertEqual(
         form.as_p(),
         u'<p><label for="id_q">Search:</label> <input type="text" name="q" value="Search for..." id="id_q" /></p>'
     )
Example #9
0
def search(request):
    """
    Calls Haystack, but allows us to first log the search query
    """

    if request.GET.get('q', '').strip() == '':
        return redirect(front_page)

    # Avoid duplicate logging if search request results in more than 1 page
    if 'page' not in request.GET:
        create_hit(request, 'haystack_search', request.GET['q'])
        logger.info('SEARCH [%s]: %s' % (get_IP_address(request),
                                         request.GET['q']))
    return SearchView().__call__(request)
Example #10
0
    def test_details(self):
        # Create an instance of a GET request.


        from django.test.client import RequestFactory
        from haystack.views import SearchView
        import urllib2
        url = '/search/?q=information'
        request = urllib2.Request(url)
        #request.add_header("Content-Type", "application/json") #
        sv = SearchView(request)
        sv.build_form()
        results = sv.get_results()
        # Test my_view() as if it were deployed at /customer/details
        self.assertEqual(len(results), 35)
Example #11
0
    def test_spelling(self):
        # Stow.
        from django.conf import settings
        old = settings.HAYSTACK_CONNECTIONS['default'].get('INCLUDE_SPELLING', None)

        sv = SearchView()
        sv.query = 'Nothing'
        sv.results = []
        sv.build_page = lambda: (None, None)
        output = sv.create_response()

        # Restore
        settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = old

        if old is None:
            del settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING']
Example #12
0
def search(request):
    """
    Calls Haystack, but allows us to first log the search query
    """
    if request.GET['q'].strip() == '':
        return redirect(front_page)

    try:
        item_id = int(request.GET['q'])
    except ValueError:
        pass
    else:
        items = Item.objects.filter(id=item_id)
        if items:
            return redirect('lit-view-item', item_id=item_id)
        else:
            pass

    # Avoid duplicate logging if search request results in more than 1 page
    if 'page' not in request.GET:
        create_hit(request, 'haystack_search', request.GET['q'])
        logger.info('SEARCH [%s]: %s' %
                    (get_IP_address(request), request.GET['q']))
    return SearchView().__call__(request)
Example #13
0
    url(r'^delete/', delete, name='delete'),
    url(
        r'^crawler/$',
        TemplateView.as_view(template_name="document_manager/crawler.html",
                             content_type="text/html")),
    url(r'^admin/', admin.site.urls),
    url(r'^user_profile/', get_user_profile),
    url(r'^recommendations/', recommendations, name='recommendations'),
    url(r'^entity_search/(?P<entityslug>[-\w]+)$',
        entity_search,
        name='entity_search'),
    url(r'^paragraph_search/(?P<paragraphslug>[-\w]+)$',
        paragraph_search,
        name='paragraph_search'),
    url(r'^(?P<id>[^/]+)/(?P<slug>[-\w]+)$',
        DocumentDetailView.as_view(),
        name='document-detail'),
    url(r'^login/$',
        login, {'template_name': 'document_manager/login.html'},
        name='legal_mining_login'),
    url(r'^logout/$',
        logout, {'next_page': reverse_lazy('legal_mining_login')},
        name='legal_mining_logout'),
    url(r'^$',
        login_required(
            SearchView(template='search/search.html',
                       searchqueryset=sqs,
                       form_class=CustomSearchForm)),
        name='haystack_search'),
]
Example #14
0
    AreaDetailView,
    KnowYourCandidatesView,
)

from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.decorators.cache import cache_page

media_root = getattr(settings, 'MEDIA_ROOT', '/')

urlpatterns = [
    path('',
         cache_page(60 * settings.CACHE_MINUTES)(xframe_options_exempt(
             HomeView.as_view())),
         name='home'),
    path('buscar',
         SearchView(template='search.html', form_class=ElectionForm),
         name='search'),
    path('busqueda_tags',
         ElectionsSearchByTagView.as_view(),
         name='tags_search'),
    path('eleccion/<slug:slug>',
         ElectionDetailView.as_view(
             template_name='elections/election_detail.html'),
         name='election_view'),
    path('eleccion/<slug:slug>/questionary',
         ElectionDetailView.as_view(
             template_name='elections/election_questionary.html'),
         name='questionary_detail_view'),
    # compare two candidates
    path(
        'eleccion/<slug:slug>/face-to-face/<slug:slug_candidate_one>/<slug:slug_candidate_two>',
Example #15
0
def search(request):
    from haystack.views import SearchView
    search_view = SearchView(template="dinette/search.html")
    return search_view(request)
Example #16
0
from django.urls import path

from haystack.views import SearchView

urlpatterns = [path("", SearchView(), name="haystack_search")]
Example #17
0
from django.conf.urls import include, url
from django.contrib import admin

from haystack.query import SearchQuerySet
from haystack.views import SearchView
from haystack.forms import SearchForm

from search.views import countries

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    # #url(r'.*', 'search.views.search', name='search'),
    url(r'^countries/$', countries, name='countries'),
    url(
        r'.*',
        SearchView(searchqueryset=SearchQuerySet().order_by('-added_on'),
                   form_class=SearchForm)),
]
Example #18
0
def search(request):
    """Runner search
  """
    return SearchView(template='search/search.html')(request)
# encoding: utf-8

from __future__ import absolute_import, division, print_function, unicode_literals

from haystack.views import SearchView

try:
    from django.conf.urls import patterns, url
except ImportError:
    from django.conf.urls.defaults import patterns, url

urlpatterns = patterns(
    'haystack.views',
    url(r'^$', SearchView(), name='haystack_search'),
)
Example #20
0
 def test_empty_results(self):
     sv = SearchView()
     sv.request = HttpRequest()
     sv.form = sv.build_form()
     self.assert_(isinstance(sv.get_results(), EmptySearchQuerySet))
Example #21
0
# urls for posts
urlpatterns += patterns('',
    url(r'^post/thumbs/$', iknow_thumbs, name="iknow_thumbs"),
    url(r'^post/answerer_rating/$', iknow_answerer_rating, name="iknow_answerer_rating"),
    url(r'^post/tipping/$', iknow_tipping, name="iknow_tipping"),
    url(r'^post/comment/$', iknow_comment, name="iknow_comment"),
    url(r'^post/add/favorite/$', iknow_post_add_favorite, name="iknow_post_add_favorite"),
    url(r'^post/amendment/$', iknow_post_amendment, name="iknow_post_amendment"),
    url(r'^post/asker/hide/$', iknow_post_asker_hide, name="iknow_post_asker_hide"),
    url(r'^post/answerer/hide/$', iknow_post_answerer_hide, name="iknow_post_answerer_hide"),
)

# urls for json
urlpatterns += patterns('',
    url(r'^json/answer_comments/$', iknow_json_answer_comments, name="iknow_json_answer_comments"),
)

from haystack.forms import ModelSearchForm
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from iknow.models import Question
sqs = SearchQuerySet().models(Question)
# urls for search
urlpatterns += patterns('haystack.views',
	url(r'^search/$', SearchView(
		template="iknow/iknow_search.html",
		searchqueryset=sqs,
		form_class=ModelSearchForm
	), name="iknow_search"),
)
Example #22
0
from django.conf.urls import url
from . import views
from haystack.views import SearchView

app_name = 'shopping'

urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^list_all/$', views.ListAllView.as_view(), name='list_all'),
    url(r'^crow/(\d+)/$', views.CrowView.as_view(), name='crow'),
    url(r'^style/(\d+)/$', views.StyleView.as_view(), name='style'),
    url(r'^brand/(\d+)/$', views.BrandView.as_view(), name='brand'),
    url(r'^contact/$', views.ContactView.as_view(), name='contact'),
    url(r'^login/$', views.LoginView.as_view(), name='login'),
    url(r'^register/$', views.RegisterView.as_view(), name='register'),
    url(r'^logout/$', views.LogOutView.as_view(), name='logout'),
    url(r'^active/(.*?)/$', views.ActiveView.as_view(), name='active'),
    url(r'^search/$', SearchView(), name='search'),
]
Example #23
0
from django.contrib import admin

from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView, SearchView

admin.autodiscover()

urlpatterns = patterns(
    '',
    (r'^admin/', include(admin.site.urls)),
)

urlpatterns += patterns(
    'haystack.views',
    url(r'^$', SearchView(load_all=False), name='haystack_search'),
    url(r'^faceted/$',
        FacetedSearchView(searchqueryset=SearchQuerySet().facet('author'),
                          form_class=FacetedSearchForm),
        name='haystack_faceted_search'),
    url(r'^basic/$',
        'basic_search', {'load_all': False},
        name='haystack_basic_search'),
)

urlpatterns += patterns(
    'app-without-models',
    url(
        r'',
        include('test_haystack.test_app_without_models.urls',
                namespace='app-without-models')),
Example #24
0
from django.conf.urls import url
from . import views
from .feed import ArticleFeed
from haystack.views import SearchView
app_name = "blog"
urlpatterns = [
    # url(r'^$', views.IndexView.as_view(),name="index"),
    url(r'^$', views.index,name="index"),
    url(r'^single/(\d+)/$', views.SingleView.as_view(), name="single"),
    url(r'^archives/(\d+)/(\d+)/$',views.ArchieveView.as_view(),name="archives"),
    url(r'^category/(\d+)/$',views.CategoryView.as_view(),name="category"),
    url(r'^tags/(\d+)/$',views.TagView.as_view(),name="tags"),
    url(r'^contact/$',views.ContactView.as_view(),name="contact"),
    url(r'^rss/$',ArticleFeed(), name="rss"),

    url(r'sendmail',views.SendMailView.as_view(),name="sendmail"),
    url(r'^search/$',SearchView(),name="search")
]
Example #25
0
from django.conf.urls.defaults import *
from haystack.forms import ModelSearchForm
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from search.views import RestrictedSearchView

urlpatterns = patterns('haystack.views',
    url(r'^$', SearchView(
        template='search/search.html',
        form_class=ModelSearchForm,
    ), name='haystack_search'),
)
Example #26
0
def SearchBizCir(request):
    import sys
    default_encoding = 'utf-8'
    if sys.getdefaultencoding() != default_encoding:
        reload(sys)
        sys.setdefaultencoding(default_encoding)
    response_data = {}
    if request.method == 'POST':
        keyWord = request.POST.get('q', None)  #关键字
        page = request.POST.get('page', None)  #1 ++
        communityId = request.POST.get('commid', None)
#         sort        = request.POST.get('sort',0) #1离我最近 2好评优先 3人气最高0智能排序
#         tag         = request.POST.get('bctag',0) #0全部1酒店2美食3生活
    else:
        keyWord = request.GET.get('q', None)  #关键字
        page = request.GET.get('page', None)  #1 ++
        communityId = request.GET.get('commid', None)
#         sort        = request.GET.get('sort',0) #1离我最近 2好评优先 3人气最高0智能排序
#         tag         = request.GET.get('bctag',0) #0全部1酒店2美食3生活
    if page is None or communityId is None or keyWord is None:
        response_data['flag'] = 'argv_error'
        return response_data
    from haystack import indexes
    from addrinfo.models import BusinessCircle
    from haystack.views import SearchView
    from addrinfo.search_indexes import search_indexes
    #    qe = queryset_comm(communityId)
    #     queryset_comm.community = communityId
    #    search_indexes.index_queryset = qe.my_queryset
    resultlist = []
    pagenum = long(page)
    while (len(resultlist) < 10):
        search = SearchView()
        #        if request.method == 'POST':
        #            request.POST = request.POST.copy()
        #            request.POST['page'] = str(pagenum)
        #            pagenum = pagenum+1
        #            request.POST['q'] = keyWord
        #            request.POST['commid'] = communityId
        #        else:
        request.GET = request.GET.copy()
        request.GET['page'] = str(pagenum)
        pagenum = pagenum + 1
        request.GET['q'] = keyWord
        request.GET['commid'] = communityId
        try:
            result = search(request)
        except:
            result = 'final'
        if result == 'final':
            #             resultlist.append(result)
            break


#        resultlist.append(str(result))
        if htmlanalysis(str(result)) != None:
            resultlist.append(htmlanalysis(str(result)))
    size = len(resultlist)
    if size == 0:
        response_data['flag'] = 'none'
        response_data['yl_msg'] = u'没有更多了'
        return response_data
    else:
        response_data['flag'] = 'ok'
        response_data['page'] = pagenum
        response_data['data'] = resultlist
        return response_data
Example #27
0
from django.urls import path
from .views import product_create_admin, product_detail_admin, product_edit_admin, product_list_admin, index_admin, \
    category_create, categories, product_delete_admin, category_delete, category_edit
from haystack.views import SearchView

urlpatterns = [
    path('', index_admin, name='index_admin'),
    path('produtos/', product_list_admin, name='product_list_admin'),
    path('novo-produto/', product_create_admin, name='product_create_admin'),
    path('produto/<slug:slug>',
         product_detail_admin,
         name='product_detail_admin'),
    path('editar-produto/<slug:slug>',
         product_edit_admin,
         name='product_edit_admin'),
    path('apagar-produto/<slug:slug>',
         product_delete_admin,
         name='product_delete_admin'),
    path('apagar-categoria/<int:id>', category_delete, name='category_delete'),
    path('editar-categoria/<int:id>', category_edit, name='category_edit'),
    path('nova-categoria/', category_create, name='category_create'),
    path('categorias/', categories, name='categories'),
    path('busca/',
         SearchView(template='admin2/search.html'),
         name='haystack_search_admin'),
]
Example #28
0
    url(r'^pages/(?P<page>[-\w]+)/$',
        'display_page_helper',
        name='post_page_base'),
    url(r'^pages/(?P<page>[-\w]+)/(?P<sort_id>\d+)/$',
        'display_page_helper',
        name='post_page_base'),
    url(r'^user/(?P<user>[-\w]+)/$', 'user_page', name='user_page'),
    url(r'^robots.txt$', 'robots_page'))

sitemaps = {
    'home_sitemap': HomeSitemap,
    'piqs_sitemap': PIQSSitemap,
    'accounts_sitemap': LoginRegisterSitemap,
    'learn_faq_sitemap': LearnFaqSitemap,
    'posts': PostSitemap,
    'users': UserSitemap,
}

urlpatterns += patterns(
    '',
    url(r'^' + settings.ADMIN_URL, include(admin.site.urls)),
    url(r'^post/', include('posts.urls')),
    url(r'^comments/', include('djangospam.cookie.urls')),  #IT'S A TRAP!
    url(r'^accounts/', include('accounts.urls')),
    url(r'^accounts/', include('registrationFix.urls')),
    url(r'^', include('votes.urls')),
    url(r'^comment/', include('comments.urls')),
    url(r'^search/$', SearchView(form_class=SearchForm), name='search'),
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
        {'sitemaps': sitemaps}))
Example #29
0
"""blog URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from django.http import HttpResponse
from haystack.views import SearchView

urlpatterns = [
    path('admin/', admin.site.urls),
    url('articletest/', include('articletest.urls', namespace='articletest')),
    # 全文检索路由
    url('search/', SearchView(), name='search'),
]
Example #30
0
from django.urls import path, register_converter, re_path

from . import views
from haystack.views import SearchView

# 自定义过滤器
# register_converter(converters.IntConverter,'myint')
# register_converter(converters.FourDigitYearConverter, 'yyyy')

urlpatterns = [
    path('', views.show_all_comments, name='index'),
    path('index', views.show_all_comments, name='index'),
    # path('search/', views.search,name='search'),
    path('search/', SearchView(), name='haystack_search'),
]