Derek
Derek

Reputation: 12388

How do you improve search?

I just got haystack with solr installed and created a custom view:

from haystack.query import SearchQuerySet
def post_search(request, template_name='search/search.html'):
    getdata = request.GET.copy()
    try:
        results = SearchQuerySet().filter(title=getdata['search'])[:10]
    except:
        results = None
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))

This view only returns exact matches on the title field. How do I do at least things like the sql LIKE '%string%' (or at least i think it's this) where if I search 'i' or 'IN' or 'index' I will get the result 'index'?

Also are most of the ways you search edited using haystack or solr?

What other good practices/search improvements do you suggest (please give implementation too)?

Thanks a bunch in advance!

Upvotes: 0

Views: 626

Answers (1)

Bialecki
Bialecki

Reputation: 31081

When you use Haystack/Solr, the idea is that you have to tell Haystack/Solr what you want indexed for a particular object. So say you wanted to build a find as you type index for a basic dictionary. If you wanted it to just match prefixes, for the word Boston, you'd need to tell it to index B, Bo, Bos, etc. and then you'd issue a query for whatever the current search expression was and you could return the results. If you wanted to search any part of the word, you'd need to build suffix trees and then Solr would take care of indexing them.

Look at templates in Haystack for more info. http://docs.haystacksearch.org/dev/best_practices.html#well-constructed-templates

The question you're asking is fairly generic, it might help to give specifics about what people are searching for. Then it'll be easier to suggest how to index the data. Good luck.

Upvotes: 1

Related Questions