Designing a schema
设计一个架构
About schemas and fields
关于架构和字段
The schema specifies the fields of documents in an index.
架构指定索引中的文件字段。
Each document can have multiple fields, such as title, content, url, date, etc.
每一个文件可以有多个字段,好比标题,内容,url,日期等等。
Some fields can be indexed, and some fields can be stored with the document so the field value is available in search results. Some fields will be both indexed and stored.
有些字段可以被索引,有些字段可以和文件一起被存储起来,这样字段的值可用于查询结果。有些字段将会被索引和存储。
The schema is the set of all possible fields in a document. Each individual document might only use a subset of the available fields in the schema.
架构是文件里面所有的可选字段的集合。每一个文件可能只使用架构里面可用字段的子集。
For example, a simple schema for indexing emails might have fields like
from_addr,to_addr,subject,body, andattachments, where theattachmentsfield lists the names of attachments to the email. For emails without attachments, you would omit the attachments field.
举一个例子,对于索引邮件一个简单的架构可能有这些字段 “from_addr”,“to_addr”,“subject”,“body”,“attachments”.其中attachments字段列出了邮件附件的名字。对于emails没有附件的情况,你可以忽略附件这个字段。
Built-in field types(内建字段类型)
Whoosh provides some useful predefined field types:
whoosh提供了一些有用的提前定义好的字段类型。
whoosh.fields.TEXT
This type is for body text. It indexes (and optionally stores) the text and stores term positions to allow phrase searching.
这种类型是用于正文的。它索引(可选是否存储)文本和存储短语位置来允许短语查询。
TEXTfields useStandardAnalyzerby default. To specify a different analyzer, use theanalyzerkeyword argument to the constructor, e.g.TEXT(analyzer=analysis.StemmingAnalyzer())See About analyzers
TEXT字段使用StandardAnalyzer默认标准分析器的方式。
为了指定不同的分析器,使用构造函数里面的分析器关键字。举例TEXT(analyzer=analysis.StemmingAnalyzer()),点击后会跳转官方文档,后面翻译了当前文章后再回来更新链接
By default, TEXT fields store position information for each indexed term, to allow you to search for phrases. If you don’t need to be able to search for phrases in a text field, you can turn off storing term positions to save space. Use TEXT(phrase=False).
默认的,TEXT字段会为每一个被索引的术语存储位置信息,来允许你按短语进行查询。如果你不需要在TEXT字段里面按短语查询,你可以关闭存储位置术语来节省空间,使用TEXT(phrase=False)
By default, TEXT fields are not stored. Usually you will not want to store the body text in the search index. Usually you have the indexed documents themselves available to read or link to based on the search results, so you don’t need to store their text in the search index. However, in some circumstances it can be useful (see How to create highlighted search result excerpts). Use TEXT(stored=True) to specify that the text should be stored in the index.
circumstances 情况
默认的,TEXT字段也不会存储。通常你不会想存储正文在查询索引里面。通常你有一个被索引的文档来允许读或者链接到搜索结果上,你不需要存储它们的文本在一个查询索引中。然而,在某些情况下,它将会非常有用(请参阅如何去创建一个查询结果的部分高亮)使用TEXT(stored=True)来指定text是不是应该被存储在索引中。
3万+



被折叠的 条评论
为什么被折叠?



