Haystack with Whoosh not returning any results
<p>I've installed Django-Haystack and Whoosh and set it all up following the haystack documentation, but no matter what I search for I always get "No results found." on the search page, despite the index apparently being OK.</p>

<p>When running "manage.py rebuild_index" it correctly states:</p>

<pre><code>Indexing 12 assets
  indexed 1 - 12 of 12 (worker PID: 1234).
</code></pre>

<p>And when running this in a Django shell:</p>

<pre><code>from whoosh.index import open_dir
ix = open_dir('mysite/whoosh_index')
from pprint import pprint
pprint(list(ix.searcher().documents()))
</code></pre>

<p>It correctly returns all details of the 12 indexed assets, so it looks like the index is fine, but no matter what I search for I cannot get any results, only "No results found"!  </p>

<p>I have followed the advice in every other similar question on StackOverflow (and everywhere else that popped up on Google) to no avail.</p>

<p>Does anyone have any suggestions?</p>

<p>Files used (edited for brevity):</p>

<p>settings.py</p>

<pre><code>INSTALLED_APPS = [
....
'haystack',
'assetregister',
....
]

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
    },
}
</code></pre>

<p>models.py</p>

<pre><code>class Asset(models.Model):
    asset_id = models.AutoField(primary_key=True)
    asset_description = models.CharField(max_length=200)
    asset_details = models.TextField(blank=True)
</code></pre>

<p>search_indexes.py</p>

<pre><code>from haystack import indexes
from .models import Asset

class AssetIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    asset_description = indexes.CharField(model_attr='asset_description')

    def get_model(self):
        return Asset

    def no_query_found(self):
        # The .exclude is a hack from another stackoverflow question that prevents it returning an empty queryset
        return self.searchqueryset.exclude(content='foo')

    def index_queryset(self, using=None):
        return self.get_model().objects
</code></pre>

<p>/templates/search/indexes/assetregister/asset_text.txt</p>

<pre><code>{{ object.asset_description }}
{{ object.asset_details }}
</code></pre>

<p>urls.py</p>

<pre><code>urlpatterns = [
    url(r'^search/', include('haystack.urls')),
]
</code></pre>

<p>search.html</p>

<pre><code>&lt;h2&gt;Search&lt;/h2&gt;

&lt;form method="get" action="."&gt;
    &lt;table&gt;
        {{ form.as_table }}
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;
                &lt;input type="submit" value="Search"&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;

    {% if query %}
        &lt;h3&gt;Results&lt;/h3&gt;

        {% for result in page.object_list %}
            &lt;p&gt;
                &lt;a href="{{ result.object.get_absolute_url }}"&gt;{{ result.object.asset_description }}&lt;/a&gt;
            &lt;/p&gt;
        {% empty %}
            &lt;p&gt;No results found.&lt;/p&gt;
        {% endfor %}

    {% else %}
        {# Show some example queries to run, maybe query syntax, something else? #}
    {% endif %}
&lt;/form&gt;
</code></pre>

<p>And just in case it's useful, my "pip freeze":</p>

<pre><code>Django==1.9.3
django-cleanup==0.4.2
django-haystack==2.5.0
django-pyodbc-azure==1.9.3.0
Pillow==3.2.0
pyodbc==3.0.10
Whoosh==2.7.4
</code></pre>

<p>For the benefit of any future people having this same problem, I found an unconventional solution...</p>

<p>So I double checked everything according to the haystack documentation and it all looked OK.  I found out about a pip package called "django-haystackbrowser" that, once installed correctly, allows you to view your index through the django admin interface. </p>

<p>For some reason once I had viewed the index in the admin interface (and confirmed everything was already there as it should be) and then restarted the server using</p>

<pre><code>python manage.py runserver
</code></pre>

<p>I finally started getting search results back! </p>

<p>No idea what was causing the problem, and certainly no idea how just viewing the index using that package fixed it, but it now seems to be returning results as it should! </p>

python django python-3.x django-haystack whoosh