/* * Searches for articles in the database * @param tags string[] The tags entered by the user.Currently only entity search has been implemented. Algorithm in Readme */ func SearchForArticles(tags []string, store *cayley.Handle) PairList { links := make(map[string]int) for _, tag := range tags { entities := extractArticleData.GetEntityInfo(tag, "") if len(entities) == 0 { continue } entitityInfo := entities[0] // Get the First Entity //TODO:- Change to Best Label Match for _, category := range entitityInfo.Categories { path := cayley.StartPath(store, category). In("has_category"). In("has_entity") it := path.BuildIterator() it, _ = it.Optimize() for cayley.RawNext(it) { link := store.NameOf(it.Result()) links[link] += 10 } } } return sortMapByValue(links) }
func (p *mgoPersistenceProvider) loadVersionsByAPI(apiVersion string, graph *cayley.Handle, session *mgo.Session, target common.IServiceRegistry) error { var startingNodeID = utils.CreateAPIVersionKey(apiVersion) var path = cayley.StartPath(graph, startingNodeID).Out(utils.ContainsVersionRel) it := path.BuildIterator() for cayley.RawNext(it) { var version serviceVersion err := session.DB("test").C("serviceVersions").Find(bson.M{"_id": graph.NameOf(it.Result())}).One(&version) if err != nil { return err } target.LinkServiceToAPI(version.Service, version.Version, apiVersion) } return nil }
func (p *mgoPersistenceProvider) loadVersionsByService(serviceIdentifier string, graph *cayley.Handle, session *mgo.Session, target common.IServiceRegistry) error { var startingNodeID = utils.CreateServiceDefinitionKey(serviceIdentifier) var path = cayley.StartPath(graph, startingNodeID).Out(utils.ContainsVersionRel) it := path.BuildIterator() for cayley.RawNext(it) { var version serviceVersion var serviceVersionNode = graph.NameOf(it.Result()) err := session.DB("test").C("serviceVersions").Find(bson.M{"_id": serviceVersionNode}).One(&version) if err != nil { return fmt.Errorf("Cannot find %s in collection 'serviceVersions': %s", serviceVersionNode, err.Error()) } target.AddServiceVersion(serviceIdentifier, version.Version) } return nil }
func GetInfoForLink(store *cayley.Handle, link string) Article { path := cayley.StartPath(store, link). Save("has_title", "title"). Save("has_description", "description") it := path.BuildIterator() it, _ = it.Optimize() graph.Next(it) tags := make(map[string]graph.Value) it.TagResults(tags) return Article{ store.NameOf(tags["title"]), store.NameOf(tags["description"]), link, } }
/* The root page.Gets Data from the database to Display articles */ func mainHandler(w http.ResponseWriter, r *http.Request, store *cayley.Handle) { t, error := template.ParseFiles("website/templates/index.html") if error != nil { fmt.Println("error:", error) fmt.Println("HTML TEMPLATE WAS NOT FOUND. Check if the html file is present.") } path := cayley.StartPath(store, "Article"). In(). Tag("link"). Save("has_image", "image"). Save("has_title", "title"). Save("has_description", "description") it := path.BuildIterator() it, _ = it.Optimize() articleList := make([]Article, 0) for graph.Next(it) { tags := make(map[string]graph.Value) it.TagResults(tags) articleList = append(articleList, Article{ store.NameOf(tags["title"]), store.NameOf(tags["description"]), store.NameOf(tags["link"]), store.NameOf(tags["image"]), }) } type PageContent struct { Articles []Article } t.Execute(w, PageContent{articleList}) }