我的Search_Indexes
from datetime import datetime
from haystack import indexes
import json
from dezign.models import dezign
class dezignIndex(indexes.SearchIndex,indexes.Indexable):
text=indexes.CharField(document=True,use_template=True)
post_date=indexes.DateTimeField(model_attr='post_date')
like=indexes.IntegerField(model_attr='like',indexed=False)
#content_auto=indexes.EdgeNgramField(model_attr='title')
#r= indexes.CharField(indexed=False)
def get_model(self):
return dezign
def index_queryset(self,using=None):
return self.get_model().objects.filter(like__exact=0)
# Error in prepare method
def prepare(self, object):
self.prepared_data = super(dezignIndex, self).prepare(object)
self.dezign_jsonformat=[]
select_dezign = dezign.objects.filter(like=self.prepared_data['like'])
for i in select_dezign:
dezign_jsonformat.append({'title':i.title,'body':i.body,'like':i.like,'date':i.post_date})
self.prepared_data['list']=json.dumps(dezign_jsonformat)
return self.prepared_data
当我在命令提示符下运行时
我正在使用Haystack和Whoosh
python。\ manage.py rebuild_index
错误
PS C:\Python27\Scripts\dezignup_django> python .\manage.py rebuild_index
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Traceback (most recent call last):
File ".\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\haystack\management\commands\rebuild_index.py", line 15, in handle
call_command('clear_index', **options)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\haystack\management\commands\clear_index.py", line 50, in handle
backend.clear()
File "C:\Python27\lib\site-packages\haystack\backends\whoosh_backend.py", line 239, in clear
self.setup()
File "C:\Python27\lib\site-packages\haystack\backends\whoosh_backend.py", line 126, in setup
self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_
searchfields())
File "C:\Python27\lib\site-packages\haystack\utils\loading.py", line 316, in all_searchfields
self.build()
File "C:\Python27\lib\site-packages\haystack\utils\loading.py", line 200, in build
indexes = self.collect_indexes()
File "C:\Python27\lib\site-packages\haystack\utils\loading.py", line 169, in collect_indexes
search_index_module = importlib.import_module("%s.search_indexes" % app)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\Python27\Scripts\dezignup_django\dezign\search_indexes.py", line 28
return self.prepared_data
SyntaxError: 'return' outside function
我正在做一个小型网络搜索项目,我们需要json格式的数据
请帮助
我将非常感谢你
答案 0 :(得分:0)
确保您没有混合空格和标签以进行缩进。
错误的一个可能原因是包含return
语句的行使用制表符缩进,而其他语句使用空格缩进。
选择空格(首选)或仅为缩进选项卡。