tortoise / tortoise/tortoise-orm
How to use SearchCriterio with fulltext of mysql
Open
Nobody has claimed this yet.
question
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
创建的fulltext索引:
class CourseText(Model):
id = fields.IntField(pk=True)
shines_text = fields.TextField()
english_text = fields.TextField()
def __str__(self):
return self.shines_text
class Meta:
table = 'course_text'
indexes = [
FullTextIndex(fields=("shines_text", "english_text"), parser_name='ngram')
]
使用 SearchCriterio全文检索:
@app.get('/coursetext/{strs}')
async def get_course_text(strs: str):
#c = await CourseText.raw(f"select * from course_text where match (shines_text, english_text) against ('{strs}')")
c = SearchCriterion(Term('shines_text'),
Term('english_text'), expr=Term(strs), mode=Mode.NATURAL_LANGUAGE_MODE)
return c
接口返回:
{
"alias": null,
"comparator": " ",
"left": {
"alias": null,
"name": "MATCH",
"args": [
{
"alias": "shines_text"
},
{
"alias": "english_text"
}
],
"schema": null
},
"right": {
"alias": null,
"name": "AGAINST",
"args": [
{
"alias": "王速所院里持口切"
}
],
"schema": null,
"mode": "IN NATURAL LANGUAGE MODE"
}
}
为什么没有正确返回检索出来的内容呢
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CourseText model, its FullTextIndex declaration, and the get_course_text endpoint. Compare the commented raw SQL path with the SearchCriterion construction and inspect how the criterion is consumed by a query; done means the endpoint returns the expected full-text matches rather than only the criterion representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100