Skip to content

Commit

Permalink
Merge ca713f9 into 3d09365
Browse files Browse the repository at this point in the history
  • Loading branch information
eonu committed Apr 17, 2021
2 parents 3d09365 + ca713f9 commit 4feae35
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Although [Scholastica](https://github.com/scholastica) offer a great [Ruby gem](
```ruby
require 'arx'

papers = Arx(sort_by: :date_submitted) do |query|
papers = Arx(sort_by: :submitted_at) do |query|
query.category('cs.FL')
query.title('Buchi Automata').and_not.author('Tomáš Babiak')
end
Expand Down Expand Up @@ -92,13 +92,13 @@ The `Arx::Query` class provides a small DSL for writing these query strings.

The order in which search results are returned can be modified through the `sort_by` and `sort_order` keyword arguments (in the `Arx::Query` initializer):

- `sort_by` accepts the symbols: `:relevance`, `:last_updated` or `:date_submitted`
- `sort_by` accepts the symbols: `:relevance`, `:updated_at` or `:submitted_at`

- `sort_order` accepts the symbols: `:ascending` or `:descending`

```ruby
# Sort by submission date in ascending order (earliest first)
Arx::Query.new(sort_by: :date_submitted, sort_order: :ascending)
Arx::Query.new(sort_by: :submitted_at, sort_order: :ascending)
#=> sortBy=submittedDate&sortOrder=ascending
```

Expand Down Expand Up @@ -153,15 +153,16 @@ The arXiv search API supports searches for the following paper metadata fields:

```ruby
FIELDS = {
title: 'ti', # Title
author: 'au', # Author
abstract: 'abs', # Abstract
comment: 'co', # Comment
journal: 'jr', # Journal reference
category: 'cat', # Subject category
report: 'rn', # Report number
last_updated_date: 'lastUpdatedDate', # Last updated date
all: 'all' # All (of the above)
title: 'ti', # Title
author: 'au', # Author
abstract: 'abs', # Abstract
comment: 'co', # Comment
journal: 'jr', # Journal reference
category: 'cat', # Subject category
report: 'rn', # Report number
updated_at: 'lastUpdatedDate', # Last updated date
submitted_at: 'submittedDate', # Submission date
all: 'all' # All (of the above)
}
```

Expand Down Expand Up @@ -277,7 +278,7 @@ Calling the `Arx()` method with a block allows for the construction and executio

```ruby
# Papers in the cs.FL category whose title contains "Buchi Automata", not authored by Tomáš Babiak
results = Arx(sort_by: :date_submitted) do |query|
results = Arx(sort_by: :submitted_at) do |query|
query.category('cs.FL')
query.title('Buchi Automata').and_not.author('Tomáš Babiak')
end
Expand All @@ -293,7 +294,7 @@ The `Arx()` method accepts a predefined `Arx::Query` object through the `query`

```ruby
# Papers in the cs.FL category whose title contains "Buchi Automata", not authored by Tomáš Babiak
q = Arx::Query.new(sort_by: :date_submitted)
q = Arx::Query.new(sort_by: :submitted_at)
q.category('cs.FL')
q.title('Buchi Automata').and_not.author('Tomáš Babiak')

Expand Down
37 changes: 23 additions & 14 deletions lib/arx/query/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@ class Query
# @see https://arxiv.org/help/prep arXiv metadata fields
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual (query details)
FIELDS = {
title: 'ti', # Title
author: 'au', # Author
abstract: 'abs', # Abstract
comment: 'co', # Comment
journal: 'jr', # Journal reference
category: 'cat', # Subject category
report: 'rn', # Report number
last_updated_date: 'lastUpdatedDate', # Last updated date
all: 'all' # All (of the above)
title: 'ti', # Title
author: 'au', # Author
abstract: 'abs', # Abstract
comment: 'co', # Comment
journal: 'jr', # Journal reference
category: 'cat', # Subject category
report: 'rn', # Report number
updated_at: 'lastUpdatedDate', # Last updated date
submitted_at: 'submittedDate', # Submission date
all: 'all' # All (of the above)
}

# Supported criteria for the +sortBy+ parameter.
SORT_BY = {
relevance: 'relevance',
last_updated: 'lastUpdatedDate',
date_submitted: 'submittedDate'
updated_at: 'lastUpdatedDate',
submitted_at: 'submittedDate'
}

# Supported criteria for the +sortOrder+ parameter.
Expand Down Expand Up @@ -158,10 +159,17 @@ def initialize(*ids, sort_by: :relevance, sort_order: :descending, start: 0, max
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
# @return [self]

# @!method last_updated_date(*values, connective: :and)
# @!method updated_at(*values, connective: :and)
# Search for papers by lastUpdatedDate.
#
# @param values [Array<String>] lastUpdatedDate (String or range) of papers to search for.
# @param values [Array<String>] lastUpdatedDate (string or range) of papers to search for.
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
# @return [self]

# @!method submitted_at(*values, connective: :and)
# Search for papers by submittedDate.
#
# @param values [Array<String>] submittedDate (string or range) of papers to search for.
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
# @return [self]

Expand All @@ -174,7 +182,8 @@ def initialize(*ids, sort_by: :relevance, sort_order: :descending, start: 0, max
# @return [self]

FIELDS.each do |name, field|
define_method(name) do |*values, exact: true, connective: :and|
_exact = ![:updated_at, :submitted_at].include?(name)
define_method(name) do |*values, exact: _exact, connective: :and|
return if values.empty?

values.flatten!
Expand Down
2 changes: 1 addition & 1 deletion spec/arx/query/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
end
end
context 'with IDs and key-word arguments' do
it { expect(subject.new('1105.5379', 'cond-mat/9609089', sort_by: :date_submitted, sort_order: :ascending).to_s).to eq 'sortBy=submittedDate&sortOrder=ascending&start=0&max_results=10&id_list=1105.5379,cond-mat/9609089' }
it { expect(subject.new('1105.5379', 'cond-mat/9609089', sort_by: :submitted_at, sort_order: :ascending).to_s).to eq 'sortBy=submittedDate&sortOrder=ascending&start=0&max_results=10&id_list=1105.5379,cond-mat/9609089' }
end
end

Expand Down

0 comments on commit 4feae35

Please sign in to comment.