Need to Order by best match

Continuing the discussion from Ordering of results in `anyofterms` query:

@MichelDiz forgive me, but I am not seeing an existing feature request, so I am creating this one.

Experience Report for Feature Request

What you wanted to do

Do term based matching and order by best matching first.

What you actually did

Why that wasn’t great, with examples

Because now my head hurts. (See example above)

Any external references to support your case

It can be done with SQL type languages using CASE in the ORDER BY clause:

It can sort of be done using field weights against a MongoDB:

Here is an approach for ordering based upon matched string length vs. total string length in SPARQL:

All of these do seem more like hacks than actual true solutions, but even a hack isn’t available with pure GraphQL. I think it is possible with DQL, but trying to utilize this functionality on GQL to enable deep nested graphs.

2 Likes

My use case:

I have a firstName field and a lastName field.

I can use anyofterms and match against these fields with a single string. If the string matches a term in both fields, I want it at the top of the list.

What would be really nice is to weight the fields somehow because matching the last name would have more priority over matching the first name. (ie: “Bob Jones” might actually be “Robert Jones” or “Bobby Jones”) I also have a nickName field, so matching against three fields with a single string, I would like to match in order of lastName, firstName, nickName, [middleName, Suffix, Prefix]. This would give a really good order of best match vs. a otherwise seemingly ordered list.

And if we get something relative close to string functions, I would really love to match vs a concatenated string. This would be the best match as in the example above I would want “Bob Jones” over “Jones Bob”.

LOL

I feel there are two things are that are needed to be considered.
First, there is a need to boost one result over the other.
Secondly, I feel there is a need for defining the distance between search query and field in documents. There are many standard algorithms like Jaro Winkler Distance or Levenshtein Distance that can help here.

Even though last name matches are high weighted, I guess there is still a problem of random order among last name matched entities.

Just trying to understand the problem in more detail.