DjangoPy
DjangoPy

Reputation: 865

No result for django + haystack 1.2.7 and solr 3.6.1

I'm having trouble getting results back.

This is what I've got so far:

search_indexes.py

class CompanyIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    name = CharField(model_attr='name')
    sector = CharField(model_attr='sector')

    def get_model(self):
        return Company

    def index_queryset(self):
        return self.get_model().objects.all()

site.register(Company, CompanyIndex)

class CompanySearchForm(ModelSearchForm):
    name = forms.CharField(max_length=64, required=False)
    sector = forms.MultipleChoiceField(choices=SECTORS_CHOICES, required=False)

    def search(self):
        # First, store the SearchQuerySet received from other processing.
        sqs = super(CompanySearchForm, self).search()
        print "fgdgdfgdfgdfg"
        if self.is_valid():
            # Check to see if a start_date was chosen.
            if self.cleaned_data['name']:
                print "%s" % self.cleaned_data['name']
                sqs = sqs.filter(name__exact=self.cleaned_data['name'])

            # Check to see if an end_date was chosen.
            if self.cleaned_data['sector']:
                sqs = sqs.filter(sector__contains=self.cleaned_data['sector'])

        return sqs

and urls:

sqs = SearchQuerySet()
    url(r'^search/', SearchView(
    template='search/search.html',
    form_class=CompanySearchForm,
    searchqueryset=sqs,
), name='haystack_search'),

I'm using the template from haystack documentation. i see no results.

I appreciate any help

Upvotes: 0

Views: 250

Answers (1)

Sergey Lyapustin
Sergey Lyapustin

Reputation: 1937

You should create template in:

templates\search\indexes\APP_NAME\company_text.txt

what represent searchable fields from you CompanyIndex

{{ object.text }}
{{ object.name }}
{{ object.sector }}

Whatever you write in template will be searched from your indexes regardless it is present in search_index.py or not. Following is enough to make an index.

 text = CharField(document=True, use_template=True) 

Upvotes: 1

Related Questions