Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: implemented the API client #1

Merged
merged 1 commit into from
May 14, 2017
Merged

all: implemented the API client #1

merged 1 commit into from
May 14, 2017

Conversation

odeke-em
Copy link
Member

Implemented simple & advanced searching with
all the categories and filters supported by arxiv.org.

Sample usage

  • Preamble:
package main

import (
    "fmt"
    "log"

    "github.com/orijtech/arxiv/v1"
)
  • Simple search
func simpleSearch() {
  resChan, cancel, err := arxiv.Search(&arxiv.Query{
    Terms:         "deep learning",
    MaxPageNumber: 5,
  })
  if err != nil {
    log.Fatal(err)
  }

  for resPage := range resChan {
    if err := resPage.Err; err != nil {
      fmt.Printf("#%d err: %v", resPage.PageNumber, err)
      continue
    }

    fmt.Printf("#%d\n", resPage.PageNumber)
    feed := resPage.Feed
    fmt.Printf("\tTitle: %s\n\tID: %s\n\tAuthor: %#v\n\tUpdated: %#v\n",
feed.Title, feed.ID, feed.Author, feed.Updated)
    for i, entry := range feed.Entry {
      fmt.Printf("\n\t\tEntry: #%d Title: %s ID: %s\n\t\tSummary:
%s\n\t\tContent: %#v\n\t\tUpdated: %#v\n\t\tLinks: %#v\n",
	i, entry.Title, entry.ID, entry.Summary.Body, entry.Content,
entry.Updated, entry.Link,
      )
    }
    if resPage.PageNumber >= 2 {
      cancel()
    }
  }
}
  • Advanced/complex search
func advancedSearch() {
  resChan, cancel, err := arxiv.Search(&arxiv.Query{
    Filters: []*arxiv.Filter{
      &arxiv.Filter{
	Op: arxiv.OpOR,
	Fields: []*arxiv.Field{
	  {Title: "architecture"},
	  {Category: arxiv.CSGameTheory},
	  {Comment: "biological"},
	},
      },
    },
    MaxPageNumber: 2,
  })
  if err != nil {
    log.Fatal(err)
  }

  for resPage := range resChan {
    if err := resPage.Err; err != nil {
      fmt.Printf("#%d err: %v", resPage.PageNumber, err)
      continue
    }

    fmt.Printf("#%d\n", resPage.PageNumber)
    feed := resPage.Feed
    fmt.Printf("\tTitle: %s\n\tID: %s\n\tAuthor: %#v\n\tUpdated: %#v\n",
feed.Title, feed.ID, feed.Author, feed.Updated)
    for i, entry := range feed.Entry {
      fmt.Printf("\n\t\tEntry: #%d Title: %s ID: %s\n\t\tSummary:
%s\n\t\tContent: %#v\n\t\tUpdated: %#v\n\t\tLinks: %#v\n",
	i, entry.Title, entry.ID, entry.Summary.Body, entry.Content,
entry.Updated, entry.Link,
      )
    }
    if resPage.PageNumber >= 2 {
      cancel()
    }
  }
}

Implemented simple & advanced searching with
all the categories and filters supported by arxiv.org.

Sample usage
* Preamble:
```go
package main

import (
    "fmt"
    "log"

    "github.com/orijtech/arxiv/v1"
)
```

* Simple search
```go
func simpleSearch() {
  resChan, cancel, err := arxiv.Search(&arxiv.Query{
    Terms:         "deep learning",
    MaxPageNumber: 5,
  })
  if err != nil {
    log.Fatal(err)
  }

  for resPage := range resChan {
    if err := resPage.Err; err != nil {
      fmt.Printf("#%d err: %v", resPage.PageNumber, err)
      continue
    }

    fmt.Printf("#%d\n", resPage.PageNumber)
    feed := resPage.Feed
    fmt.Printf("\tTitle: %s\n\tID: %s\n\tAuthor: %#v\n\tUpdated: %#v\n",
feed.Title, feed.ID, feed.Author, feed.Updated)
    for i, entry := range feed.Entry {
      fmt.Printf("\n\t\tEntry: #%d Title: %s ID: %s\n\t\tSummary:
%s\n\t\tContent: %#v\n\t\tUpdated: %#v\n\t\tLinks: %#v\n",
	i, entry.Title, entry.ID, entry.Summary.Body, entry.Content,
entry.Updated, entry.Link,
      )
    }
    if resPage.PageNumber >= 2 {
      cancel()
    }
  }
}
```

* Advanced/complex search
```go
func advancedSearch() {
  resChan, cancel, err := arxiv.Search(&arxiv.Query{
    Filters: []*arxiv.Filter{
      &arxiv.Filter{
	Op: arxiv.OpOR,
	Fields: []*arxiv.Field{
	  {Title: "architecture"},
	  {Category: arxiv.CSGameTheory},
	  {Comment: "biological"},
	},
      },
    },
    MaxPageNumber: 2,
  })
  if err != nil {
    log.Fatal(err)
  }

  for resPage := range resChan {
    if err := resPage.Err; err != nil {
      fmt.Printf("#%d err: %v", resPage.PageNumber, err)
      continue
    }

    fmt.Printf("#%d\n", resPage.PageNumber)
    feed := resPage.Feed
    fmt.Printf("\tTitle: %s\n\tID: %s\n\tAuthor: %#v\n\tUpdated: %#v\n",
feed.Title, feed.ID, feed.Author, feed.Updated)
    for i, entry := range feed.Entry {
      fmt.Printf("\n\t\tEntry: #%d Title: %s ID: %s\n\t\tSummary:
%s\n\t\tContent: %#v\n\t\tUpdated: %#v\n\t\tLinks: %#v\n",
	i, entry.Title, entry.ID, entry.Summary.Body, entry.Content,
entry.Updated, entry.Link,
      )
    }
    if resPage.PageNumber >= 2 {
      cancel()
    }
  }
}
```
@odeke-em odeke-em merged commit 2e194aa into master May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant