Comments (7)
It should be possible to expose _score
(however, it's not always available). Let me know if you have trouble implementing this. Eventually, PRs are welcome.
from graphene-elastic.
How would this be done? Would I have to create a custom resolver to retrieve the _score
attribute? Is that attribute going to be available on the parent object within an ElasticsearchObjectType resolver?
from graphene-elastic.
Yep. Most likely, through a filter backend. It should be done in a declarative, non-breaking manner. Somewhat, like in highlight, but much simpler.
from graphene-elastic.
Check this (not yet released, just pushed into master):
from graphene import Node
from graphene_elastic import ElasticsearchObjectType
from graphene_elastic.filter_backends import (
# ...
ScoreFilterBackend,
OrderingFilterBackend,
# ...
)
from search_index.documents import Post as PostDocument
class Post(ElasticsearchObjectType):
class Meta:
document = PostDocument
interfaces = (Node,)
filter_backends = [
# ...
ScoreFilterBackend,
OrderingFilterBackend,
# ...
]
# For `OrderingFilterBackend` backend
ordering_fields = {
# The dictionary key (in this case `tags`) is the name of
# the corresponding GraphQL query argument. The dictionary
# value (in this case `tags.raw`) is the field name in the
# Elasticsearch document (`PostDocument`).
'title': 'title.raw',
# The dictionary key (in this case `created_at`) is the name of
# the corresponding GraphQL query argument. The dictionary
# value (in this case `created_at`) is the field name in the
# Elasticsearch document (`PostDocument`).
'created_at': 'created_at',
# The dictionary key (in this case `num_views`) is the name of
# the corresponding GraphQL query argument. The dictionary
# value (in this case `num_views`) is the field name in the
# Elasticsearch document (`PostDocument`).
'num_views': 'num_views',
# Score
'score': '_score',
}
Do make sure you have added ordering results by score
(as shown in ordering_fields
above).
Query like this:
query PostsQuery {
allPostDocuments(
search:{query:"Budget"},
filter:{category:{value:"Elastic"}},
ordering:{score:DESC}
) {
edges {
node {
id
title
category
content
createdAt
score
}
}
}
}
Will produce results similar to these:
{
"data": {
"allPostDocuments": {
"edges": [
{
"node": {
"id": "UG9zdDpMNnBiV1hNQjhYRzdJclZ2X20waA==",
"title": "Budget.",
"category": "Elastic",
"content": "Bed television public teacher behind human up.\nMind anyone politics ball cost wife try adult. College work for.\nPlay five ten not sort energy.\nCommon word behind spring. All behind voice policy.",
"createdAt": "1973-03-12T00:00:00",
"score": 20.420774
}
},
]
}
}
}
from graphene-elastic.
Oh wow, thanks for the quick code update! I'll try it out tomorrow.
from graphene-elastic.
Some more work is done on this. It's now possible (in master) to allow sorting on score (if added as option to the ordering_fields
). See updated example.
from graphene-elastic.
Released in 0.6.3.
from graphene-elastic.
Related Issues (20)
- [Question] Mutations and Subscriptions? HOT 2
- How to use a non-default elastic connection HOT 1
- How to use connection between indices HOT 3
- Refresh index before querying HOT 1
- Is it possible to combine graphene-elastic with graphene-django? HOT 2
- Fiter several fields using OR HOT 3
- Add documentation on query string and simple query string backends
- Add more complex tests to query string and simple query string backends
- Fix failing travis config
- Implement search_as_you_type field
- Possibility to use the request object in Filter backends HOT 1
- Support for `search_after`
- Question: Resolve data across indices HOT 2
- Flexible aggregations
- Migrate to GitHub actions
- How to handle foreign fields HOT 1
- "Received incompatible instance" errors with basic setup HOT 10
- Migrate to anysearch (support both Elasticsearch and OpenSearch) HOT 1
- Add support for Graphene 3.x HOT 2
- How to filter on nested document fields
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene-elastic.