I'm working on a project where I need to create search functionality that can efficiently search a list of data structures like:

json1 = [
    "name": "bob",
    "age": 55,
    "active": false,
    "location": {
      "state": "FF",
      "country": "NZ"
    "name": "susan",
    "age": 30,
    "active": true,
    "location": {
      "state": "BB",
      "country": "USA"
json2 = [...]

The user would in put something like categories: [json1, json2], fields: [name, location], search_term: "bob"

It needs to support complex queries. I've looked at inverted indexing used in search engines but all the implementations I see are for text searching, not searching data structures and they don't appear to be suitable for filtering based on a data structure field etc. I have the following requirements:

  • Needs to be able to search based on a field (ie name/age/active)
  • It very likely will need to support searching like search value > 40 IN json1 FIELD age
  • Needs to support nested structures like location

Are there any data structures more suitable than an inverted index? If inverted indexing is the way to go can you please provide guidance on how the structure should look in order to support my requirements? Any general reading suggestions on the matter would also be great.

  • 2
    $\begingroup$ I don't understand what kinds of search queries you want to support. I don't know what categories: [json1, json2], fields: [name, location], search_term: "bob" means or what it is supposed to match. You say you want to support "complex queries" but that is quite vague. You list two kinds of queries. Are those the only queries you need to handle? Or do you also want to handle complex predicates (e.g., conjunctions of these)? $\endgroup$
    – D.W.
    May 27 '21 at 21:44
  • $\begingroup$ Also, I'm not sure what it means to "support" nested structures. I'm not sure what kind of search query that corresponds to. Without knowing the set/space of possible queries, I doubt the question will be answerable in a useful way. $\endgroup$
    – D.W.
    May 27 '21 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.