Boosting documents where more than one field matches terms

Hi

We have a question regarding how to do some ranking on our queries, which may also fall back on to how to best index our data.

Our scenario is that we have documents something along the lines of a Model, which then contains arrays of Colours (with multiple fields in each Colour object) and Shapes (with multiple fields on each Shape object).

Example documents:

{
    "model": "1",
    "colours": [
        {
            "name": "Magenta",
            "rgb": "FFFF00"
        },
        {
            "name": "blue",
            "rgb": "0000FF"
        }
    ],
    "shapes": [
        {
            "name": "square",
            "sides": 4
        },
        {
            "name": "rectangle",
            "sides": 4
        },
        {
            "name": "triangle",
            "sides": 3
        }
    ]
},
{
    "model": "2",
    "colours": [
        {
            "name": "red",
            "rgb": "FF0000"
        },
        {
            "name": "blue",
            "rgb": "0000FF"
        }
    ],
    "shapes": [
        {
            "name": "ellipse",
            "sides": 4
        },
       {
            "name": "triangle",
            "sides": 3
        }
    ]
},
{
    "model": "3",
    "colours": [
        {
            "name": "red",
            "rgb": "FF0000"
        },
        {
            "name": "yellow",
            "rgb": "00FFFF"
        },
        {
            "name": "green",
            "rgb": "00FF00"
        }
    ],
    "shapes": [
        {
            "name": "ellipse",
            "sides": 1
        } 
    ]
}

When we search, the query will include terms for Colours & Shapes, searching one or more of the fields with each search term.

What is critical for us is to highly rank any items that match on both colour and shape. This should rank higher than something that matched on colour or shape alone - even.

So - if I searched the above data for
Colours
Name = Red
Name = Yellow
Name = Green
RGB = 00FFFF

Shapes
Name = Triangle
Name = Square
Name = Rectangle
Sides= 4

Model 1 would match on all the shapes but no colours. I still want this result but with a low rank.
Model 2 would match on red and triangle - this is the item I am most interested in and want to boost the fact it matches on two parts of the path as a priority.
Model 3 would match on all the colours but no shapes. I still want this result but with a low rank.

The above is a simplicifation and we may have dozens of terms, maybe matching on 10 or 20 colours or shapes - however still the items that matches on both colour and shape should be (by far) the highest ranked.

What would be a good way to go about this?

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.