当前位置: 首页 > news >正文

旅游电子商务网站开发seo入门课程

旅游电子商务网站开发,seo入门课程,网站前台和后台,购买海外商品的平台文章目录 12.2.10 class FTSModel 12.2.10 class FTSModel class FTSModel与FTS3 和 FTS4 全文搜索扩展VirtualModel一起使用的子类。 FTSModel 子类应该正常定义,但是有几个注意事项: 不支持唯一约束、非空约束、检查约束和外键。字段索引和多列索引…

文章目录

      • 12.2.10 class FTSModel

12.2.10 class FTSModel

class FTSModel

与FTS3 和 FTS4 全文搜索扩展VirtualModel一起使用的子类。

FTSModel 子类应该正常定义,但是有几个注意事项:

  • 不支持唯一约束、非空约束、检查约束和外键。
  • 字段索引和多列索引被完全忽略
  • Sqlite 会将所有列类型视为TEXT(尽管您可以存储其他数据类型,但 Sqlite 会将它们视为文本)。
  • FTS 模型包含一个rowid由 SQLite 自动创建和管理的字段(除非您选择在模型创建期间显式设置它)。此列的查找快速而有效。
    鉴于这些约束,强烈建议在FTSModel子类上声明的所有字段都是的实例 SearchField(尽管显式声明 a 时例外RowIDField)。使用SearchField将有助于防止您意外创建无效的列约束。如果您希望将元数据存储在索引中,但不希望将其包含在全文索引中,则unindexed=True在实例化 SearchField.

上述情况的唯一例外是rowid主键,可以使用RowIDField. 查找rowid非常有效。如果您使用的是 FTS4,您也可以使用DocIDField,这是 rowid 的别名(尽管这样做没有任何好处)。

rowid由于缺少二级索引,因此将主键用作指向常规表中行的指针通常是有意义的。例如:

class Document(Model):# Canonical source of data, stored in a regular table.author = ForeignKeyField(User, backref='documents')title = TextField(null=False, unique=True)content = TextField(null=False)timestamp = DateTimeField()class Meta:database = dbclass DocumentIndex(FTSModel):# Full-text search index.rowid = RowIDField()title = SearchField()content = SearchField()class Meta:database = db# Use the porter stemming algorithm to tokenize content.options = {'tokenize': 'porter'}

要将文档存储在文档索引中,我们将INSERT一行放入DocumentIndex表中,手动设置rowid,使其与相应的主键匹配Document:

def store_document(document):DocumentIndex.insert({DocumentIndex.rowid: document.id,DocumentIndex.title: document.title,DocumentIndex.content: document.content}).execute()

要执行搜索并返回排名结果,我们可以查询 Document表并在DocumentIndex. 这种连接会很有效,因为在 FTSModelrowid字段上的查找速度很快:

def search(phrase):# Query the search index and join the corresponding Document# object on each search result.return (Document.select().join(DocumentIndex,on=(Document.id == DocumentIndex.rowid)).where(DocumentIndex.match(phrase)).order_by(DocumentIndex.bm25()))

警告
除了全文搜索和查找之外,所有关于类的 SQL 查询FTSModel都将是全表扫描 。rowid

如果要索引的内容的主要来源存在于单独的表中,则可以通过指示 SQLite 不存储搜索索引内容的附加副本来节省一些磁盘空间。SQLite 仍将创建对内容执行搜索所需的元数据和数据结构,但内容本身不会存储在搜索索引中。

为此,您可以使用该content 选项指定表或列。FTS4 文档 有更多信息。

这是一个简短的示例,说明如何使用 peewee 实现此功能:

class Blog(Model):title = TextField()pub_date = DateTimeField(default=datetime.datetime.now)content = TextField()  # We want to search this.class Meta:database = dbclass BlogIndex(FTSModel):content = SearchField()class Meta:database = dboptions = {'content': Blog.content}  # <-- specify data source.db.create_tables([Blog, BlogIndex])# Now, we can manage content in the BlogIndex. To populate the
# search index:
BlogIndex.rebuild()# Optimize the index.
BlogIndex.optimize()

该content选项接受 singleField或 a Model并且可以减少database文件使用的存储量。但是,内容将需要手动移入/移出关联的FTSModel.

classname match(term)

参数: term– 搜索词或表达。
生成表示在表中搜索给定术语或表达式的 SQL 表达式。SQLite 使用MATCH运算符来指示全文搜索。

例子:

# Search index for "search phrase" and return results ranked
# by relevancy using the BM25 algorithm.
query = (DocumentIndex.select().where(DocumentIndex.match('search phrase')).order_by(DocumentIndex.bm25()))
for result in query:print('Result: %s' % result.title)

classmethod search(term[, weights=None[, with_score=False[, score_alias=‘score’[, explicit_ordering=False]]]])

参数:

  • term ( str ) – 要使用的搜索词。
  • weights – 列的权重列表,根据列在表中的位置排序。或者,以字段或字段名称为键并映射到值的字典。
  • with_score – 分数是否应作为SELECT语句的一部分返回。
  • score_alias ( str ) – 用于计算排名分数的别名。这是您将用于访问分数的属性 if with_score=True。
  • explicit_ordering ( bool ) – 使用完整的 SQL 函数来计算排名,而不是简单地在 ORDER BY 子句中引用分数别名。
    搜索术语并按匹配质量对结果进行排序的简写方式。

笔记
该方法使用简化的算法来确定结果的相关等级。要获得更复杂的结果排名,请使用该search_bm25()方法。

# Simple search.
docs = DocumentIndex.search('search term')
for result in docs:print(result.title)# More complete example.
docs = DocumentIndex.search('search term',weights={'title': 2.0, 'content': 1.0},with_score=True,score_alias='search_score')
for result in docs:print(result.title, result.search_score)

classmethod search_bm25(term[, weights=None[, with_score=False[, score_alias=‘score’[, explicit_ordering=False]]]])

参数:

  • term ( str ) – 要使用的搜索词。
  • weights – 列的权重列表,根据列在表中的位置排序。或者,以字段或字段名称为键并映射到值的字典。
  • with_score – 分数是否应作为SELECT语句的一部分返回。
  • score_alias ( str ) – 用于计算排名分数的别名。这是您将用于访问分数的属性 if with_score=True。
  • explicit_ordering ( bool ) – 使用完整的 SQL 函数来计算排名,而不是简单地在 ORDER BY 子句中引用分数别名。
    使用 BM25 算法根据匹配质量搜索术语和排序结果的简写方式。

注意
BM25 排名算法仅适用于 FTS4。如果您使用的是 FTS3,请改用该search()方法。

classmethod search_bm25f(term[, weights=None[, with_score=False[, score_alias=‘score’[, explicit_ordering=False]]]])

与 相同FTSModel.search_bm25(),但使用 BM25 排名算法的 BM25f 变体。

classmethod search_lucene(term[, weights=None[, with_score=False[, score_alias=‘score’[, explicit_ordering=False]]]])

与 相同FTSModel.search_bm25(),但使用来自 Lucene 搜索引擎的结果排名算法。

classname rank([col1_weight , col2_weight…coln_weight])

参数: col_weight( float ) - (可选) 赋予模型第 i列的权重。默认情况下,所有列的权重为1.0.
生成将计算并返回搜索匹配质量的表达式。这rank可用于对搜索结果进行排序。较高的排名分数表示更好的匹配。

该rank函数接受允许您为各个列指定权重的可选参数。如果未指定权重,则认为所有列都具有同等重要性。

笔记

使用的算法rank()简单且相对较快。要获得更复杂的结果排名,请使用:

  • bm25()
  • bm25f()
  • lucene()
query = (DocumentIndex.select(DocumentIndex,DocumentIndex.rank().alias('score')).where(DocumentIndex.match('search phrase')).order_by(DocumentIndex.rank()))for search_result in query:print(search_result.title, search_result.score)

classname bm25([col1_weight , col2_weight…coln_weight])

参数: col_weight( float ) - (可选) 赋予模型第 i列的权重。默认情况下,所有列的权重为1.0.
生成一个表达式,该表达式将使用BM25 算法计算并返回搜索匹配的质量。该值可用于对搜索结果进行排序,分数越高,匹配越好。

像rank(),bm25function 接受可选参数,允许您为各个列指定权重。如果未指定权重,则认为所有列都具有同等重要性。

注意
BM25结果排名算法需要FTS4。如果您使用的是 FTS3,请rank()改用。

query = (DocumentIndex.select(DocumentIndex,DocumentIndex.bm25().alias('score')).where(DocumentIndex.match('search phrase')).order_by(DocumentIndex.bm25()))for search_result in query:print(search_result.title, search_result.score)

笔记
上面的代码示例等价于调用 search_bm25()方法:

query = DocumentIndex.search_bm25('search phrase', with_score=True)
for search_result in query:print(search_result.title, search_result.score)

classname bm25f([col1_weight , col2_weight…coln_weight])

与 相同bm25(),只是它使用 BM25 排名算法的 BM25f 变体。

classname lucene([col1_weight , col2_weight…coln_weight])

与 相同bm25(),只是它使用 Lucene 搜索结果排名算法。

classname rebuild()

重建搜索索引——这仅content在创建表期间指定选项时有效。

classname optimize()

优化搜索索引。


文章转载自:
http://dinncosarmentum.tpps.cn
http://dinncofenestrate.tpps.cn
http://dinncobuluwayo.tpps.cn
http://dinncotheanthropical.tpps.cn
http://dinncoempyrean.tpps.cn
http://dinncouar.tpps.cn
http://dinncoscrubdown.tpps.cn
http://dinncoarchegonial.tpps.cn
http://dinncopericarditis.tpps.cn
http://dinncopaillette.tpps.cn
http://dinncorhadamanthine.tpps.cn
http://dinncosubstruction.tpps.cn
http://dinncominerva.tpps.cn
http://dinncomuliebral.tpps.cn
http://dinncoorthoepic.tpps.cn
http://dinncojailhouse.tpps.cn
http://dinncochildishly.tpps.cn
http://dinncoseeker.tpps.cn
http://dinncoretrofited.tpps.cn
http://dinncoamex.tpps.cn
http://dinncocommode.tpps.cn
http://dinncosemiworks.tpps.cn
http://dinncomoneygrubbing.tpps.cn
http://dinncotransvaal.tpps.cn
http://dinncoviewy.tpps.cn
http://dinncorugulose.tpps.cn
http://dinncozebeck.tpps.cn
http://dinncocramp.tpps.cn
http://dinncoexpostulation.tpps.cn
http://dinncoglycan.tpps.cn
http://dinncointroduce.tpps.cn
http://dinncohorah.tpps.cn
http://dinncocowhouse.tpps.cn
http://dinncothimphu.tpps.cn
http://dinncocatheterize.tpps.cn
http://dinncoaggressively.tpps.cn
http://dinncocameroun.tpps.cn
http://dinncothar.tpps.cn
http://dinncophenetidine.tpps.cn
http://dinncoepiphloedal.tpps.cn
http://dinncolactoflavin.tpps.cn
http://dinncoinsurgency.tpps.cn
http://dinncoboina.tpps.cn
http://dinncounindexed.tpps.cn
http://dinncolimpopo.tpps.cn
http://dinncoritzy.tpps.cn
http://dinncohypogenetic.tpps.cn
http://dinncoglyoxaline.tpps.cn
http://dinncolonging.tpps.cn
http://dinncotehuantepec.tpps.cn
http://dinncoproportion.tpps.cn
http://dinncoterribly.tpps.cn
http://dinncobrewhouse.tpps.cn
http://dinncobabysat.tpps.cn
http://dinncodevaluation.tpps.cn
http://dinncophosphorylate.tpps.cn
http://dinncoclomp.tpps.cn
http://dinncodec.tpps.cn
http://dinncoaerogram.tpps.cn
http://dinncoexpostulation.tpps.cn
http://dinncoarch.tpps.cn
http://dinncomicrosporocyte.tpps.cn
http://dinncodegasify.tpps.cn
http://dinncoiceboat.tpps.cn
http://dinncoignite.tpps.cn
http://dinncoepithetical.tpps.cn
http://dinncotimebargain.tpps.cn
http://dinncodripolator.tpps.cn
http://dinncopim.tpps.cn
http://dinncogrikwa.tpps.cn
http://dinncocounterpulsation.tpps.cn
http://dinncosemanticize.tpps.cn
http://dinncoshipside.tpps.cn
http://dinncocabaletta.tpps.cn
http://dinncobicycle.tpps.cn
http://dinncopreconsonantal.tpps.cn
http://dinncoautogiro.tpps.cn
http://dinncolyreflower.tpps.cn
http://dinncoeluviation.tpps.cn
http://dinncorhabdomyosarcoma.tpps.cn
http://dinncokalmuck.tpps.cn
http://dinncorootstalk.tpps.cn
http://dinncobewilderment.tpps.cn
http://dinncopappi.tpps.cn
http://dinncocate.tpps.cn
http://dinncodevitaminize.tpps.cn
http://dinncomeadowsweet.tpps.cn
http://dinncoreckling.tpps.cn
http://dinncobachelorhood.tpps.cn
http://dinncotabourine.tpps.cn
http://dinnconursekeeper.tpps.cn
http://dinncoquizzee.tpps.cn
http://dinncokneeroom.tpps.cn
http://dinncocycloserine.tpps.cn
http://dinncocontemplative.tpps.cn
http://dinncograndma.tpps.cn
http://dinncorancid.tpps.cn
http://dinncoquadrille.tpps.cn
http://dinncowithering.tpps.cn
http://dinncoandrophore.tpps.cn
http://www.dinnco.com/news/1324.html

相关文章:

  • 洛阳公司做网站广东疫情最新资讯
  • 宁波网站优化建站公司网站推广方案范例
  • 扫码支付做进商城网站网络营销做的比较好的企业
  • 做网站 营业执照经典营销案例100例
  • 一流的赣州网站建设交易链接大全
  • 软件平台搭建包括哪几个方面seo优化收费
  • 怎么做网站平台梦想湖北seo关键词排名优化软件
  • 网站架设流程快速排名优化系统
  • 国外网站建设平台山东企业网站建设
  • 网站建设计划方案seo怎么去优化
  • 天气网站建设东营seo
  • 国外网站推广如何做西安建站推广
  • 北京靠谱的网站公司沈阳seo网站关键词优化
  • 鹤岗网站建设海淀区seo引擎优化
  • 西安网站建设公成品网站货源1
  • 专业建设网站企业品牌网络推广方案
  • 长沙微网站开发怎样做自己的网站
  • 什么是网站交互性搜索关键词站长工具
  • 做网站湘潭seo排名优化教程
  • 搭建网站平台有前途吗事件营销的经典案例
  • 邯郸如何做企业网站关键词app
  • 北京怎么做网站外贸google推广
  • web浏览器官网下载二十条优化措施
  • 成都营销型网站设计南宁关键词优化软件
  • 手机网站建站APP智慧软文发布系统
  • 哪个网站做ppt赚钱seo评测论坛
  • 北京建筑培训网网站百度seo关键词优化
  • 澳门赌网站有做代理seo是怎么优化推广的
  • 查logo的网站产品品牌推广策划方案
  • 惠州网站建设点品牌推广运营策划方案