func GetArticlesByOntologyWithSentencesAndMeter(ontologyName string, ontologyValue string, meter string, syllabi *rhyme.Syllabi, maxArticles int, maxMillis int) (*[]*ArticleWithSentencesAndMeter, *[]*MatchedPhraseWithUrl) { start := time.Now() maxDurationNanoseconds := int64(maxMillis * 1e6) // sapiResult := sapi.Search( sapi.SearchParams{ Author: author } ) articles := []*ArticleWithSentencesAndMeter{} // if sapiResult != nil && *(sapiResult.Items) != nil && len(*(sapiResult.Items)) > 0 { // for _,item := range (*(sapiResult.Items))[0:maxArticles] { // if item != nil { // aws := GetArticleWithSentencesAndMeter(item.Id, meter, syllabi) // articles = append( articles, aws ) // } // if time.Since(start).Nanoseconds() > maxDurationNanoseconds { // break // } // } // } sRequest := &content.SearchRequest{ QueryType: ontologyName, QueryText: ontologyValue, MaxArticles: maxArticles, MaxDurationMillis: maxMillis, SearchOnly: true, } sapiResult := content.Search(sRequest) if sapiResult != nil && *(sapiResult.Articles) != nil && len(*(sapiResult.Articles)) > 0 { for i, item := range *(sapiResult.Articles) { if i >= maxArticles { break } if item != nil { aws := GetArticleWithSentencesAndMeter(item.Uuid, meter, syllabi) articles = append(articles, aws) } if time.Since(start).Nanoseconds() > maxDurationNanoseconds { break } } } mpwus := []*MatchedPhraseWithUrl{} for _, article := range articles { for _, mp := range *(article.MatchedPhrases) { mpwu := &MatchedPhraseWithUrl{ mp, &article.SiteUrl, } mpwus = append(mpwus, mpwu) } } return &articles, &mpwus }
func Search(text string, source string) *ResultParams { // sapiResults := sapi.Search( params ) var textForSearch string if source != "title-only" { source = "keyword" textForSearch = `\"` + text + `\"` } else { textForSearch = text } sRequest := &content.SearchRequest{ QueryType: source, QueryText: textForSearch, MaxArticles: 100, MaxDurationMillis: 3000, SearchOnly: true, // i.e. don't bother looking up articles } // fmt.Println("align.Search: sRequest=", sRequest) sapiResults := content.Search(sRequest) // fmt.Println("align.Search: sapiResults=", sapiResults) // fmt.Println("align.Search: sapiResults.Articles=", sapiResults.Articles) var ( maxIndent int = 0 phrases []PhraseBits = []PhraseBits{} ) for _, resultItem := range *(*sapiResults).Articles { var phrase string if source == "title-only" { phrase = resultItem.Title } else { phrase = resultItem.Excerpt } splitPhrase := FullOnPartial(phrase, text) // fmt.Println("align.Search: resultItem.Excerpt=", resultItem.Excerpt, ", text=", text, ", splitPhrase=", splitPhrase) if splitPhrase.Indent >= 0 { bits := &PhraseBits{ Before: splitPhrase.Before, Common: splitPhrase.Common, After: splitPhrase.After, Excerpt: resultItem.Excerpt, Title: resultItem.Title, LocationUri: resultItem.SiteUrl, } phrases = append(phrases, *bits) if maxIndent < splitPhrase.Indent { maxIndent = splitPhrase.Indent } } // because it looks better this way sort.Sort(ByBeforeBit(phrases)) } var ( titleOnlyChecked string = "" anyChecked string = "" ) if source == "title-only" { titleOnlyChecked = "checked" } else { anyChecked = "checked" } p := &ResultParams{ Text: text, Source: source, MaxIndent: maxIndent, Phrases: phrases, FtcomUrl: sapiResults.SiteUrl, FtcomSearchUrl: sapiResults.SiteSearchUrl, TitleOnlyChecked: titleOnlyChecked, AnyChecked: anyChecked, } return p }