How to query terms which are neighbour of provided terms?

Hello, I used to go market every day and take pictures of different products which contain brand names. A product can have zero brand names or multiple brand names. I do analysis on the products photos and retrieve brand names from the photo and add a ranking of how well brand name is analyze and store it in database. Now I would like to match query and get the brand names based on the higher ranking, set for the brand name. And after that if I have selected some brand name then I would like to get the new brand names from the photos which contain the selected brand name. I also need to know what will be the correct format for storing this type of data in documents.