from django.contrib.search.backends import LuceneIndexer
from pressblog.blogs.models import Article

def getArticle(i):
    articles=Article.objects.filter(id=i)
    if len(articles)<>1 :
        return None
    article=articles[0]
    return article                 

indexer = LuceneIndexer('/datas/paperblog/pressblog/indexs/article-index',
                        Article,
                        fields=['Article.description'],
                        attributes={'id': 'Article.id'}
                        )

indexer.update()
res=indexer.search('pour')
res2=res._hits
resids=[]
for hit in res2:
    resids.append(int(hit.get('id')))

print resids

articles=[]
for i in resids:
    a=getArticle(i)
    if a:
        articles.append(a)

print articles

                                                            
