1 from haystack
import site
2 from haystack
.indexes
import *
3 from ganeti_web
.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
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
25 class VirtualMachineIndex(SearchIndex
):
26 ''' Search index for VirtualMachines '''
28 text
= CharField(document
=True, use_template
=True)
30 # We can pull data strait out of the model via `model_attr`
31 # (Commmenting out 'cause I'm not sure it's needed)
32 # hostname = CharField(model_attr='hostname')
34 # Autocomplete search field on the `hostname` model field
35 content_auto
= EdgeNgramField(model_attr
='hostname')
37 def get_queryset(self
):
38 return VirtualMachine
.objects
.all()
40 site
.register(VirtualMachine
, VirtualMachineIndex
)
43 class ClusterIndex(SearchIndex
):
44 ''' Search index for Clusters '''
46 text
= CharField(document
=True, use_template
=True)
48 # Autocomplete search field on `hostname` model field
49 content_auto
= EdgeNgramField(model_attr
='hostname')
51 def get_queryset(self
):
52 return Cluster
.objects
.all()
54 site
.register(Cluster
, ClusterIndex
)
57 class NodeIndex(RealTimeSearchIndex
):
58 ''' Search index for Nodes '''
60 text
= CharField(document
=True, use_template
=True)
62 # Autocomplete search field on `hostname` model field
63 content_auto
= EdgeNgramField(model_attr
='hostname')
65 def get_queryset(self
):
66 return Node
.objects
.all()
68 site
.register(Node
, NodeIndex
)