Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:12:38+00:00 2026-06-17T09:12:38+00:00

I am having a difficult time getting autocomplete to work with haystack and Solr

  • 0

I am having a difficult time getting autocomplete to work with haystack and Solr in a search form. Following the instructions here Auto-complete i was able to create my index in the following way.

class PersonIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
    text = CharField(document=True, use_template=True)
    first_name = CharField(model_attr='first_name')
    last_name = CharField(model_attr='last_name')
    first_name_auto = indexes.EdgeNgramField(model_attr='first_name')


    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all().order_by('first_name')

    def get_model(self):
        return Person

And with the way my URL route is set up, i dont have a view request that get directed to, the search method works.

url(r'^search/person/', search_view_factory(
    view_class=SearchView,
    template='index.html',
    form_class=ModelSearchForm
), name='haystack_search'),

The instructions say that we can perform the query in this fashion

from haystack.query import SearchQuerySet

sqs = SearchQuerySet().filter(content_auto=request.GET.get('q', ''))

but where do we put this SearchQuerySet, i am not sure what to override, how to modify my url to route correctly. My search currently works out of the box this way but i want to try auto complete with EdgeNgramField ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:12:38+00:00Added an answer on June 17, 2026 at 9:12 am

    You’ll need to define your own custom search form and tell it how to generate the SearchQuerySet it returns to the view, and then tell your search_view_factory to use that form instead of the ModelSearchForm.

    Specify the way you want to generate the SearchQuerySet used by your view by overriding the ModelSearchForm search method:

    from haystack.forms import ModelSearchForm
    
    class AutocompleteModelSearchForm(ModelSearchForm):
    
        def search(self):
            if not self.is_valid():
                return self.no_query_found()
            if not self.cleaned_data.get('q')
                return self.no_query_found()
            sqs = self.searchqueryset.filter(first_name_auto=self.cleaned_data['q'])
    
            if self.load_all
                sqs = sqs.load_all()
    
            return sqs
    

    This will now perform a filter on the form’s SearchQuerySet on the first_name_auto field rather than the auto_query that it would usually do on the text field (see haystack/forms.py to see what the original search function looks like).

    You specify that you want to use this form in the argument list to your search_view_factory

    from path.to.your.forms import AutocompleteModelSearchForm
    
    url(r'^search/person/', search_view_factory(
        view_class=SearchView,
        template='index.html',
        form_class=AutocompleteModelSearchForm
     ), name='haystack_search'),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a difficult time getting the hyperlink to work in a JEditorPane. Could
i'm having a really difficult time getting this to work... Basically - I have
I am having an extremely difficult time getting this to work. The applet is
I'm having a real difficult time getting this code to work. I'm trying to
I am having a difficult time getting a select box populated with optgroups that
I'm having a difficult time getting my head around this logic. (I've completely rewritten
I am still pretty new to C# and am having a difficult time getting
I'm having an extremely difficult time getting a private method with arguments to be
I am having a difficult time getting the right positional css for a layout
I'm having a difficult time getting into using mod_rewrite. I've been at this for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.