taskstopics = db.Table(‘taskstopics’, db.Column(‘taskid’, db.Integer,…
- User
tasks_topics = db.Table(‘tasks_topics’, db.Column(‘task_id’, db.Integer, db.ForeignKey(‘tasks.id’)), db.Column(‘topics_id’, db.Integer, db.ForeignKey(‘topics.id’)) )
class Tasks(db.Model): tablename = ‘tasks’ searchable = [‘task’, ‘id’] # these fields will be indexed by whoosh
id = db.Column(db.Integer, primary_key=True, autoincrement=True) url = db.Column(db.String(120), comment=“ЧПУ задачи в адресе (транслитом)”) task = db.Column(db.Text, comment=‘Условие задачи’) answer = db.Column(db.Text, comment=‘Ответ’) status = db.Column(db.Boolean, default=0, comment=‘Статус: опубликована/неактивна (по умолчанию нет)’) created_t = db.Column(db.DateTime, comment=‘Дата и время создания’) level = db.Column(db.SmallInteger, default=1, comment=‘Уровень сложности: 1,2 … (по умолчанию 1 уровень)’)
связи
topics = db.relationship(‘Topics’, secondary=tasks_topics, back_populates=“tasks”)
class Topics(db.Model): tablename = ‘topics’ searchable = [‘name’]
id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(140), comment=“Уникальное название темы(подтемы)”) parent = db.Column(db.Integer, default=0, comment=“ID родительской темы(если есть)”)
связи
tasks = db.relationship(‘Tasks’, secondary=tasks_topics, back_populates=“topics”)
schema = Schema(id=ID(stored=True), task=TEXT(stored=True), answer=TEXT(stored=True), topics_name = TEXT(stored=True))
index_dir = 'tasks_index' if not os.path.exists(index_dir): os.mkdir(index_dir) ix = create_in(index_dir, schema) else: ix = open_dir(index_dir)
with ix.searcher() as searcher: query = QueryParser('task','topics_name', ix.schema).parse('Умножение и деление')
results = searcher.search(query, limit=None) print(results) for hit in results: print(hit)with ix.writer() as writer: all_tasks = Tasks.query.options(subqueryload(Tasks.topics)).all() for task in all_tasks: topics_name = "" for top in task.topics: topics_name.join(top.name)
writer.add_document(id=str(task.id), task=task.task, answer=task.answer,topics_name = topics_name) writer.commit()AttributeError: 'TEXT' object has no attribute 'taggers' line 575, in query = QueryParser('task','topics_name', ix.schema).parse('Умножение и деление')
- Assistant
It seems like you are trying to use a tagger on a 'TEXT' object which does not have the attribute 'taggers'. This could be because the tagger attribute is not defined in your schema. You can add the 'taggers' attribute to your schema by modifying it as follows:
schema = Schema(id=ID(stored=True), task=TEXT(stored=True, analyzer=StemmingAnalyzer()), answer=TEXT(stored=True), topics_name = TEXT(stored=True))
In this example, I have added the 'StemmingAnalyzer' as the tagger for the 'task' field, but you can choose any other tagger that suits your needs.
- User
NameError: name 'StemmingAnalyzer' is not defined
- Assistant
The
StemmingAnalyzeris not defined in the current namespace, and you need to import it from thewhoosh.analysismodule. You can add the following import statement to your code:from whoosh.analysis import StemmingAnalyzerThis will import the
StemmingAnalyzerclass so that you can use it in your schema definition.Then, you can modify your schema definition as follows:
schema = Schema(id=ID(stored=True), task=TEXT(stored=True, analyzer=StemmingAnalyzer()), answer=TEXT(stored=True), topics_name = TEXT(stored=True))This will apply the stemming analyzer to the
taskfield, which will break down words into their root form and remove any suffixes. This can improve the accuracy of your search results. - User
AttributeError: ‘TEXT’ object has no attribute ‘taggers’ line 575, in query = QueryParser(‘task’,‘topics_name’, ix.schema).parse(‘Умножение и деление’)
- Assistant
The error message
'TEXT' object has no attribute 'taggers'"indicates that you are trying to access thetaggersattribute on a 'TEXT' object, which does not have this attribute.One possible cause of this error is that you have not specified an analyzer for the
topics_namefield in your schema. Thetaggersattribute is used by theQueryParserto choose the appropriate analyzer for each field, and if you do not specify an analyzer, this attribute will not be present.To fix this error, you need to specify an analyzer for the
topics_namefield in your schema. For example, you can use theStandardAnalyzer, which is a basic analyzer that separates text into tokens based on whitespace and punctuation:from whoosh.analysis import StandardAnalyzer schema = Schema(id=ID(stored=True), task=TEXT(stored=True), answer=TEXT(stored=True), topics_name=TEXT(stored=True, analyzer=StandardAnalyzer()))By specifying an analyzer for the
topics_namefield, you should now be able to use theQueryParserto search this field without encountering the error. - User
AttributeError: 'TEXT' object has no attribute 'taggers'
- Assistant
This error usually occurs when you try to use a text field in a search query without specifying an analyzer for it in your schema. In particular, the error message
'TEXT' object has no attribute 'taggers'"suggests that theQueryParseris trying to apply an analyzer to aTEXTfield, but the field does not have an analyzer defined.To fix this error, you need to add an analyzer to your
TEXTfield in your schema definition. You can use one of the available analyzers provided by Whoosh, such as theStemmingAnalyzerorStandardAnalyzer.For example, you can modify your schema definition as follows to add a
StemmingAnalyzerto thetaskandtopics_namefields:from whoosh.analysis import StemmingAnalyzer schema = Schema(id=ID(stored=True), task=TEXT(stored=True, analyzer=StemmingAnalyzer()), answer=TEXT(stored=True), topics_name=TEXT(stored=True, analyzer=StemmingAnalyzer()))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.