V1 0 0
v1_0_0Hasher
¶
Query hasher class for the v1.0.0 query schema.
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
build_geo_polygon_query(points)
staticmethod
¶
Given a series of points, returns a string version of them. Note that we don't sort them as that could change the meaning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
the points as lat lon pairs |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the points |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
664 665 666 667 668 669 670 671 672 673 | |
create_and(group)
¶
Creates and returns a string version of the given group as an and query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
the group to build the and from |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the group |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
494 495 496 497 498 499 500 501 502 503 | |
create_exists(options)
staticmethod
¶
Given the options for a exists term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the exists query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
create_geo_custom_area(coordinates)
¶
Given the coordinates for a geo_custom_area term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
the coordinates for the geo_custom_area query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
create_geo_named_area(options)
staticmethod
¶
Given the options for a geo_named_area term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the geo_named_area query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
624 625 626 627 628 629 630 631 632 633 | |
create_geo_point(options)
staticmethod
¶
Given the options for a geo_point term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the geo_point query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
612 613 614 615 616 617 618 619 620 621 622 | |
create_group_or_term(group_or_term)
¶
Creates and returns a string version of the given group or term dict and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_or_term
|
a dict defining a single group or term |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the group or term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
481 482 483 484 485 486 487 488 489 490 491 492 | |
create_not(group)
¶
Creates and returns a string version of the given group as a not query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
the group to build the not from |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the group |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
516 517 518 519 520 521 522 523 524 525 | |
create_number_equals(options)
staticmethod
¶
Given the options for a number_equals term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the number_equals query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
553 554 555 556 557 558 559 560 561 562 563 564 | |
create_number_range(options)
staticmethod
¶
Given the options for a number_range term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the number_range query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
create_or(group)
¶
Creates and returns a string version of the given group as an or query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
the group to build the or from |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the group |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
505 506 507 508 509 510 511 512 513 514 | |
create_string_contains(options)
staticmethod
¶
Given the options for a string_contains term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the string_contains query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
540 541 542 543 544 545 546 547 548 549 550 551 | |
create_string_equals(options)
staticmethod
¶
Given the options for a string_equals term, creates and returns a string version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the string_equals query |
required |
Returns:
| Type | Description |
|---|---|
|
a string representing the term |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
527 528 529 530 531 532 533 534 535 536 537 538 | |
hash_query(query)
¶
Stable hash function for v1.0.0 queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
the query dict |
required |
Returns:
| Type | Description |
|---|---|
|
the hex digest |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
v1_0_0Schema
¶
Bases: Schema
Schema class for the v1.0.0 query schema.
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
build_geo_polygon_query(points)
staticmethod
¶
Given a list of points (where each point is a list with 2 elements, the longitude and the latitude (note the order, it's the same as the GeoJSON spec)), creates a geo_polygon elasticsearch-dsl query object for the points and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
a list of points |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl query object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
build_multipolygon_query(coordinates)
staticmethod
¶
Utility function for building elasticsearch-dsl queries that represent GeoJSON MultiPolygons. Given the coordinates this function creates a geo_polygon queries and Bool queries to represent the varioud enclosures and holes in those enclosures to find all records residing in the MultiPolygon. The coordinates parameter should match the format required by GeoJSON and therefore be a series of nested lists, see the GeoJSON docs for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
the coordinate list, which is basically a list of Polygons. See the GeoJSON doc for the exact format and meaning |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl object representing the MultiPolygon |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
build_or(terms)
staticmethod
¶
Utility function which when given a list of elasticsearch-dsl query objects, either returns the first one on it's own or creates an "or" query encapsulating them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms
|
a list of elasticsearch-dsl terms |
required |
Returns:
| Type | Description |
|---|---|
|
either a Query object or a Bool should object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
332 333 334 335 336 337 338 339 340 341 342 343 344 | |
create_and(group)
¶
Creates and returns an elasticsearch-dsl query object representing the given group as an and query. This will be a Bool with a must in it for groups with more than 1 member, or will just be the actual member if only 1 member is found in the group. This is strictly unnecessary as elasticsearch/lucerne itself will normalise the query and remove redundant nestings, but we might as well do it here seeing as we can, and it makes smaller elasticsearch queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
the group to build the and from |
required |
Returns:
| Type | Description |
|---|---|
|
the first member from the group if there's only one member in the group, or a Bool |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
create_exists(options)
¶
Given the options for an exists term, creates and returns an elasticsearch-dsl object to represent it. This term maps directly to an elasticsearch exists query. If only one field is present in the fields property then the term query is returned directly, otherwise an or query is returned across all the fields requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the exists query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object or a Bool object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
create_geo_custom_area(coordinates)
¶
Given the coordinates for a geo_custom_area term, creates and returns an elasticsearch-dsl object to represent it. This term takes the equivalent of the coordinates array from a MultiPolygon type feature in GeoJSON and uses it to build a query which captures records that fall in the polygon (and outside any holes defined in the Polygon).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
a MultiPolygon coordinates list |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object (a single geo_polygon Query or a Bool Query) |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
318 319 320 321 322 323 324 325 326 327 328 329 330 | |
create_geo_named_area(options)
¶
Given the options for a geo_named_area term, creates and returns an elasticsearch-dsl object to represent it. This term maps directly to one or more elasticsearch geo_polygon queries, if necessary combined using ands, ors and nots to provide MultiPolygon hole support.
In v1.0.0, Natural Earth Data datasets are used to provide the lists of names
and corresponding geojson areas. The 1:50million scale is used in an attempt to
provide a good level of detail without destroying Elasticsearch with enormous
numbers of points. See the theme/public/querySchemas/geojson/ directory for
source data and readme, and also the load_geojson function in this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the geo_named_area query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object (a single geo_polygon Query or a Bool Query) |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
create_geo_point(options)
¶
Given the options for a geo_point term, creates and returns an elasticsearch- dsl object to represent it. This term maps directly to an elasticsearch geo_distance query. If only one field is present in the fields property then the term query is returned directly, otherwise an or query is returned across all the fields requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the geo_point query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object or a Bool object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
create_group_or_term(group_or_term)
¶
Creates and returns the elasticsearch-dsl query object necessary for the given group or term dict and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_or_term
|
a dict defining a single group or term |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
121 122 123 124 125 126 127 128 129 130 131 132 | |
create_not(group)
¶
Creates and returns an elasticsearch-dsl query object representing the given group as a not query. This will be a Bool with a must_not in it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
the group to build the not from |
required |
Returns:
| Type | Description |
|---|---|
|
a Bool query |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
165 166 167 168 169 170 171 172 173 | |
create_number_equals(options)
¶
Given the options for a number_equals term, creates and returns an elasticsearch-dsl object to represent it. This term maps directly to an elasticsearch term query. If only one field is present in the fields property then the term query is returned directly, otherwise an or query is returned across all the fields requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the number_equals query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object or a Bool object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
create_number_range(options)
¶
Given the options for a number_range term, creates and returns an elasticsearch- dsl object to represent it. This term maps directly to an elasticsearch range query. If only one field is present in the fields property then the term query is returned directly, otherwise an or query is returned across all the fields requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the number_range query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object or a Bool object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
create_or(group)
¶
Creates and returns an elasticsearch-dsl query object representing the given group as an or query. This will be a Bool with a should in it for groups with more than 1 member, or will just be the actual member if only 1 member is found in the group. This is strictly unnecessary as elasticsearch/lucerne itself will normalise the query and remove redundant nestings, but we might as well do it here seeing as we can, and it makes smaller elasticsearch queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
the group to build the or from |
required |
Returns:
| Type | Description |
|---|---|
|
the first member from the group if there's only one member in the group, or a Bool |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
create_string_contains(options)
¶
Given the options for a string_contains term, creates and returns an elasticsearch-dsl object to represent it. This term maps directly to an elasticsearch match query on the .full subfield. If only one field is present in the fields property then the term query is returned directly, otherwise an or query is returned across all the fields requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the string_contains query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object or a Bool object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
create_string_equals(options)
¶
Given the options for a string_equals term, creates and returns an elasticsearch-dsl object to represent it. This term maps directly to an elasticsearch term query. If only one field is present in the fields property then the term query is returned directly, otherwise an or query is returned across all the fields requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
the options for the string_equals query |
required |
Returns:
| Type | Description |
|---|---|
|
an elasticsearch-dsl Query object or a Bool object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
get_filters(query)
¶
Creates a boolean query from the query into the search object and then returns it. If no filters are defined in the query then None is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
dict
|
the whole query dict |
required |
Returns:
| Type | Description |
|---|---|
Optional[Query]
|
a Bool object or None |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
109 110 111 112 113 114 115 116 117 118 119 | |
hash(query)
¶
Hashes the given query and returns the hex digest of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
dict
|
the query dict |
required |
Returns:
| Type | Description |
|---|---|
str
|
the hex digest of the hash of the query |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
61 62 63 64 65 66 67 68 | |
load_geojson(filename, name_keys)
staticmethod
¶
Load the given geojson file, build a lookup using the data and the name_keys parameter and return it.
The geojson file is assumed to be a list of features containing only Polygon or MultiPolygon types.
The name_keys parameter should be a sequence of keys to use to retrieve a name for the feature from the properties dict. The first key found in the properties dict with a value is used and therefore the keys listed should be in priority order. The extracted name is passed to string.capwords to produce a sensible and consistent set of names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
the name geojson file to load from the given path |
required | |
name_keys
|
a priority ordered sequence of keys to use for feature name retrieval |
required |
Returns:
| Type | Description |
|---|---|
|
a dict of names -> MultiPolygons |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
normalise(query)
¶
Corrects some (small) common query errors, e.g. removing empty groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
the query dict |
required |
Returns:
| Type | Description |
|---|---|
|
the corrected/normalised query dict |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
70 71 72 73 74 75 76 77 78 79 | |
translate(query)
¶
Translates the query into an elasticsearch-dsl search object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
dict
|
the whole query dict |
required |
Returns:
| Type | Description |
|---|---|
Query
|
an instantiated elasticsearch-dsl object |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
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 | |
validate(query)
¶
Validates the query against the v1.0.0 schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
dict
|
the query to validate |
required |
Source code in ckanext/versioned_datastore/lib/query/schemas/v1_0_0.py
53 54 55 56 57 58 59 | |