Astro-ADS

 view release on metacpan or  search on metacpan

lib/Astro/ADS/Search.pm  view on Meta::CPAN

            if ( @{$self->authors} > 1 ) {
                my $logic = $self->author_logic->{OR} ? q{ OR } : q{ };
                push @query, "$tag(" . join( $logic, map { quote $_ } @{$self->authors}) . ')';
            }
            else {
                push @query, $tag . quote $self->authors->[0];
            }
        }

        if ( @{$self->objects} ) {
            my $tag = 'object:';
            if ( @{$self->objects} > 1 ) {
                my $logic = $self->object_logic->{OR} ? q{ OR } : q{ };
                push @query, "$tag(" . join( $logic, map { quote $_ } @{$self->objects}) . ')';
            }
            else {
                push @query, $tag . quote $self->objects->[0];
            }
        }

        # need to remember which attributes take multiple values
        push @query, @{$self->bibcode} if @{$self->bibcode};
    }
                
    unless ( @query ) {
        carp 'No search terms provided for query';
        return;
    }

    my $search_terms = {
        q => join(q{ }, @query),
        maybe fq => $self->fq,
        maybe fl => $self->fl,
        maybe start => $self->start,
        maybe rows  => $self->rows,
        maybe sort  => $self->sort,
        %$terms
    };

    return $search_terms;
}

sub add_authors {
    my ($self, @authors) = @_;
    push @{$self->authors}, @authors;
}

sub add_objects {
    my ($self, @objects) = @_;
    push @{$self->objects}, @objects;
}

1;

=pod

=encoding UTF-8

=head1 NAME

Astro::ADS::Search - Queries the ADS Search endpoint and collects the results

=head1 VERSION

version 1.92

=head1 SYNOPSIS

    my $search = Astro::ADS::Search->new({
        q  => '...', # initial search query
        fl => '...', # return list of attributes
    });

    my $result = $search->query();
    my @papers = $result->papers();

    while ( my $t = $result->next_query() ) {
        $result = $search->query( $t );
        push @papers, $result->get_papers();
    }

    while ( my $t = $result->next_query() ) {
        push @papers, $result->more_papers( $t );
    }

    while ( push @papers, $result->next_query()->more_papers() ) {
    }

=head1 DESCRIPTION

Search for papers in the Harvard ADS 

You can put base terms in the creation of the object and use the
query method to add new terms to that query only

=head1 Methods

=head2 query

Adding a field key C<+q> to the query method B<adds> the query
term to the existing query terms,
whereas specifying a value for C<q> in the query method
overwrites the query terms and neglects gathering other search attributes,
such as authors or objects.

=head2 add_authors

Add a list of authors to a search query. Authors added here will not be
deleted if the query attribute is updated.

=head2 add_objects

Add a list of objects to a search query. Objects added here will not be
deleted if the query attribute is updated.

=head2 query_tree

Will return the L<Abstract Syntax Tree|https://ui.adsabs.harvard.edu/help/api/api-docs.html#get-/search/qtree> for the query.

=head2 bigquery



( run in 0.358 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )