Skip to content

sxolar.api.search

Higher-level api for searching for papers, uses an object interface with overridden magic methods for syntactic sugar

Abstract

Bases: Query

Represents an abstract query for the arxiv API

Source code in sxolar/api/search.py
358
359
360
361
362
363
364
365
366
367
368
369
370
class Abstract(Query):
    """Represents an abstract query for the arxiv API"""

    def __init__(self, abstract: str):
        """Creates a new abstract query

        Args:
            abstract:
                str, the abstract of the paper
        """
        if not abstract.startswith(SearchField.ABSTRACT):
            abstract = f"{SearchField.ABSTRACT}:{abstract}"
        super().__init__(abstract)

__init__(abstract)

Creates a new abstract query

Parameters:

Name Type Description Default
abstract str

str, the abstract of the paper

required
Source code in sxolar/api/search.py
361
362
363
364
365
366
367
368
369
370
def __init__(self, abstract: str):
    """Creates a new abstract query

    Args:
        abstract:
            str, the abstract of the paper
    """
    if not abstract.startswith(SearchField.ABSTRACT):
        abstract = f"{SearchField.ABSTRACT}:{abstract}"
    super().__init__(abstract)

All

Bases: Query

Represents an all query for the arxiv API

Source code in sxolar/api/search.py
373
374
375
376
377
378
379
380
381
382
383
384
385
class All(Query):
    """Represents an all query for the arxiv API"""

    def __init__(self, all_: str):
        """Creates a new all query

        Args:
            all_:
                str, the value to search for
        """
        if not all_.startswith(SearchField.ALL):
            all_ = f"{SearchField.ALL}:{all_}"
        super().__init__(all_)

__init__(all_)

Creates a new all query

Parameters:

Name Type Description Default
all_ str

str, the value to search for

required
Source code in sxolar/api/search.py
376
377
378
379
380
381
382
383
384
385
def __init__(self, all_: str):
    """Creates a new all query

    Args:
        all_:
            str, the value to search for
    """
    if not all_.startswith(SearchField.ALL):
        all_ = f"{SearchField.ALL}:{all_}"
    super().__init__(all_)

Author

Bases: Query

Represents an author query for the arxiv API

Source code in sxolar/api/search.py
328
329
330
331
332
333
334
335
336
337
338
339
340
class Author(Query):
    """Represents an author query for the arxiv API"""

    def __init__(self, name: str):
        """Creates a new author query

        Args:
            name:
                str, the name of the author, "First Last"
        """
        if not name.startswith(SearchField.AUTHOR):
            name = f"{SearchField.AUTHOR}:{name}"
        super().__init__(name)

__init__(name)

Creates a new author query

Parameters:

Name Type Description Default
name str

str, the name of the author, "First Last"

required
Source code in sxolar/api/search.py
331
332
333
334
335
336
337
338
339
340
def __init__(self, name: str):
    """Creates a new author query

    Args:
        name:
            str, the name of the author, "First Last"
    """
    if not name.startswith(SearchField.AUTHOR):
        name = f"{SearchField.AUTHOR}:{name}"
    super().__init__(name)

Category

Bases: Query

Represents a category query for the arxiv API

Source code in sxolar/api/search.py
403
404
405
406
407
408
409
410
411
412
413
414
class Category(Query):
    """Represents a category query for the arxiv API"""

    def __init__(self, category: str):
        """Creates a new category query

        Args:
            category:
        """
        if not category.startswith(SearchField.CATEGORY):
            category = f"{SearchField.CATEGORY}:{category}"
        super().__init__(category)

__init__(category)

Creates a new category query

Parameters:

Name Type Description Default
category str
required
Source code in sxolar/api/search.py
406
407
408
409
410
411
412
413
414
def __init__(self, category: str):
    """Creates a new category query

    Args:
        category:
    """
    if not category.startswith(SearchField.CATEGORY):
        category = f"{SearchField.CATEGORY}:{category}"
    super().__init__(category)

JournalRef

Bases: Query

Represents a journal reference query for the arxiv API

Source code in sxolar/api/search.py
388
389
390
391
392
393
394
395
396
397
398
399
400
class JournalRef(Query):
    """Represents a journal reference query for the arxiv API"""

    def __init__(self, journal_ref: str):
        """Creates a new journal reference query

        Args:
            journal_ref:
                str, the journal reference
        """
        if not journal_ref.startswith(SearchField.JOURNAL_REFERENCE):
            journal_ref = f"{SearchField.JOURNAL_REFERENCE}:{journal_ref}"
        super().__init__(journal_ref)

__init__(journal_ref)

Creates a new journal reference query

Parameters:

Name Type Description Default
journal_ref str

str, the journal reference

required
Source code in sxolar/api/search.py
391
392
393
394
395
396
397
398
399
400
def __init__(self, journal_ref: str):
    """Creates a new journal reference query

    Args:
        journal_ref:
            str, the journal reference
    """
    if not journal_ref.startswith(SearchField.JOURNAL_REFERENCE):
        journal_ref = f"{SearchField.JOURNAL_REFERENCE}:{journal_ref}"
    super().__init__(journal_ref)

Query

Represents a query clause for the arxiv API

Attributes:

Name Type Description
value str

The value to search for

operator str

The operator to use

Source code in sxolar/api/search.py
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
class Query:
    """Represents a query clause for the arxiv API

    Attributes:
        value (str): The value to search for
        operator (str): The operator to use
    """

    def __init__(
        self,
        value: str,
        filter_authors: List[str] = None,
    ):
        """Creates a new query

        Args:
            value:
                str, the value to search for
            filter_authors:
                List[str], the authors to filter by
        """
        self.value = value
        self.filter_authors = filter_authors or []

    def __str__(self):
        """Returns the string representation of the query"""
        return self.value

    def __and__(self, other):
        """Overloads the and operator to create a new query"""
        return self.and_(other)

    def __or__(self, other):
        """Overloads the or operator to create a new query"""
        return self.or_(other)

    def __sub__(self, other):
        """Overloads the subtraction operator to create a new query"""
        return self.and_not(other)

    def and_(self, other: Union[str, "Query"]):
        """Join two queries with the AND operator

        Args:
            other:
                str, the other query to join with

        Returns:
            Query: A new query object
        """
        return Query(
            f"{self}{LogicalOperator.AND}{other}",
            filter_authors=list(set(self.filter_authors) & set(other.filter_authors)),
        )

    def and_not(self, other):
        """Join two queries with the AND NOT operator

        Args:
            other:
                str, the other query to join with

        Returns:
            Query: A new query object
        """
        return Query(
            f"{self}{LogicalOperator.AND_NOT}{other}",
            filter_authors=list(set(self.filter_authors) - set(other.filter_authors)),
        )

    def or_(self, other):
        """Join two queries with the OR operator

        Args:
            other:
                str, the other query to join with

        Returns:
            Query: A new query object
        """
        return Query(
            f"{self}{LogicalOperator.OR}{other}",
            filter_authors=list(set(self.filter_authors) | set(other.filter_authors)),
        )

    def join(
        self, *others: Iterable["Query"], operator: LogicalOperator = LogicalOperator.OR
    ):
        """Join multiple queries with an operator

        Args:
            others:
                Iterable[Query], the queries to join
            operator:
                LogicalOperator, the operator to use to join the queries

        Returns:
            Query: A new query object
        """
        if not others:
            return self

        value = self.value
        authors = set(self.filter_authors)
        for other in others:
            value = f"{value}{operator}{other}"
            authors |= set(other.filter_authors)

        return Query(value, filter_authors=list(sorted(authors))).wrap()

    def wrap(self):
        """Wrap the query in parenthesis

        Returns:
            Query: A new query object
        """
        return Query(f"({self})", filter_authors=self.filter_authors)

    def search(
        self,
        start: int = 0,
        max_results: int = 10,
        sort_by: SortBy = SortBy.Relevance,
        sort_order: SortOrder = SortOrder.Descending,
        min_date: datetime.datetime = None,
        max_date: datetime.datetime = None,
        date_filter_field: str = FIELD_ENTRY_UPDATED,
    ):
        """Searches the arxiv API with the query

        Args:
            start:
                int, optional, The starting index of the results
            max_results:
                int, optional, The maximum number of results to return

        Returns:
            list: A list of dictionaries representing the search results
        """
        results = arxiv.execute(
            self.value,
            id_list=None,
            start=start,
            max_results=max_results,
            sort_by=sort_by,
            sort_order=sort_order,
            min_date=min_date,
            max_date=max_date,
            date_filter_field=date_filter_field,
        )

        # Apply filter authors if any
        if self.filter_authors:
            results = [
                entry for entry in results if entry.filter_authors(self.filter_authors)
            ]

        return results

    def to_str(self) -> str:
        """Returns the string representation of the query"""
        return self.value

    @staticmethod
    def from_str(value: str):
        """Creates a new query from a string

        Args:
            value:
                str, the value to search for
        """
        return Query(value)

    @staticmethod
    def from_authors(*authors: Iterable[str]):
        """Creates a new author query

        Args:
            authors:
                str, the name of the author, "First Last"
        """
        authors = [Author(author).wrap() for author in authors]
        query = authors[0]
        if authors[1:]:
            query = query.join(*authors[1:], operator=LogicalOperator.OR)
        return query

    @staticmethod
    def from_titles(*titles: Iterable[str]):
        """Creates a new title query

        Args:
            titles:
                str, the title of the paper
        """
        titles = [Title(title) for title in titles]
        query = titles[0]
        if titles[1:]:
            query = query.join(*titles[1:], operator=LogicalOperator.OR)
        return query

    @staticmethod
    def from_abstracts(*abstracts: Iterable[str]):
        """Creates a new abstract query

        Args:
            abstracts:
                str, the abstract of the paper
        """
        abstracts = [Abstract(abstract) for abstract in abstracts]
        query = abstracts[0]
        if abstracts[1:]:
            query = query.join(*abstracts[1:], operator=LogicalOperator.OR)
        return query

    @staticmethod
    def from_alls(*alls: Iterable[str], operator: LogicalOperator = LogicalOperator.OR):
        """Creates a new all query

        Args:
            alls:
                str, the value to search for
        """
        alls = [All(all_) for all_ in alls]
        query = alls[0]
        if alls[1:]:
            query = query.join(*alls[1:], operator=operator)
        return query

    @staticmethod
    def from_journal_refs(*journal_refs: Iterable[str]):
        """Creates a new journal reference query

        Args:
            journal_refs:
                str, the journal reference
        """
        journal_refs = [JournalRef(journal_ref) for journal_ref in journal_refs]
        query = journal_refs[0]
        if journal_refs[1:]:
            query = query.join(*journal_refs[1:], operator=LogicalOperator.OR)
        return query

    @staticmethod
    def from_categories(*categories: Iterable[str]):
        """Creates a new category query

        Args:
            categories:
                str, the category
        """
        categories = [Category(category) for category in categories]
        query = categories[0]
        if categories[1:]:
            query = query.join(*categories[1:], operator=LogicalOperator.OR)
        return query

    @staticmethod
    def from_combo(
        authors: Iterable[str] = None,
        titles: Iterable[str] = None,
        abstracts: Iterable[str] = None,
        alls: Iterable[str] = None,
        journal_refs: Iterable[str] = None,
        categories: Iterable[str] = None,
        operator: LogicalOperator = LogicalOperator.AND,
        filter_authors: bool = False,
        alls_operator: LogicalOperator = LogicalOperator.OR,
    ):
        """Creates a new combo query

        Args:
            authors:
                Iterable[str], the name of the author, "First Last"
            titles:
                Iterable[str], the title of the paper
            abstracts:
                Iterable[str], the abstract of the paper
            alls:
                Iterable[str], the value to search for
            journal_refs:
                Iterable[str], the journal reference
            categories:
                Iterable[str], the category
        """
        queries = []
        if authors:
            queries.append(Query.from_authors(*authors))
        if titles:
            queries.append(Query.from_titles(*titles))
        if abstracts:
            queries.append(Query.from_abstracts(*abstracts))
        if alls:
            queries.append(Query.from_alls(*alls, operator=alls_operator))
        if journal_refs:
            queries.append(Query.from_journal_refs(*journal_refs))
        if categories:
            queries.append(Query.from_categories(*categories))

        query = queries[0]
        if queries[1:]:
            query = query.join(*queries[1:], operator=operator)

        # Add author filters if needed
        if filter_authors and authors:
            query.filter_authors = list(set(authors))

        return query

__and__(other)

Overloads the and operator to create a new query

Source code in sxolar/api/search.py
46
47
48
def __and__(self, other):
    """Overloads the and operator to create a new query"""
    return self.and_(other)

__init__(value, filter_authors=None)

Creates a new query

Parameters:

Name Type Description Default
value str

str, the value to search for

required
filter_authors List[str]

List[str], the authors to filter by

None
Source code in sxolar/api/search.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(
    self,
    value: str,
    filter_authors: List[str] = None,
):
    """Creates a new query

    Args:
        value:
            str, the value to search for
        filter_authors:
            List[str], the authors to filter by
    """
    self.value = value
    self.filter_authors = filter_authors or []

__or__(other)

Overloads the or operator to create a new query

Source code in sxolar/api/search.py
50
51
52
def __or__(self, other):
    """Overloads the or operator to create a new query"""
    return self.or_(other)

__str__()

Returns the string representation of the query

Source code in sxolar/api/search.py
42
43
44
def __str__(self):
    """Returns the string representation of the query"""
    return self.value

__sub__(other)

Overloads the subtraction operator to create a new query

Source code in sxolar/api/search.py
54
55
56
def __sub__(self, other):
    """Overloads the subtraction operator to create a new query"""
    return self.and_not(other)

and_(other)

Join two queries with the AND operator

Parameters:

Name Type Description Default
other Union[str, Query]

str, the other query to join with

required

Returns:

Name Type Description
Query

A new query object

Source code in sxolar/api/search.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def and_(self, other: Union[str, "Query"]):
    """Join two queries with the AND operator

    Args:
        other:
            str, the other query to join with

    Returns:
        Query: A new query object
    """
    return Query(
        f"{self}{LogicalOperator.AND}{other}",
        filter_authors=list(set(self.filter_authors) & set(other.filter_authors)),
    )

and_not(other)

Join two queries with the AND NOT operator

Parameters:

Name Type Description Default
other

str, the other query to join with

required

Returns:

Name Type Description
Query

A new query object

Source code in sxolar/api/search.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def and_not(self, other):
    """Join two queries with the AND NOT operator

    Args:
        other:
            str, the other query to join with

    Returns:
        Query: A new query object
    """
    return Query(
        f"{self}{LogicalOperator.AND_NOT}{other}",
        filter_authors=list(set(self.filter_authors) - set(other.filter_authors)),
    )

from_abstracts(*abstracts) staticmethod

Creates a new abstract query

Parameters:

Name Type Description Default
abstracts Iterable[str]

str, the abstract of the paper

()
Source code in sxolar/api/search.py
219
220
221
222
223
224
225
226
227
228
229
230
231
@staticmethod
def from_abstracts(*abstracts: Iterable[str]):
    """Creates a new abstract query

    Args:
        abstracts:
            str, the abstract of the paper
    """
    abstracts = [Abstract(abstract) for abstract in abstracts]
    query = abstracts[0]
    if abstracts[1:]:
        query = query.join(*abstracts[1:], operator=LogicalOperator.OR)
    return query

from_alls(*alls, operator=LogicalOperator.OR) staticmethod

Creates a new all query

Parameters:

Name Type Description Default
alls Iterable[str]

str, the value to search for

()
Source code in sxolar/api/search.py
233
234
235
236
237
238
239
240
241
242
243
244
245
@staticmethod
def from_alls(*alls: Iterable[str], operator: LogicalOperator = LogicalOperator.OR):
    """Creates a new all query

    Args:
        alls:
            str, the value to search for
    """
    alls = [All(all_) for all_ in alls]
    query = alls[0]
    if alls[1:]:
        query = query.join(*alls[1:], operator=operator)
    return query

from_authors(*authors) staticmethod

Creates a new author query

Parameters:

Name Type Description Default
authors Iterable[str]

str, the name of the author, "First Last"

()
Source code in sxolar/api/search.py
191
192
193
194
195
196
197
198
199
200
201
202
203
@staticmethod
def from_authors(*authors: Iterable[str]):
    """Creates a new author query

    Args:
        authors:
            str, the name of the author, "First Last"
    """
    authors = [Author(author).wrap() for author in authors]
    query = authors[0]
    if authors[1:]:
        query = query.join(*authors[1:], operator=LogicalOperator.OR)
    return query

from_categories(*categories) staticmethod

Creates a new category query

Parameters:

Name Type Description Default
categories Iterable[str]

str, the category

()
Source code in sxolar/api/search.py
261
262
263
264
265
266
267
268
269
270
271
272
273
@staticmethod
def from_categories(*categories: Iterable[str]):
    """Creates a new category query

    Args:
        categories:
            str, the category
    """
    categories = [Category(category) for category in categories]
    query = categories[0]
    if categories[1:]:
        query = query.join(*categories[1:], operator=LogicalOperator.OR)
    return query

from_combo(authors=None, titles=None, abstracts=None, alls=None, journal_refs=None, categories=None, operator=LogicalOperator.AND, filter_authors=False, alls_operator=LogicalOperator.OR) staticmethod

Creates a new combo query

Parameters:

Name Type Description Default
authors Iterable[str]

Iterable[str], the name of the author, "First Last"

None
titles Iterable[str]

Iterable[str], the title of the paper

None
abstracts Iterable[str]

Iterable[str], the abstract of the paper

None
alls Iterable[str]

Iterable[str], the value to search for

None
journal_refs Iterable[str]

Iterable[str], the journal reference

None
categories Iterable[str]

Iterable[str], the category

None
Source code in sxolar/api/search.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
@staticmethod
def from_combo(
    authors: Iterable[str] = None,
    titles: Iterable[str] = None,
    abstracts: Iterable[str] = None,
    alls: Iterable[str] = None,
    journal_refs: Iterable[str] = None,
    categories: Iterable[str] = None,
    operator: LogicalOperator = LogicalOperator.AND,
    filter_authors: bool = False,
    alls_operator: LogicalOperator = LogicalOperator.OR,
):
    """Creates a new combo query

    Args:
        authors:
            Iterable[str], the name of the author, "First Last"
        titles:
            Iterable[str], the title of the paper
        abstracts:
            Iterable[str], the abstract of the paper
        alls:
            Iterable[str], the value to search for
        journal_refs:
            Iterable[str], the journal reference
        categories:
            Iterable[str], the category
    """
    queries = []
    if authors:
        queries.append(Query.from_authors(*authors))
    if titles:
        queries.append(Query.from_titles(*titles))
    if abstracts:
        queries.append(Query.from_abstracts(*abstracts))
    if alls:
        queries.append(Query.from_alls(*alls, operator=alls_operator))
    if journal_refs:
        queries.append(Query.from_journal_refs(*journal_refs))
    if categories:
        queries.append(Query.from_categories(*categories))

    query = queries[0]
    if queries[1:]:
        query = query.join(*queries[1:], operator=operator)

    # Add author filters if needed
    if filter_authors and authors:
        query.filter_authors = list(set(authors))

    return query

from_journal_refs(*journal_refs) staticmethod

Creates a new journal reference query

Parameters:

Name Type Description Default
journal_refs Iterable[str]

str, the journal reference

()
Source code in sxolar/api/search.py
247
248
249
250
251
252
253
254
255
256
257
258
259
@staticmethod
def from_journal_refs(*journal_refs: Iterable[str]):
    """Creates a new journal reference query

    Args:
        journal_refs:
            str, the journal reference
    """
    journal_refs = [JournalRef(journal_ref) for journal_ref in journal_refs]
    query = journal_refs[0]
    if journal_refs[1:]:
        query = query.join(*journal_refs[1:], operator=LogicalOperator.OR)
    return query

from_str(value) staticmethod

Creates a new query from a string

Parameters:

Name Type Description Default
value str

str, the value to search for

required
Source code in sxolar/api/search.py
181
182
183
184
185
186
187
188
189
@staticmethod
def from_str(value: str):
    """Creates a new query from a string

    Args:
        value:
            str, the value to search for
    """
    return Query(value)

from_titles(*titles) staticmethod

Creates a new title query

Parameters:

Name Type Description Default
titles Iterable[str]

str, the title of the paper

()
Source code in sxolar/api/search.py
205
206
207
208
209
210
211
212
213
214
215
216
217
@staticmethod
def from_titles(*titles: Iterable[str]):
    """Creates a new title query

    Args:
        titles:
            str, the title of the paper
    """
    titles = [Title(title) for title in titles]
    query = titles[0]
    if titles[1:]:
        query = query.join(*titles[1:], operator=LogicalOperator.OR)
    return query

join(*others, operator=LogicalOperator.OR)

Join multiple queries with an operator

Parameters:

Name Type Description Default
others Iterable[Query]

Iterable[Query], the queries to join

()
operator LogicalOperator

LogicalOperator, the operator to use to join the queries

OR

Returns:

Name Type Description
Query

A new query object

Source code in sxolar/api/search.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def join(
    self, *others: Iterable["Query"], operator: LogicalOperator = LogicalOperator.OR
):
    """Join multiple queries with an operator

    Args:
        others:
            Iterable[Query], the queries to join
        operator:
            LogicalOperator, the operator to use to join the queries

    Returns:
        Query: A new query object
    """
    if not others:
        return self

    value = self.value
    authors = set(self.filter_authors)
    for other in others:
        value = f"{value}{operator}{other}"
        authors |= set(other.filter_authors)

    return Query(value, filter_authors=list(sorted(authors))).wrap()

or_(other)

Join two queries with the OR operator

Parameters:

Name Type Description Default
other

str, the other query to join with

required

Returns:

Name Type Description
Query

A new query object

Source code in sxolar/api/search.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def or_(self, other):
    """Join two queries with the OR operator

    Args:
        other:
            str, the other query to join with

    Returns:
        Query: A new query object
    """
    return Query(
        f"{self}{LogicalOperator.OR}{other}",
        filter_authors=list(set(self.filter_authors) | set(other.filter_authors)),
    )

search(start=0, max_results=10, sort_by=SortBy.Relevance, sort_order=SortOrder.Descending, min_date=None, max_date=None, date_filter_field=FIELD_ENTRY_UPDATED)

Searches the arxiv API with the query

Parameters:

Name Type Description Default
start int

int, optional, The starting index of the results

0
max_results int

int, optional, The maximum number of results to return

10

Returns:

Name Type Description
list

A list of dictionaries representing the search results

Source code in sxolar/api/search.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def search(
    self,
    start: int = 0,
    max_results: int = 10,
    sort_by: SortBy = SortBy.Relevance,
    sort_order: SortOrder = SortOrder.Descending,
    min_date: datetime.datetime = None,
    max_date: datetime.datetime = None,
    date_filter_field: str = FIELD_ENTRY_UPDATED,
):
    """Searches the arxiv API with the query

    Args:
        start:
            int, optional, The starting index of the results
        max_results:
            int, optional, The maximum number of results to return

    Returns:
        list: A list of dictionaries representing the search results
    """
    results = arxiv.execute(
        self.value,
        id_list=None,
        start=start,
        max_results=max_results,
        sort_by=sort_by,
        sort_order=sort_order,
        min_date=min_date,
        max_date=max_date,
        date_filter_field=date_filter_field,
    )

    # Apply filter authors if any
    if self.filter_authors:
        results = [
            entry for entry in results if entry.filter_authors(self.filter_authors)
        ]

    return results

to_str()

Returns the string representation of the query

Source code in sxolar/api/search.py
177
178
179
def to_str(self) -> str:
    """Returns the string representation of the query"""
    return self.value

wrap()

Wrap the query in parenthesis

Returns:

Name Type Description
Query

A new query object

Source code in sxolar/api/search.py
128
129
130
131
132
133
134
def wrap(self):
    """Wrap the query in parenthesis

    Returns:
        Query: A new query object
    """
    return Query(f"({self})", filter_authors=self.filter_authors)

Title

Bases: Query

Represents a title query for the arxiv API

Source code in sxolar/api/search.py
343
344
345
346
347
348
349
350
351
352
353
354
355
class Title(Query):
    """Represents a title query for the arxiv API"""

    def __init__(self, title: str):
        """Creates a new title query

        Args:
            title:
                str, the title of the paper
        """
        if not title.startswith(SearchField.TITLE):
            title = f"{SearchField.TITLE}:{title}"
        super().__init__(title)

__init__(title)

Creates a new title query

Parameters:

Name Type Description Default
title str

str, the title of the paper

required
Source code in sxolar/api/search.py
346
347
348
349
350
351
352
353
354
355
def __init__(self, title: str):
    """Creates a new title query

    Args:
        title:
            str, the title of the paper
    """
    if not title.startswith(SearchField.TITLE):
        title = f"{SearchField.TITLE}:{title}"
    super().__init__(title)