本文整理匯總了Golang中github.com/blevesearch/bleve.NewTextFieldMapping函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTextFieldMapping函數的具體用法?Golang NewTextFieldMapping怎麽用?Golang NewTextFieldMapping使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTextFieldMapping函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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)
}
}
示例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
}
示例5: 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
}
示例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
}
示例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
}
示例8: 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
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: 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
}
示例13: 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
}
示例14: NewOfferIndex
func NewOfferIndex(dir string) (bleve.Index, error) {
err := os.RemoveAll(dir)
if err != nil && !os.IsNotExist(err) {
return nil, err
}
parts := []string{}
for _, exc := range indexExceptions {
parts = append(parts, regexp.QuoteMeta(exc))
}
pattern := strings.Join(parts, "|")
pattern = "(?i)(?:" + pattern + ")"
m := bleve.NewIndexMapping()
apecTokenizer := "apec"
err = m.AddCustomTokenizer(apecTokenizer, map[string]interface{}{
"type": exception.Name,
"exceptions": []string{pattern},
"tokenizer": bleveuni.Name,
})
if err != nil {
return nil, err
}
apecTokens := "apec_tokens"
err = m.AddCustomTokenMap(apecTokens, map[string]interface{}{
"type": tokenmap.Name,
"tokens": stopWords,
})
if err != nil {
return nil, err
}
apecStop := "apec_stop"
err = m.AddCustomTokenFilter(apecStop, map[string]interface{}{
"type": stop.Name,
"stop_token_map": apecTokens,
})
if err != nil {
return nil, err
}
frTokens := []string{
lowercase.Name,
fr.ElisionName,
fr.StopName,
fr.LightStemmerName,
apecStop,
}
fr := map[string]interface{}{
"type": custom.Name,
"tokenizer": apecTokenizer,
"token_filters": frTokens,
}
frHtml := map[string]interface{}{
"type": custom.Name,
"char_filters": []string{
html.Name,
},
"tokenizer": apecTokenizer,
"token_filters": frTokens,
}
err = m.AddCustomAnalyzer("fr", fr)
if err != nil {
return nil, fmt.Errorf("failed to register analyzer fr: %s", err)
}
err = m.AddCustomAnalyzer("fr_html", frHtml)
if err != nil {
return nil, fmt.Errorf("failed to register analyzer fr_html: %s", err)
}
htmlFr := bleve.NewTextFieldMapping()
htmlFr.Store = false
htmlFr.IncludeInAll = false
htmlFr.IncludeTermVectors = false
htmlFr.Analyzer = "fr_html"
textFr := bleve.NewTextFieldMapping()
textFr.Store = false
textFr.IncludeInAll = false
textFr.IncludeTermVectors = false
textFr.Analyzer = "fr"
textAll := bleve.NewTextFieldMapping()
textAll.Store = false
textAll.IncludeInAll = true
textAll.IncludeTermVectors = false
date := bleve.NewDateTimeFieldMapping()
date.Index = false
date.Store = true
date.IncludeInAll = false
date.IncludeTermVectors = false
offer := bleve.NewDocumentStaticMapping()
offer.Dynamic = false
offer.AddFieldMappingsAt("html", htmlFr)
offer.AddFieldMappingsAt("title", textFr)
offer.AddFieldMappingsAt("date", date)
//.........這裏部分代碼省略.........
示例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()
}