JanusGraph / JanusGraph/janusgraph

Use BM25 score from Elasticsearch to order results

Open
#4,799 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5.8k
Forks
1.2k
Avg merge
13h 53m
Merged PRs (30d)
6

Description

**Describe the feature:**
When using mixed indexes, it seems that there is no option to sort Gremlin results according to [Okapi BM25](https://en.wikipedia.org/wiki/Okapi_BM25) relevance score provided by Elasticsearch
That would be very handy to have order method to have an option to sort by score value, or alternatively, provide the score value inline with vertex properties.

**Describe a specific use case for the feature:**
One of such use cases might be a search function.
It boils down to mixed index with number of vertex properties indexed as TEXT and set with different boost weights.

For example, having my mixed index include:
- Property "Name" with boost weight of 5
- Property "Topic" with boost weight of 4
- Property "Desc" with boost weight of 1
```
mgmt.buildIndex('myIndex', Vertex.class)
.addKey(nameProperty, Mapping.TEXT.asParameter(), Parameter.of(ParameterType.customParameterName("boost"), 5))
.addKey(topicProperty, Mapping.TEXT.asParameter(), Parameter.of(ParameterType.customParameterName("boost"), 4))
.addKey(descProperty, Mapping.TEXT.asParameter(), Parameter.of(ParameterType.customParameterName("boost"), 1))
.buildMixedIndex("search")
```
I would expect the results to be sorted with the relevance score in mind as I execute my query, or get the score together with gremlin response to sort it later in the application.

```
g.V().or(
has('Name',textContainsPrefix("ProjectA")),
has('Topic',textContainsPrefix("ProjectA"))
has('Desc',textContainsPrefix("ProjectA"))
).order().by(score, desc)
```
I could achieve the desired results by querying index directly with indexQuery() method, getting the correct relevance score with getScore(), but I would very much like to have it working within gremlin.

If it is not currently implemented, perhaps there is a way to customize the query and inject my own sorting/ordering mechanism using some smart mechanics like TraversalStrategy.

Is that even possible?

Link to [StackOverflow](https://stackoverflow.com/questions/79651932/use-bm25-score-from-elasticsearch-to-order-gremlin-results)

Contributor guide

Open the contributing guide

Research direction

No source files or tests are named. Start by comparing the existing indexQuery() and getScore() path with Gremlin ordering, then inspect whether a TraversalStrategy provides a documented extension point; done should mean a confirmed, tested way to expose or order by the Elasticsearch relevance score in Gremlin, or a clear limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
elasticsearch, java
Domain
databases, search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.