Couchbase Lite 2 Full Text Search

Hello,

I have found an example for fts support in cb 2. So I have implemented the index the following way:

var name = “fts_index”
var indices = new List();
// fullTextFields is a string list of fields to be indexed
foreach (var field in fullTextFields)
{
indices.Add(FullTextIndexItem.Property(field.Key));
}
var ftsIndex = IndexBuilder.FullTextIndex(indices.ToArray());
Context.CreateIndex(name, ftsIndex);

Then i am calling my Query with following params:

var term = string.empty; //the search term tb replaced by any valid term
var ftsExpression = FullTextExpression.Index(“fts_index”);
var query = QueryBuilder.Select(SelectResult.Expression(Meta.ID))
.From(DataSource.Database(Context))
.Where(Expression.Property(“Type”).EqualTo(Expression.String(typeof(tt).Name))
.And(ftsExpression.Match(term + “*”)))
.Limit(Expression.Int(1000), Expression.Int(0));
var res = query.Execute();

no matter what i set for term i do not get any results… res is always not containing a collection. with string empty all items of type tt should be returned…

Any idea?

TY

Please post the string returned by calling explain on the Query object — this will include the SQL translation of the query.

Have you verified that typeof(tt).Name) has the value you expect, and that this matches the docs in the DB?

Hi,

Thank you for your answer, here is the Explain output:

SELECT kv_default.rowid, offsets(“kv_default::fts_index”), fl_result(key) FROM kv_default JOIN “kv_default::fts_index” AS FTS1 ON FTS1.docid = kv_default.rowid WHERE (fl_value(body, ‘Type’) = ‘ScenarioModel’ AND FTS1.“kv_default::fts_index” MATCH ‘*’) AND (flags & 1) = 0 LIMIT MAX(0, 1000) OFFSET MAX(0, 0)
0|0|1| SCAN TABLE kv_default::fts_index AS FTS1 VIRTUAL TABLE INDEX 49:
0|1|0| SEARCH TABLE kv_default USING INTEGER PRIMARY KEY (rowid=?)

Type ‘ScenarioModel’ is contained in my database.

You used an uppercase “Type” property in the query. Is that the exact name used in the docs? (The usual convention is “type”.)

Other than that it looks OK. I’m not sure a query string of “*” matches all docs, but presumably you tried it with other strings too.

Yes i am using the upper Case for Type.
A normal Query like:

var query = QueryBuilder.Select(SelectResult.Expression(Meta.ID)) .From(DataSource.Database(Context)).Where(Expression.Property(“Type”).EqualTo(Expression.String(typeof(tt).Name)));

returns the results perfectly.

Only with fulltextsearch i do not get any results…

and yes i have tried different terms, but none is working

anyone else who can support on this issue? :slight_smile:

If you believe it’s an issue then create a simple self contained program that shows the unexpected behavior and someone will look at it if you file an issue