Djapian 没有为 Django 创建索引器

发布于 2024-08-09 09:31:43 字数 1466 浏览 8 评论 0原文

我正在完成设置 Djapian 的教程,并尝试使用 indexshell(如 此步骤)。当我运行命令“list”时,我得到以下输出:

Installed spaces/models/indexers:
- 0: 'global'

因此我无法运行任何查询:

>>> query
No index selected

这导致我尝试:

>>> use 0
Illegal index alias '0'. See 'list' command for available aliases

我的index.py如下:

from djapian import space, Indexer, CompositeIndexer
from cms.models import Article

class ArticleIndexer(Indexer):
    fields = ['body']
    tags = [
        ('title', 'title'),
        ('author', 'author'),
        ('pub_date', 'pub_date',),
        ('category', 'category')
    ]

space.add_index(Article, ArticleIndexer, attach_as='indexer')

更新:我将 djapian 文件夹从site-packages 到我的项目文件夹中,并将 index.py 从项目根移动到 djapian 文件夹中。当我在indexshell中运行“list”时,现在返回以下内容:

>>> list
Installed spaces/models/indexers:
- 0: 'global'
    - 0.0 'cms.Article'
        -0.0.0: 'djapian.space.defaultcmsarticleindexer'

我仍然无法执行任何操作,但当我尝试选择索引时,我仍然收到以下错误:

>>> use 0.0
Illegal index alias '0'. See 'list' command for available aliases

更新2:我遇到了问题我对 DJAPIAN_DATABASE_PATH 的设置现已修复。我可以使用命令“use 0.0.0”选择索引器,但是当我尝试运行查询时,它会引发以下 ValueError:“空切片”。

I am working through the tutorial for setting up Djapian and am trying to use the indexshell (as demonstrated in this step). When I run the command 'list' I get the following output:

Installed spaces/models/indexers:
- 0: 'global'

I therefore cannot run any queries:

>>> query
No index selected

Which leads me to attempt:

>>> use 0
Illegal index alias '0'. See 'list' command for available aliases

My index.py is as follows:

from djapian import space, Indexer, CompositeIndexer
from cms.models import Article

class ArticleIndexer(Indexer):
    fields = ['body']
    tags = [
        ('title', 'title'),
        ('author', 'author'),
        ('pub_date', 'pub_date',),
        ('category', 'category')
    ]

space.add_index(Article, ArticleIndexer, attach_as='indexer')

Update: I moved the djapian folder from site-packages to within my project folder and I move index.py from the project root to within the djapian folder. When I run 'list' in the indexshell the following is now returned:

>>> list
Installed spaces/models/indexers:
- 0: 'global'
    - 0.0 'cms.Article'
        -0.0.0: 'djapian.space.defaultcmsarticleindexer'

I still cannot do anything though as when I try to select an index I still get the following error:

>>> use 0.0
Illegal index alias '0'. See 'list' command for available aliases

Update 2: I had a problem with my setting for DJAPIAN_DATABASE_PATH which is now fixed. I can select an indexer using the command 'use 0.0.0' but when I try to run a query it raises the following ValueError: "Empty slice".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

香橙ぽ 2024-08-16 09:31:43

您解决了 ValueError: Empty Slice 的问题了吗?

我在使用 djapian 教程时遇到了完全相同的问题。首先我想知道我的数据库条目是否正确,但现在我想它可能与 Xapian 安装的实际查询有关?

看到我根本不必指向安装,我想知道我是否将其放置在正确的目录中以及 djapian 是否知道在哪里可以找到它。

- 编辑
我已经找到了解决方案,至少对我来说是这样。该教程不是最新的,查询命令也需要大量结果。因此,如果您使用“query mykeyword 5”,您将获得 5 个结果,并且 ValueError: Empty Slice 消失。这是一个已知问题,根据我所读到的内容,它很快就会得到解决。

Have you fixed the problem of the ValueError: Empty Slice?

I'm having the exact same problem using the djapian tutorial. First I was wondering if my database entries were right, but now I'm thinking it might have something to do with the actual querying of the Xapian install?

Seeing that I haven't had to point to the install at all wonders me if I placed it in the right directory and if djapian knows where to find it.

-- Edit
I've found the solution, atleast for me. The tutorial is not up to date and the query command expects a number of results too. So if you use 'query mykeyword 5' you get 5 results and the ValueError: Empty Slice disappears. It's a known issue and it will be fixed soon from what I read.

感情旳空白 2024-08-16 09:31:43

也许您没有加载索引?

您可以尝试将以下内容放在主 urls.py 中:

import djapian
djapian.load_indexes()

在对您的问题的评论中,您写道您已将 index.py 文件放置在项目根目录中。它实际上应该驻留在应用程序中,与 models.py 一起。

还有一件事(这不太可能是您问题的原因);你在下面的行中有一个逗号:

('pub_date', 'pub_date',),
                       ^

Perhaps you're not loading indexes?

You could try placing the following in your main urls.py:

import djapian
djapian.load_indexes()

In a comment to your question you write that you've placed index.py file in the project root. It should actually reside within an app, along models.py.

One more thing (which is very unlikely to be the cause of your problems); you've got a stray comma on the following line:

('pub_date', 'pub_date',),
                       ^
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文