2012-04-13 32 views
1

我下面就haystack documentation.Django的草垛不會指數我的數據

說明我沒有得到任何結果SearchQuerySet()。所有()。

我認爲這個問題是在這裏

$ ./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. 
All documents removed. 
Indexing 0 notes. // <-- here 0 notes! 

的mysite/NOTE/search_indexes.py看起來像

import datetime 
import haystack 
from haystack import indexes 
from note.models import Note 

class NoteIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 
    author = indexes.CharField(model_attr='user') 
    pub_date = indexes.DateTimeField(model_attr='pub_date') 

    def get_model(self): 
     return Note 

    def index_queryset(self): 
     """Used when the entire index for model is updated.""" 
     return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now()) 

和我的mysite/NOTE /模板/搜索/索引/ NOTE/Note_text。 TXT

{{ object.title }} 
{{ object.user.get_full_name }} 
{{ object.body }} 

Debugging haystack document提到

您是否擁有運行haystack.autodiscover的search_sites.py?

你註冊過主haystack.site(通常在您的search_indexes.py中的 )模型嗎?

但在第一篇文章中沒有提到search_sites.py,haystack.autodiscover,haystack.site。
我很困惑。他們的文檔是否涉及不同的乾草堆版本?

我的設置是..

草垛版本2.0.0.beta
的Django 1.3.1
的Solr 3.6.0
sqlite的3

+0

在我的(愚蠢的)情況下,rebuild_index沒有索引任何產品,因爲沒有任何(db連接是不正確的)。 – 2018-03-07 13:44:42

回答

1

它應該是...

def index_queryset(self, using=None):

我不知道這是否會解決您的問題或沒有,但就是該方法的正確的簽名。

2
def index_queryset(self): 
     """Used when the entire index for model is updated.""" 
     return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now()) 

是罪魁禍首。

我不知道爲什麼,但註釋掉了這個問題。
我想我的系統中的'時間'有點搞砸了。

0

刪除def index_queryset(self)是有意義的。它構建了一個常規的Django ORM QuerySet,它決定將哪些對象放入全文索引。您的樣本index_queryset將對象限制爲僅限過去的時間戳(之前的現在爲)。

所以,你真的有一個datetime處理問題。檢查您的SQL數據庫的時區以及它如何存儲時間。

UTC區域設置的時間戳大約比紐約和美國大部分地區早5小時。SQLite在將來選擇UTC時間對我造成同樣的問題。