Hello,
I’ve been trying to use full text search queries on .Net driver, so far this N1QL approach works well with the online server but for offline I get weird responses.
My models look like this
public class DummyModel
{
public string Id { get; set; }
public string SomeString { get; set; }
public List<string> SomeList { get; set; }
}
And after add the following models to the database:
var top = new DummyModel()
{
SomeString = "Top 100 movies",
SomeList = new List<string>
{
"The Shawshank Redemption (1994)",
"The Godfather (1972)",
"The Godfather: Part II (1974)",
"The Dark Knight (2008)",
"12 Angry Men (1957)",
"Schindler's List (1993)",
"The Lord of the Rings: The Return of the King (2003)",
"Pulp Fiction (1994)",
"Avengers: Endgame (2019)",
"The Good, the Bad and the Ugly (1966)",
}
};
var topAction = new DummyModel()
{
SomeString = "Top 100 Action movies",
SomeList = new List<string>
{
"The Mountain II (2016)",
"Avengers: Endgame (2019)",
"The Dark Knight (2008)",
"Inception (2010)",
"The Matrix (1999)",
"Star Wars: Episode V - The Empire Strikes Back (1980)",
"Uri: The Surgical Strike (2019)",
"Léon: The Professional (1994)",
"Star Wars: Episode IV - A New Hope (1977)",
"Dangal (2016)"
}
};
var topThriller = new DummyModel()
{
SomeString = "Top 100 Thriller movies",
SomeList = new List<string>
{
"The Dark Knight (2008)",
"Inception (2010)",
"The Usual Suspects (1995)",
"Se7en (1995)",
"Léon: The Professional (1994)",
"The Silence of the Lambs (1991)",
"Andhadhun (2018)",
"The Prestige (2006)",
"The Departed (2006)",
"Memento (2000)"
}
};
var topHistory = new DummyModel()
{
SomeString = "Top 100 History movies",
SomeList = new List<string>
{
"Schindler's List (1993)",
"Ayla: The Daughter of War (2017)",
"Braveheart (1995)",
"Amadeus (1984)",
"Lawrence of Arabia (1962)",
"Downfall (2004)",
"Raise the Red Lantern (1991)",
"The Message (1976)",
"Andrei Rublev (1966)",
"The Great Escape (1963)"
}
};
And create full text indices like so:
var fullTextFields = new List<string>{ "SomeList" };
if (!fullTextFields.Any()) return;
var indices = new List<IFullTextIndexItem>();
foreach (var field in fullTextFields)
{
indices.Add(FullTextIndexItem.Property(field));
}
var ftsIndex = IndexBuilder.FullTextIndex(indices.ToArray()).IgnoreAccents(false);
bucket.Context.CreateIndex("someIndex", ftsIndex)
Searching for “Avengers” gives one result, although it should be two. Searching for Pulp Fiction or Pulp gives zero results but it should be one. Searching for “shawshank” gives one result.
Here’s the full result for each word in the database:
the, 0,
shawshank, 1, Top 100 movies
redemption, 1, Top 100 movies
(1994), 1, Top 100 movies
godfather, 0,
(1972), 0,
godfather:, 0,
part, 0,
ii, 1, Top 100 Action movies
(1974), 0,
dark, 2, Top 100 Action movies, Top 100 Thriller movies
knight, 2, Top 100 Action movies, Top 100 Thriller movies
(2008), 2, Top 100 Action movies, Top 100 Thriller movies
12, 0,
angry, 0,
men, 0,
(1957), 0,
schindler's, 1, Top 100 History movies
list, 1, Top 100 History movies
(1993), 1, Top 100 History movies
lord, 0,
of, 0,
the, 0,
rings:, 0,
return, 0,
king, 0,
(2003), 0,
pulp, 0,
fiction, 0,
avengers:, 1, Top 100 Action movies
endgame, 1, Top 100 Action movies
(2019), 4, Top 100 movies, Top 100 Action movies, Top 100 Thriller movies, Top 100 History movies
good,, 0,
bad, 0,
and, 0,
ugly, 0,
(1966), 0,
mountain, 1, Top 100 Action movies
(2016), 1, Top 100 Action movies
inception, 2, Top 100 Action movies, Top 100 Thriller movies
(2010), 2, Top 100 Action movies, Top 100 Thriller movies
matrix, 1, Top 100 Action movies
(1999), 1, Top 100 Action movies
star, 0,
wars:, 0,
episode, 0,
v, 0,
-, 0,
empire, 0,
strikes, 0,
back, 0,
(1980), 0,
uri:, 0,
surgical, 0,
strike, 0,
léon:, 0,
professional, 0,
iv, 0,
a, 0,
new, 0,
hope, 0,
(1977), 0,
dangal, 0,
ayla:, 0,
daughter, 0,
war, 0,
(2017), 0,
braveheart, 0,
(1995), 1, Top 100 Thriller movies
amadeus, 0,
(1984), 0,
lawrence, 0,
arabia, 0,
(1962), 0,
downfall, 0,
(2004), 0,
raise, 0,
red, 0,
lantern, 0,
(1991), 0,
message, 0,
(1976), 0,
andrei, 0,
rublev, 0,
great, 0,
escape, 0,
(1963), 0,
usual, 1, Top 100 Thriller movies
suspects, 1, Top 100 Thriller movies
se7en, 0,
silence, 0,
lambs, 0,
andhadhun, 0,
(2018), 0,
prestige, 0,
(2006), 0,
departed, 0,
memento, 0,
(2000), 0,
I really don’t understand the pattern here, for online database, it works as expected.
This is the function to search by the way:
var ftsExpression = FullTextExpression.Index(_index).Match($"'{_term}'");
var query = QueryBuilder.Select(SelectResult.Expression(Meta.ID))
.From(DataSource.Database(bucket.Context))
.Where(ftsExpression)
.Limit(Expression.Int(_limiting.Limit == 0 ? 1000 : _limiting.Limit), Expression.Int(_limiting.Offset));
var res = query.Execute();
foreach (var result in res)
{
var id = result.GetString("id");
var model = someFunctionToGetModel(id);
yield return JsonConvert.DeserializeObject<ttv>(JsonConvert.SerializeObject(model));
}
Thanks in advance.