Support: Wildcard Search capabilities

I recently started exploring faunadb, It looks amazing. It is more than a database.
Great Doc! FQL was slightly harder (since it is new). GraphQL API integration is amazing. Exploring more…

wildcard search capabilities are one of the key features of any small to big scale application
As document explained, currently it is not supported,

Note that FaunaDB does not currently have a full-text or wildcard search capabilities.

Any ETA? Is there any workaround currently?

Hey @jagadeeshpalaniappan, does this stackoverflow answer your questions on the workarounds?


There is a reason you didn’t find that yet, it’s using a function that is currently undocumented (Ngram) which might slightly change in the future to make it easier to use (hence undocumented). Let me know if that doesn’t help you though!

Tbh, it’s not really a ‘workaround’, we are just not focused on providing you one specific way of searching as FaunaDB is a general purpose database and searching can be done in many ways. Instead we offer you the raw power of indexes that you need to implement these things.

For example, someone recently wrote an awesome post on geospatial queries with FaunaDB. What he says there is interesting:

"If you’re lucky and your primary database has geospatial capabilities, you still have to consider the possibility that those capabilities aren’t suited for your work; "

The some goes for searching, there is autocompletion, there is searching on big bodies of text, there is fuzzy searching in small strings. Each of these have slightly different approaches. FaunaDB at the moment provides you with the necessary constructs to implement most. At a certain time we might offer high-level constructs. That is, if our community doesn’t beat us to it since the geoqueries from the geopost are also made available in an NPM library and we’re seeing more and more of those thanks to the compatibility of FQL.

2 Likes

Hey @jagadeeshpalaniappan, I see you liked the answer, is it the answer you were looking for or are you waiting for more answers? If it is, please mark it as answered, that helps us to keep track of open questions :slight_smile:

Thanks for the quick response. Great Reference!

  • Agree, there are lot of usecases / ways we can implement search.
  • I was more interested on Auto Complete (search)
  • Fwitter search example will help my search needs. Even though it has enough comments, but i still feel slightly difficult in understanding. It will be really great, if we have some video tutorials on this topic. It really help beginners (like myself).
  • Meanwhile I will read again those comments and play around.
1 Like

This might be silly question,

I saw this example on that stackoverflow article [Option 1: using ContainsStr() & Filter]

Filter(
  Paginate(Match(Index('tasks_name_and_ref'))),
  Lambda(['name', 'ref'], ContainsStr(LowerCase(Var('name')), 'first'))
)

What i miss in the above code is pagination !!

Is it possible to do something like this? (paginating the filter result) :wink:

CustomPaginate(Filter(
  Paginate(Match(Index('tasks_name_and_ref'))),
  Lambda(['name', 'ref'], ContainsStr(LowerCase(Var('name')), 'first'))
), { size: 5 } )

You are actually already paginating.

But it might not be what you want since you are filtering the paginated results or in other words. You are filtering the pages, if your page contains 10 elements and you filter out 7, of the first, and 10 of the next you will have a first page left of 3 elements and the next page will have zero elements.

The complexity of the execution is important to understand, Filter does not use an index, it’s like a Map that will loop over all the results and apply ContainsStr. The other approaches I pointed you to are more efficient.

I explain this inconvenience of filter and difference in performance iirc in the post I linked: https://stackoverflow.com/questions/61509089/how-to-query-by-multiple-conditions-in-faunadb/61581648#comment108980541_61581648

1 Like

Thank you very much for the help. I understood the search with NGrams and Trigrams.

Instead of Ngrams, I am trying to achieve something like startsWith -for each word in a sentence.
For that, I am facing some problem in writing forLoop. Could you please help me.

function CustomStrGenerate(str) {
  const myArr = [];
  for (let i = 0; i < str.length; i++) {
    myArr.push(str.substr(0, i + 1));
  }
  return myArr;
}

async function main(client) {
  const fql = q.Let(
    {
      words: ["Jagadeesh", "Palaniappan"],
      results: q.Map(
        q.Var("words"),
        q.Lambda("eachWord", CustomStrGenerate(q.Var("eachWord")))
      ),
    },
    q.Var("results")
  );
  const resp = await client.query(fql);
  console.log(resp);
}

I am looking for the below output,

[
 ["J", "Ja", "Jag", "Jaga", "Jagad", "Jagade", "Jagadee", "Jagadees", "Jagadeesh"],
 ["P", "Pa", "Pal", "Pala", "Palan", "Palani", "Palania", "Palaniap", "Palaniapp", "Palaniappa", "Palaniappan"]
]

Could you please help me.

@jagadeeshpalaniappan, I think your new question(s) is/are straying from the original question.

I would suggest creating a new topic under the “help” category, where it will have more visibility and be easier to search for later!

Also,

Like Brecht said, if your original question is answered, please mark it as “solved” for the rest of the community to see. If it’s not, and that is totally fine, This is a good space to continue to ask for clarification about your original post.

Cheers!

Some final notes:

  • I don’t work for Fauna, but I am hoping this is the best advice I can give to kick start this community. I hope Brecht or others at Fauna step in if I doing this wrong.
  • This latest question is an excellent one and very interesting! Might have a go at answering it myself! I just don’t think this is the right place for it.
2 Likes

Hi @ptpaterson
Thanks for the suggestion. Created separate topic.
Could you please help me when you get time.

1 Like