本文整理汇总了Golang中github.com/blevesearch/bleve.NewDocumentMapping函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDocumentMapping函数的具体用法?Golang NewDocumentMapping怎么用?Golang NewDocumentMapping使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDocumentMapping函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: buildIndexMapping
func buildIndexMapping() *bleve.IndexMapping {
enTextFieldMapping := bleve.NewTextFieldMapping()
enTextFieldMapping.Analyzer = textFieldAnalyzer
storeFieldOnlyMapping := bleve.NewTextFieldMapping()
storeFieldOnlyMapping.Index = false
storeFieldOnlyMapping.IncludeTermVectors = false
storeFieldOnlyMapping.IncludeInAll = false
dateTimeMapping := bleve.NewDateTimeFieldMapping()
wikiMapping := bleve.NewDocumentMapping()
wikiMapping.AddFieldMappingsAt("name", enTextFieldMapping)
wikiMapping.AddFieldMappingsAt("body", enTextFieldMapping)
wikiMapping.AddFieldMappingsAt("modified_by", enTextFieldMapping)
wikiMapping.AddFieldMappingsAt("modified_by_name", enTextFieldMapping)
wikiMapping.AddFieldMappingsAt("modified_by_email", enTextFieldMapping)
wikiMapping.AddFieldMappingsAt("modified_by_avatar", storeFieldOnlyMapping)
wikiMapping.AddFieldMappingsAt("modified", dateTimeMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("wiki", wikiMapping)
indexMapping.DefaultAnalyzer = textFieldAnalyzer
return indexMapping
}
开发者ID:pedronasser,项目名称:bleve-wiki-indexer,代码行数:28,代码来源:mapping.go
示例2: BuildArticleMapping
// BuildArticleMapping returns a mapping for indexing wikipedia articles
// in a manner similar to that done by lucene nightly benchmarks
func BuildArticleMapping() *bleve.IndexMapping {
// a generic reusable mapping for english text
standardJustIndexed := bleve.NewTextFieldMapping()
standardJustIndexed.Store = false
standardJustIndexed.IncludeInAll = false
standardJustIndexed.IncludeTermVectors = false
standardJustIndexed.Analyzer = "standard"
keywordJustIndexed := bleve.NewTextFieldMapping()
keywordJustIndexed.Store = false
keywordJustIndexed.IncludeInAll = false
keywordJustIndexed.IncludeTermVectors = false
keywordJustIndexed.Analyzer = "keyword"
articleMapping := bleve.NewDocumentMapping()
// title
articleMapping.AddFieldMappingsAt("title",
keywordJustIndexed)
// text
articleMapping.AddFieldMappingsAt("text",
standardJustIndexed)
// _all (disabled)
disabledSection := bleve.NewDocumentDisabledMapping()
articleMapping.AddSubDocumentMapping("_all", disabledSection)
indexMapping := bleve.NewIndexMapping()
indexMapping.DefaultMapping = articleMapping
indexMapping.DefaultAnalyzer = "standard"
return indexMapping
}
开发者ID:steveyen,项目名称:bleve-bench,代码行数:37,代码来源:mapping.go
示例3: getIndexMapping
// Returns data model for index
func getIndexMapping() *bv.IndexMapping {
indexMapping := bv.NewIndexMapping()
messageMapping := bv.NewDocumentStaticMapping()
// Will search exact string, e.g.: «hostname.example.org» will search for «hostname.example.org»
mappingKeyword := getTextFieldMapping()
mappingKeyword.Analyzer = bvKeywordAnalyzer.Name
// Tokenized query, e.g.: «hostname example org» will search for «hostname», «example» or «org»
mappingText := getTextFieldMapping()
mappingText.Analyzer = bvStandardAnalyzer.Name
messageMapping.AddFieldMappingsAt("version", mappingKeyword)
messageMapping.AddFieldMappingsAt("host", mappingKeyword)
messageMapping.AddFieldMappingsAt("short_message", mappingText)
messageMapping.AddFieldMappingsAt("full_message", mappingText)
messageMapping.AddFieldMappingsAt("timestamp", bv.NewDateTimeFieldMapping())
messageMapping.AddFieldMappingsAt("level", bv.NewNumericFieldMapping())
messageMapping.AddFieldMappingsAt("facility", mappingKeyword)
messageMapping.AddSubDocumentMapping("extra", bv.NewDocumentMapping())
indexMapping.AddDocumentMapping(DOC_TYPE, messageMapping)
return indexMapping
}
开发者ID:endeveit,项目名称:recause,代码行数:26,代码来源:bleve.go
示例4: buildIndexMapping
func buildIndexMapping() (*bleve.IndexMapping, error) {
// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = "en"
// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = "keyword"
// a specific mapping to index the description fields
// detected language
descriptionLangFieldMapping := bleve.NewTextFieldMapping()
descriptionLangFieldMapping.Name = "descriptionLang"
descriptionLangFieldMapping.Analyzer = "detect_lang"
descriptionLangFieldMapping.Store = false
descriptionLangFieldMapping.IncludeTermVectors = false
descriptionLangFieldMapping.IncludeInAll = false
beerMapping := bleve.NewDocumentMapping()
// name
beerMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
// description
beerMapping.AddFieldMappingsAt("description",
englishTextFieldMapping,
descriptionLangFieldMapping)
beerMapping.AddFieldMappingsAt("type", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("style", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("category", keywordFieldMapping)
breweryMapping := bleve.NewDocumentMapping()
breweryMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
breweryMapping.AddFieldMappingsAt("description", englishTextFieldMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("beer", beerMapping)
indexMapping.AddDocumentMapping("brewery", breweryMapping)
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = "en"
return indexMapping, nil
}
开发者ID:nerdpanda,项目名称:beer-search,代码行数:46,代码来源:mapping.go
示例5: Init
func Init(allDocs GetAllDocsFn) {
var err error
idx_path := path.Join(config.Current.DataDir, index_name)
index, err = bleve.Open(idx_path)
if err == bleve.ErrorIndexPathDoesNotExist {
log.Info("Creating new Index")
indexMapping := bleve.NewIndexMapping()
indexMapping.DefaultAnalyzer = config.Current.DefaultAnalyzer
entryMapping := bleve.NewDocumentMapping()
textField := bleve.NewTextFieldMapping()
entryMapping.AddFieldMappingsAt("Body", textField)
entryMapping.AddFieldMappingsAt("Title", textField)
tagField := bleve.NewTextFieldMapping()
tagField.Analyzer = tag_analyzer
entryMapping.AddFieldMappingsAt("Tags", tagField)
indexMapping.AddDocumentMapping("entry", entryMapping)
index, err = bleve.New(idx_path, indexMapping)
if err != nil {
log.Fatal(err)
}
// reindex existing documents
indexRebuildingLogged := false
for itm := range allDocs() {
if !indexRebuildingLogged {
indexRebuildingLogged = true
log.Info("Start rebuilding Search-Index")
}
index.Index(itm.Id(), itm.Content())
}
if indexRebuildingLogged {
log.Info("Finished rebuilding Search-Index")
}
} else if err == nil {
log.Info("Opening existing Index")
} else {
log.Fatal(err)
}
}
开发者ID:oblank,项目名称:knowledgedb,代码行数:50,代码来源:index.go
示例6: buildIndexMapping
func buildIndexMapping() (*bleve.IndexMapping, error) {
var err error
// Create the index mapping, configure the analyzer, and set as default.
indexMapping := bleve.NewIndexMapping()
err = indexMapping.AddCustomTokenizer("ekanite_tk",
map[string]interface{}{
"regexp": `[^\W_]+`,
"type": regexp_tokenizer.Name,
})
if err != nil {
return nil, err
}
err = indexMapping.AddCustomAnalyzer("ekanite",
map[string]interface{}{
"type": custom_analyzer.Name,
"char_filters": []interface{}{},
"tokenizer": `ekanite_tk`,
"token_filters": []interface{}{`to_lower`},
})
if err != nil {
return nil, err
}
indexMapping.DefaultAnalyzer = "ekanite"
// Create field-specific mappings.
simpleJustIndexed := bleve.NewTextFieldMapping()
simpleJustIndexed.Store = false
simpleJustIndexed.IncludeInAll = true // XXX Move to false when using AST
simpleJustIndexed.IncludeTermVectors = false
timeJustIndexed := bleve.NewDateTimeFieldMapping()
timeJustIndexed.Store = false
timeJustIndexed.IncludeInAll = false
timeJustIndexed.IncludeTermVectors = false
articleMapping := bleve.NewDocumentMapping()
// Connect field mappings to fields.
articleMapping.AddFieldMappingsAt("Message", simpleJustIndexed)
articleMapping.AddFieldMappingsAt("ReferenceTime", timeJustIndexed)
articleMapping.AddFieldMappingsAt("ReceptionTime", timeJustIndexed)
// Tell the index about field mappings.
indexMapping.DefaultMapping = articleMapping
return indexMapping, nil
}
开发者ID:tjyang,项目名称:ekanite,代码行数:50,代码来源:index.go
示例7: buildIndexMapping
func buildIndexMapping() (*bleve.IndexMapping, error) {
// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = en.AnalyzerName
// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = keyword_analyzer.Name
beerMapping := bleve.NewDocumentMapping()
// name
beerMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
// description
beerMapping.AddFieldMappingsAt("description",
englishTextFieldMapping)
beerMapping.AddFieldMappingsAt("type", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("style", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("category", keywordFieldMapping)
breweryMapping := bleve.NewDocumentMapping()
breweryMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
breweryMapping.AddFieldMappingsAt("description", englishTextFieldMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("beer", beerMapping)
indexMapping.AddDocumentMapping("brewery", breweryMapping)
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = "en"
return indexMapping, nil
}
开发者ID:Xackery,项目名称:beer-search,代码行数:36,代码来源:mapping.go
示例8: buildIndexMapping
func buildIndexMapping() *bleve.IndexMapping {
// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = en.AnalyzerName
// RecipeLink
linkMapping := bleve.NewDocumentMapping()
linkMapping.AddFieldMappingsAt("title", englishTextFieldMapping)
linkMapping.AddFieldMappingsAt("description", englishTextFieldMapping)
linkMapping.AddFieldMappingsAt("url", englishTextFieldMapping)
// Recipe
recipeMapping := bleve.NewDocumentMapping()
recipeMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
recipeMapping.AddFieldMappingsAt("description", englishTextFieldMapping)
recipeMapping.AddFieldMappingsAt("author", englishTextFieldMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.DefaultAnalyzer = "en"
indexMapping.AddDocumentMapping("title", linkMapping)
//indexMapping.AddDocumentMapping("recipe", recipeMapping)
return indexMapping
}
开发者ID:gophergala2016,项目名称:recipe,代码行数:24,代码来源:blevecache.go
示例9: NewSearchIndex
func NewSearchIndex(repo content.Repo, config Config, logger webfw.Logger) (SearchIndex, error) {
var err error
var index bleve.Index
si := SearchIndex{}
_, err = os.Stat(config.SearchIndex.BlevePath)
if err == nil {
logger.Infoln("Opening search index " + config.SearchIndex.BlevePath)
index, err = bleve.Open(config.SearchIndex.BlevePath)
if err != nil {
return EmptySearchIndex, errors.New(fmt.Sprintf("Error opening search index: %v\n", err))
}
} else if os.IsNotExist(err) {
mapping := bleve.NewIndexMapping()
docMapping := bleve.NewDocumentMapping()
idfieldmapping := bleve.NewTextFieldMapping()
idfieldmapping.IncludeInAll = false
docMapping.AddFieldMappingsAt("FeedId", idfieldmapping)
docMapping.AddFieldMappingsAt("ArticleId", idfieldmapping)
mapping.AddDocumentMapping(mapping.DefaultType, docMapping)
logger.Infoln("Creating search index " + config.SearchIndex.BlevePath)
index, err = bleve.New(config.SearchIndex.BlevePath, mapping)
if err != nil {
return EmptySearchIndex, errors.New(fmt.Sprintf("Error creating search index: %v\n", err))
}
si.newIndex = true
} else {
return EmptySearchIndex, errors.New(
fmt.Sprintf("Error getting stat of '%s': %v\n", config.SearchIndex.BlevePath, err))
}
si.logger = logger
si.repo = repo
si.Index = index
si.batchSize = config.SearchIndex.BatchSize
return si, nil
}
开发者ID:RavenB,项目名称:readeef,代码行数:45,代码来源:search_index.go
示例10: buildIndexMapping
func buildIndexMapping() *bleve.IndexMapping {
// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = "keyword"
torrentMapping := bleve.NewDocumentMapping()
torrentMapping.AddFieldMappingsAt("category", keywordFieldMapping)
im := bleve.NewIndexMapping()
im.AddDocumentMapping("torrent", torrentMapping)
im.TypeField = "type"
im.DefaultAnalyzer = "standard"
im.DefaultType = "torrent"
im.DefaultField = "name"
return im
}
开发者ID:thomasmodeneis,项目名称:tpb-search,代码行数:18,代码来源:index.go
示例11: buildIndexMapping
func buildIndexMapping(language string) *bleve.IndexMapping {
txtMapping := bleve.NewTextFieldMapping()
txtMapping.Analyzer = language
storeFieldOnlyMapping := bleve.NewTextFieldMapping()
storeFieldOnlyMapping.Index = false
storeFieldOnlyMapping.IncludeTermVectors = false
storeFieldOnlyMapping.IncludeInAll = false
docMapping := bleve.NewDocumentMapping()
docMapping.AddSubDocumentMapping("id", bleve.NewDocumentDisabledMapping())
docMapping.AddFieldMappingsAt("content", txtMapping)
docMapping.AddFieldMappingsAt("title", txtMapping)
docMapping.AddFieldMappingsAt("data", storeFieldOnlyMapping)
mapping := bleve.NewIndexMapping()
mapping.AddDocumentMapping("doc", docMapping)
mapping.DefaultAnalyzer = language
return mapping
}
开发者ID:piger,项目名称:corpus,代码行数:20,代码来源:index.go
示例12: buildIndexMapping
func buildIndexMapping() (*bleve.IndexMapping, error) {
zlmapping := bleve.NewDocumentMapping()
fulltext := bleve.NewTextFieldMapping()
fulltext.Name = "fulltext"
fulltext.Analyzer = "gojieba"
zlmapping.AddFieldMappingsAt("F_ApplicationNo", fulltext)
zlmapping.AddFieldMappingsAt("F_PatentName", fulltext)
zlmapping.AddFieldMappingsAt("F_Inventor", fulltext)
zlmapping.AddFieldMappingsAt("F_Applicant", fulltext)
zlmapping.AddFieldMappingsAt("F_AreaCode", fulltext)
zlmapping.AddFieldMappingsAt("F_ApplicantAddress", fulltext)
zlmapping.AddFieldMappingsAt("W_WoAppCode", fulltext)
zlmapping.AddFieldMappingsAt("F_Abstract", fulltext)
zlmapping.AddFieldMappingsAt("F_Cite", fulltext)
zlmapping.AddFieldMappingsAt("W_ReprintPatent", fulltext)
zlmapping.AddFieldMappingsAt("F_SignoryItem", fulltext)
zlmapping.AddFieldMappingsAt("F_PatentName", fulltext)
indexMapping.AddDocumentMapping("zl", zlmapping)
return indexMapping, nil
}
开发者ID:yourhe,项目名称:gojieba,代码行数:21,代码来源:mapping.go
示例13: openIndex
func openIndex(name string) (bleve.Index, error) {
textFieldMapping := bleve.NewTextFieldMapping()
doc := bleve.NewDocumentMapping()
doc.AddFieldMappingsAt("name", textFieldMapping)
doc.AddFieldMappingsAt("body", textFieldMapping)
doc.AddFieldMappingsAt("modied", textFieldMapping)
indexMap := bleve.NewIndexMapping()
indexMap.AddDocumentMapping("document", doc)
blv, err := bleve.New(name, indexMap)
if err != nil {
blv, err = bleve.Open(name)
if err != nil {
return nil, err
}
}
return blv, nil
}
开发者ID:guilhermebr,项目名称:caddy-search,代码行数:22,代码来源:bleve.go
示例14: NewBleve
func NewBleve(path string, size int64, logger webfw.Logger) (content.SearchProvider, error) {
var err error
var exists bool
var index bleve.Index
_, err = os.Stat(path)
if err == nil {
logger.Infoln("Opening search index " + path)
index, err = bleve.Open(path)
if err != nil {
return nil, errors.New(fmt.Sprintf("Error opening search index: %v\n", err))
}
exists = true
} else if os.IsNotExist(err) {
mapping := bleve.NewIndexMapping()
docMapping := bleve.NewDocumentMapping()
idfieldmapping := bleve.NewTextFieldMapping()
idfieldmapping.IncludeInAll = false
docMapping.AddFieldMappingsAt("FeedId", idfieldmapping)
docMapping.AddFieldMappingsAt("ArticleId", idfieldmapping)
mapping.AddDocumentMapping(mapping.DefaultType, docMapping)
logger.Infoln("Creating search index " + path)
index, err = bleve.NewUsing(path, mapping, upside_down.Name, goleveldb.Name, nil)
if err != nil {
return nil, errors.New(fmt.Sprintf("Error creating search index: %v\n", err))
}
} else {
return nil, errors.New(
fmt.Sprintf("Error getting stat of '%s': %v\n", path, err))
}
return &Bleve{logger: logger, index: index, batchSize: size, newIndex: !exists}, nil
}
开发者ID:urandom,项目名称:readeef,代码行数:39,代码来源:bleve.go
示例15: main
func main() {
flag.Parse()
if *path == "" {
log.Fatal("provide a zim file path")
}
z, err := zim.NewReader(*path, false)
if err != nil {
log.Fatal(err)
}
if *indexPath == "" {
log.Fatal("Please provide a path for the index")
}
switch *lang {
case "en":
//TODO: create a simple language support for stop word
default:
log.Fatal("unsupported language")
}
mapping := bleve.NewIndexMapping()
mapping.DefaultType = "Article"
articleMapping := bleve.NewDocumentMapping()
mapping.AddDocumentMapping("Article", articleMapping)
titleMapping := bleve.NewTextFieldMapping()
titleMapping.Store = false
titleMapping.Index = true
titleMapping.Analyzer = "standard"
articleMapping.AddFieldMappingsAt("Title", titleMapping)
fmt.Println(registry.AnalyzerTypesAndInstances())
index, err := bleve.New(*indexPath, mapping)
if err != nil {
log.Fatal(err)
}
i := 0
batch := index.NewBatch()
batchCount := 0
idoc := ArticleIndex{}
divisor := float64(z.ArticleCount) / 100
z.ListTitlesPtrIterator(func(idx uint32) {
if i%*batchSize == 0 {
fmt.Printf("%.2f%% done\n", float64(i)/divisor)
}
a, err := z.ArticleAtURLIdx(idx)
if err != nil || a.EntryType == zim.DeletedEntry {
i++
return
}
if a.Namespace == 'A' {
idoc.Title = a.Title
// index the idoc with the idx as key
batch.Index(fmt.Sprint(idx), idoc)
batchCount++
}
i++
// send a batch to bleve
if batchCount >= *batchSize {
err = index.Batch(batch)
if err != nil {
log.Fatal(err.Error())
}
batch = index.NewBatch()
batchCount = 0
}
})
// batch the rest
if batchCount > 0 {
err = index.Batch(batch)
if err != nil {
log.Fatal(err.Error())
}
}
index.Close()
}
开发者ID:postfix,项目名称:gozim,代码行数:93,代码来源:main.go
示例16: buildIndexMapping
func buildIndexMapping() (*bleve.IndexMapping, error) {
// a custom field definition that uses our custom analyzer
edgeNgram325FieldMapping := bleve.NewTextFieldMapping()
edgeNgram325FieldMapping.Analyzer = "enWithEdgeNgram325"
// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = "en"
// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = "keyword"
// a specific mapping to index the description fields
// detected language
descriptionLangFieldMapping := bleve.NewTextFieldMapping()
descriptionLangFieldMapping.Name = "descriptionLang"
descriptionLangFieldMapping.Analyzer = "detect_lang"
descriptionLangFieldMapping.Store = false
descriptionLangFieldMapping.IncludeTermVectors = false
descriptionLangFieldMapping.IncludeInAll = false
beerMapping := bleve.NewDocumentMapping()
// name
beerMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
// description
beerMapping.AddFieldMappingsAt("description",
edgeNgram325FieldMapping,
descriptionLangFieldMapping)
beerMapping.AddFieldMappingsAt("type", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("style", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("category", keywordFieldMapping)
breweryMapping := bleve.NewDocumentMapping()
breweryMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
breweryMapping.AddFieldMappingsAt("description", englishTextFieldMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("beer", beerMapping)
indexMapping.AddDocumentMapping("brewery", breweryMapping)
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = textFieldAnalyzer
err := indexMapping.AddCustomTokenFilter("edgeNgram325",
map[string]interface{}{
"type": "edge_ngram",
"min": 3.0,
"max": 25.0,
})
if err != nil {
return nil, err
}
err = indexMapping.AddCustomAnalyzer("enWithEdgeNgram325",
map[string]interface{}{
"type": "custom",
"tokenizer": "unicode",
"token_filters": []string{
"possessive_en",
"to_lower",
"stop_en",
"edgeNgram325",
},
})
if err != nil {
return nil, err
}
return indexMapping, nil
}
开发者ID:deepakm,项目名称:beer-search,代码行数:75,代码来源:mapping_example2.go
示例17: getIndex
func getIndex(indexName string) (bleve.Index, error) {
if _, err := os.Stat(indexName); os.IsNotExist(err) {
log.Printf("Creating Bleve index at %s\n", indexName)
log.Println("Setting up index...")
indexMapping := bleve.NewIndexMapping()
// Add Accession as a specific document map
accessionMapping := bleve.NewDocumentMapping()
// Now add specific accession fields
titleMapping := bleve.NewTextFieldMapping()
titleMapping.Analyzer = "en"
titleMapping.Store = true
titleMapping.Index = true
accessionMapping.AddFieldMappingsAt("title", titleMapping)
descriptionMapping := bleve.NewTextFieldMapping()
descriptionMapping.Analyzer = "en"
descriptionMapping.Store = true
descriptionMapping.Index = true
accessionMapping.AddFieldMappingsAt("content_description", descriptionMapping)
subjectsMapping := bleve.NewTextFieldMapping()
subjectsMapping.Analyzer = "en"
subjectsMapping.Store = true
subjectsMapping.Index = true
subjectsMapping.IncludeTermVectors = true
accessionMapping.AddFieldMappingsAt("subjects", subjectsMapping)
subjectsFunctionMapping := bleve.NewTextFieldMapping()
subjectsFunctionMapping.Analyzer = "en"
subjectsFunctionMapping.Store = true
subjectsFunctionMapping.Index = true
subjectsFunctionMapping.IncludeTermVectors = true
accessionMapping.AddFieldMappingsAt("subjects_function", subjectsFunctionMapping)
subjectsTopicalMapping := bleve.NewTextFieldMapping()
subjectsTopicalMapping.Analyzer = "en"
subjectsTopicalMapping.Store = true
subjectsTopicalMapping.Index = true
subjectsTopicalMapping.IncludeTermVectors = true
accessionMapping.AddFieldMappingsAt("subjects_topical", subjectsTopicalMapping)
objectTitleMapping := bleve.NewTextFieldMapping()
objectTitleMapping.Analyzer = "en"
objectTitleMapping.Store = true
objectTitleMapping.Index = false
accessionMapping.AddFieldMappingsAt("digital_objects.title", objectTitleMapping)
objectFileURIMapping := bleve.NewTextFieldMapping()
objectFileURIMapping.Analyzer = ""
objectFileURIMapping.Store = true
objectFileURIMapping.Index = false
accessionMapping.AddFieldMappingsAt("digital_objects.file_uris", objectFileURIMapping)
extentsMapping := bleve.NewTextFieldMapping()
extentsMapping.Analyzer = "en"
extentsMapping.Store = true
extentsMapping.Index = true
accessionMapping.AddFieldMappingsAt("extents", extentsMapping)
accessionDateMapping := bleve.NewTextFieldMapping()
accessionDateMapping.Analyzer = "en"
accessionDateMapping.Store = true
accessionDateMapping.Index = false
accessionMapping.AddFieldMappingsAt("accession_date", accessionDateMapping)
datesMapping := bleve.NewTextFieldMapping()
datesMapping.Store = true
datesMapping.Index = false
accessionMapping.AddFieldMappingsAt("date_expression", datesMapping)
createdMapping := bleve.NewDateTimeFieldMapping()
createdMapping.Store = true
createdMapping.Index = false
accessionMapping.AddFieldMappingsAt("created", createdMapping)
// Finally add this mapping to the main index mapping
indexMapping.AddDocumentMapping("accession", accessionMapping)
index, err := bleve.New(indexName, indexMapping)
if err != nil {
return nil, fmt.Errorf("Can't create new bleve index %s, %s", indexName, err)
}
return index, nil
}
log.Printf("Opening Bleve index at %s", indexName)
index, err := bleve.OpenUsing(indexName, map[string]interface{}{
"read_only": false,
})
if err != nil {
return nil, fmt.Errorf("Can't create new bleve index %s, %s", indexName, err)
}
return index, nil
}
开发者ID:caltechlibrary,项目名称:cait,代码行数:95,代码来源:indexpages.go
示例18: buildIndexMapping
func buildIndexMapping() (*bleve.IndexMapping, error) {
// a custom field definition that uses our custom analyzer
notTooLongFieldMapping := bleve.NewTextFieldMapping()
notTooLongFieldMapping.Analyzer = "enNotTooLong"
// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = en.AnalyzerName
// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = keyword_analyzer.Name
// a specific mapping to index the description fields
// detected language
descriptionLangFieldMapping := bleve.NewTextFieldMapping()
descriptionLangFieldMapping.Name = "descriptionLang"
descriptionLangFieldMapping.Analyzer = detect_lang.AnalyzerName
descriptionLangFieldMapping.Store = false
descriptionLangFieldMapping.IncludeTermVectors = false
descriptionLangFieldMapping.IncludeInAll = false
beerMapping := bleve.NewDocumentMapping()
// name
beerMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
// description
beerMapping.AddFieldMappingsAt("description",
notTooLongFieldMapping,
descriptionLangFieldMapping)
beerMapping.AddFieldMappingsAt("type", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("style", keywordFieldMapping)
beerMapping.AddFieldMappingsAt("category", keywordFieldMapping)
breweryMapping := bleve.NewDocumentMapping()
breweryMapping.AddFieldMappingsAt("name", englishTextFieldMapping)
breweryMapping.AddFieldMappingsAt("description", englishTextFieldMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("beer", beerMapping)
indexMapping.AddDocumentMapping("brewery", breweryMapping)
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = textFieldAnalyzer
err := indexMapping.AddCustomTokenFilter("notTooLong",
map[string]interface{}{
"type": truncate_token_filter.Name,
"length": 5.0,
})
if err != nil {
return nil, err
}
err = indexMapping.AddCustomAnalyzer("enNotTooLong",
map[string]interface{}{
"type": custom_analyzer.Name,
"tokenizer": unicode.Name,
"token_filters": []string{
"notTooLong",
en.PossessiveName,
lower_case_filter.Name,
en.StopName,
porter.Name,
},
})
if err != nil {
return nil, err
}
return indexMapping, nil
}
开发者ID:Xackery,项目名称:beer-search,代码行数:75,代码来源:mapping_example1.go
示例19: GenerateIndex
// Run index++ to generate a (new) swish++ index file.
func GenerateIndex() error {
// TODO handle multiple fields, i.e. the main text, @source, @type, tags, etc.
newIndex := false
// Try to open an existing index or create a new one if none exists.
index, err := openIndex()
if err != nil {
enTextMapping := bleve.NewTextFieldMapping()
enTextMapping.Analyzer = "en"
simpleMapping := bleve.NewTextFieldMapping()
simpleMapping.Analyzer = simple_analyzer.Name
typeMapping := bleve.NewTextFieldMapping()
typeMapping.Analyzer = keyword_analyzer.Name
scrollMapping := bleve.NewDocumentMapping()
scrollMapping.AddFieldMappingsAt("id", simpleMapping)
scrollMapping.AddFieldMappingsAt("content", enTextMapping)
scrollMapping.AddFieldMappingsAt("type", typeMapping)
scrollMapping.AddFieldMappingsAt("source", simpleMapping)
scrollMapping.AddFieldMappingsAt("tag", simpleMapping)
scrollMapping.AddFieldMappingsAt("hidden", simpleMapping)
scrollMapping.AddFieldMappingsAt("other", simpleMapping)
mapping := bleve.NewIndexMapping()
mapping.DefaultAnalyzer = "en"
mapping.DefaultMapping = scrollMapping
index, err = bleve.New(Config.AlexandriaDirectory+"bleve", mapping)
if err != nil {
panic(err)
}
newIndex = true
}
defer index.Close()
files, err := ioutil.ReadDir(Config.KnowledgeDirectory)
if err != nil {
return err
}
indexUpdateFile := Config.AlexandriaDirectory + "index_updated"
indexUpdateTime, err := getModTime(indexUpdateFile)
if err != nil {
LogError(err)
return nil
}
// Save the time of this indexing operation
_ = touch(Config.AlexandriaDirectory + "index_updated")
batch := index.NewBatch()
for _, file := range files {
// Check whether the scroll is newer than the index.
modTime, err := getModTime(Config.KnowledgeDirectory + file.Name())
if err != nil {
LogError(err)
continue
}
id := strings.TrimSuffix(file.Name(), ".tex")
if modTime < indexUpdateTime && !newIndex {
continue
}
// Load and parse the scroll content
contentBytes, err := ioutil.ReadFile(Config.KnowledgeDirectory + file.Name())
TryLogError(err)
content := string(contentBytes)
scroll := Parse(id, content)
batch.Index(id, scroll)
}
index.Batch(batch)
return nil
}
开发者ID:yzhs,项目名称:alexandria,代码行数:76,代码来源:Bleve.go
注:本文中的github.com/blevesearch/bleve.NewDocumentMapping函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论