How to query index created in CBL 2.0 DB20?

Suppose I create an index from a non-null variable of type Database named ‘database’.

final FTSIndexItem indexItem = FTSIndexItem.expression(“foo”));
database.createIndex(“MyFTSIndex”, Index.ftsIndex().on(indexItem));

When I create a Query object, how do I use the index I created, “MyFTSIndex”?

Please refer to query examples in the blog post

You do not explicitly have to specify this index in the query. It would be applied automatically if you are querying on a property that is indexed.

For example, if you create a value index on type property
try _db?.createIndex(Index.valueIndex().on( ValueIndexItem.expression("type"))), withName: "TypeIndex")

The index would be applied when you run a Query of the form where you are querying on the type property

let searchQuery = Query .select(SelectResult.all()) .from(DataSource.database(db)) .where("type").equalTo("hotel")) .limit(limit)

You would be something similar with FTS Index and corresponding match query

Hi @priya.rajagopal,

Can I use a ValueIndexItem with a condition-based expression (ValueIndexItem.expression("type").equalTo("hotel"))?

Did you mean “partial indexes” ? If so, no you can’t do that at this time.

(Also FFR, please create a separate thread if its a new topic instead of resurrecting a 2 year old thread that is discussing something not directly related in the context of a Developer Build )

Sure and thanks for replying. I found this example matching my search about the partial indexes. I’ll start a new thread to continue the further discussion on this.