Exemplo n.º 1
0
def search(query: str, include: Optional[str] = None) -> List[dict]:
    fields = parse_include(include) if include else []
    conjunction = parse_search(query)

    parts = iter(get_etexts(field, value) for field, value in conjunction)
    results = set(next(parts))
    [results.intersection_update(part) for part in parts]  # type: ignore

    return [
        dict([('text_id', text_id)] + [(field, get_metadata(field, text_id))
                                       for field in fields])
        for text_id in results
    ]
Exemplo n.º 2
0
def metadata(text_id: int, include: Optional[str] = None) -> dict:
    fields = parse_include(include)

    metadata_values = {field: get_metadata(field, text_id) for field in fields}

    return metadata_values
Exemplo n.º 3
0
 def test_bad_include_is_invalid(self):
     with self.assertRaises(InvalidUsage):
         parameters.parse_include('title,foobar,author')
Exemplo n.º 4
0
 def test_empty_uses_default(self):
     fields = parameters.parse_include('')
     self.assertEqual(fields, parameters.ALL_FIELDS)
Exemplo n.º 5
0
 def test_parses_valid_includes(self):
     fields = parameters.parse_include('title,author')
     self.assertEqual(fields, {'title', 'author'})