wenzhi xue
unread,May 23, 2012, 5:56:30 PM5/23/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-...@googlegroups.com
I have two modle here :
class StockSymbol(models.Model):
symbol = models.CharField( max_length = 15 )
exchange = models.CharField( max_length = 15, blank=True, null=True )
companyName = models.CharField( max_length = 40 )
def __unicode__(self):
return self.companyName
class WeatherLocation(models.Model):
woeid = models.IntegerField()
cityChar = models.CharField( max_length = 30,blank=True, null=True )
stateChar = models.CharField( max_length = 30, blank=True, null=True )
def __unicode__(self):
return self.cityChar
and I implement my index object like that :::
class WeatherLocationIndex(SearchIndex):
text = CharField(document=True, use_template=True)
stateChar = indexes.CharField(model_attr='stateChar')
cityChar = indexes.NgramField(model_attr='cityChar')
def get_model(self):
return WeatherLocation
def index_queryset(self):
"""Used when the entire index for model is updated."""
return WeatherLocation.objects.all()
def get_queryset(self):
return WeatherLocation.objects.all()
class StockSymbolIndex(SearchIndex):
text = CharField(document=True, use_template=True)
companyName = indexes.CharField(model_attr='companyName')
symbol = indexes.NgramField(model_attr='symbol')
def get_model(self):
return StockSymbol
def index_queryset(self):
"""Used when the entire index for model is updated."""
return StockSymbol.objects.all()
def get_queryset(self):
return StockSymbol.objects.all()
site.register(WeatherLocation, WeatherLocationIndex)
site.register(StockSymbol, StockSymbolIndex)
Then i did rebuild_index and go to django shell
My data here is "new york" and "new England"
but I can only get result if i do
>>> SearchQuerySet().filter(cityChar ='new')
[<SearchResult: rulesData.weatherlocation (pk=u'1')>, <SearchResult:
rulesData.weatherlocation (pk=u'3')>]
I can not get any result if i use "ne" or simply "n"
>>> SearchQuerySet().filter(cityChar ='ne')
[]
any one can help me ?