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 4339222
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:11:15+00:00 2026-05-21T11:11:15+00:00

I’ve recently set up solr and haystack to search one of my django models.

  • 0

I’ve recently set up solr and haystack to search one of my django models. I attempted to modify the default solr schema built by haystack to use the NGramTokenizerFactory:

<fieldType name="text" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="32" />
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
      <tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="32" />
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

I have a bunch of one or two word entries in my database which I would like to match against the user’s query. So for example, I might have one object with title "dog" and another with title "cat". If the user searches for "dog cat" then I would like to return both the dog and cat objects for that query.

Similarly, if I search for "my cool website" I would like the field with "website" to be returned.

I tried using the solr admin interface to check to make sure my queries were getting matched. Everything seems okay there:
enter image description here:
The issue is when I use the haystack default search interface to search for that same query:
enter image description here

As you can see, no results are found. I tried using KeywordFactory and a bunch of different solr configurations. If I’m not mistaken then the query should be getting matched. I’m not sure why haystack is coming up empty though.

Thanks for any help / suggestions on if this is the best way to go about such a search.

  • 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-05-21T11:11:16+00:00Added an answer on May 21, 2026 at 11:11 am

    Few month ago I worked with django-haystack and solr. I also had a problems with making some special queries to solr.
    Actually it should be solved by addng next line to settings.py:

    HAYSTACK_DEFAULT_OPERATOR = 'OR' # actually has no effect...
    

    But it does not work for me.

    So, in my case it was solved by subclassing SearchView class. This is small snippet from my project:

    # views.py:
    from haystack.views import SearchView
    
    class PeriodicalSearchView(SearchView):
      def get_results(self):
        """
        Fetches the results via the form.
        Returns an empty list if there's no query to search with.
        """
        if not (self.form.is_valid() and self.form.cleaned_data['q']):
            return self.form.no_query_found()
    
        query = self.form.cleaned_data['q']
    
        words = iter(set(query.split()))
        word = words.next()
        sqs = self.form.searchqueryset.filter(text=word) # actually I have one more field here...
        for word in words:
            sqs = sqs.filter_or(title=word).filter_or(text=word)
    
        if self.load_all:
            sqs = sqs.load_all()
    
        return sqs
    
      def __call__(self, request, template_name=None):
        """
        Generates the actual response to the search.
        Relies on internal, overridable methods to construct the response.
        """
        if template_name:
            self.template = template_name
    
        return super(PeriodicalSearchView, self).__call__(request)
    

    And urls.py

    # urls.py:
    from .views import PeriodicalSearchView
    
    urlpatterns = patterns('',
        url(r'^search/$', PeriodicalSearchView(template='template_search.html'), 
        name='haystack_search'),
    )
    

    And that’s it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.