Closed jeffisabelle closed 10 years ago
oh i see search text functionality is still in development branch of mongoengine. ver 0.9.x [1] the problem is probably related to there.
Hey @jeffisabelle! The stack trace on its own doesn't explicitly identify the issue. What MongoEngine docs did you register in the admin and how? Is t
actually a field on one of the documents you defined?
Hi again,
here how my model looks like. I try to set indexes as described here; http://docs.mongoengine.org/en/latest/guide/text-indexes.html
this document says that i should set field with a $
prefix. But it raises an exception if i use $
prefix.
mongoengine.errors.LookUpError: Cannot resolve field "$title"
class Post(Document):
title = StringField()
slug = StringField()
publish_date = DateTimeField()
score = FloatField()
upvote = IntField()
downvote = IntField()
thumbnail = StringField()
comment_count = IntField(default=0)
dortgen = ReferenceField(Dortgen)
sender = ReferenceField(User)
seq = SequenceField()
replies = ListField(EmbeddedDocumentField(Comment))
meta = {
'allow_inheritance': True,
'indexes': [
{
'fields': ['title'],
'default_language': 'english'
}
]
}
and this is the admin model I use.
class PostModel(model.ModelAdmin):
fields = (
"title", "slug", "publish_date",
"score", "upvote", "downvote", "dortgen",
"url", "domain", "comment_count", "thumbnail"
)
list_display = ("title", "dortgen", "publish_date")
search_fields = ("title")
I'm not sure but, i think its related with my version of mongoengine. The above article states that
I can search objects with QuerySet.search_text
method.
However when i look at my query set objects, they don't seem to have a search_text
method.
Change this line:
search_fields = ("title")
to this one:
search_fields = ("title",)
That comma at the end is necessary to make it a tuple. ("title")
is just a string and since search_fields
is supposed to be an iterable, it treats the value as a list of chars, i.e. search_fields = ("t", "i", "t", "l", "e")
. Hence the error: InvalidQueryError: Cannot resolve field "t"
Oh, that's did the trick. thanks @wojcikstefan!
No problem, you can close this issue now :)
I'm having troubles with searching functionality. I use flask-superadmin with mongoengine. But I'm not sure if this problem is related to mongoengine as @wojcikstefan stated in https://github.com/SyrusAkbary/Flask-SuperAdmin/pull/31#issue-12210543
Here is the trace: