Merge branch 'develop' into feature/search_autocomplete_haste
[ganeti_webmgr.git] / ganeti / search_indexes.py
blobbee6cb7a122373030828b9661b10576ea3c6501b
1 from haystack import site
2 from haystack.indexes import *
3 from ganeti.models import VirtualMachine, Cluster, Node
5 ''' Haystack search indexex.
7 This is where the search indexes are defined. They fill the Haystack search
8 query set (the set of objects that are searchable.) There should be one index
9 defined per GWM model.
11 Note that we're using the `SearchIndex` update-based search indexer. This means
12 the search index will need to be updated periodically with
13 `./manage.py update_index`
15 Previously, we were using `RealTimeSearchIndex` which updated the index anytime
16 an associated GWM model changed in the database. Concerns about database
17 performance, database locking issues, and dev server socket problems pushed us
18 away from this indexer.
20 For more informaiton about the availible search indexers, see
21 http://docs.haystacksearch.org/dev/searchindex_api.html#keeping-the-index-fresh
22 '''
24 class VirtualMachineIndex(SearchIndex):
25 ''' Search index for VirtualMachines '''
27 text = CharField(document=True, use_template=True)
29 # We can pull data strait out of the model via `model_attr`
30 # (Commmenting out 'cause I'm not sure it's needed)
31 # hostname = CharField(model_attr='hostname')
33 # Autocomplete search field on the `hostname` model field
34 content_auto = EdgeNgramField(model_attr='hostname')
36 def get_queryset(self):
37 return VirtualMachine.objects.all()
39 site.register(VirtualMachine, VirtualMachineIndex)
41 class ClusterIndex(SearchIndex):
42 ''' Search index for Clusters '''
44 text = CharField(document=True, use_template=True)
46 # Autocomplete search field on `hostname` model field
47 content_auto = EdgeNgramField(model_attr='hostname')
49 def get_queryset(self):
50 return Cluster.objects.all()
52 site.register(Cluster, ClusterIndex)
54 class NodeIndex(RealTimeSearchIndex):
55 ''' Search index for Nodes '''
57 text = CharField(document=True, use_template=True)
59 # Autocomplete search field on `hostname` model field
60 content_auto = EdgeNgramField(model_attr='hostname')
62 def get_queryset(self):
63 return Node.objects.all()
65 site.register(Node, NodeIndex)