You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import logging
from django import forms
from haystack . forms import SearchForm
logger = logging . getLogger ( __name__ )
class BlogSearchForm ( SearchForm ) :
"""
mk:
博客搜索表单类
继承自haystack的SearchForm, 添加了自定义的查询字段和搜索逻辑
"""
querydata = forms . CharField ( required = True )
def search ( self ) :
"""
mk:
执行搜索操作
首先调用父类的搜索方法获取基础搜索结果,然后验证表单数据的有效性,
如果表单数据有效且查询数据存在,则记录查询日志
Returns:
搜索结果数据集
"""
# mk:调用父类的搜索方法获取基础搜索结果
datas = super ( BlogSearchForm , self ) . search ( )
# mk:验证表单数据,如果无效则返回无查询结果
if not self . is_valid ( ) :
return self . no_query_found ( )
# mk:如果查询数据存在,记录查询日志
if self . cleaned_data [ ' querydata ' ] :
logger . info ( self . cleaned_data [ ' querydata ' ] )
return datas