in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

Full Text with FTS2 Engine?

Last post 07-20-2007 11:01 PM by Robert Simpson. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-02-2007 7:11 AM

    • SC-A9
    • Top 500 Contributor
    • Joined on 10-22-2006
    • Posts 3

    Full Text with FTS2 Engine?

    I was wondering if there was any "step by step" HOWTO-type thing on using FTS2 with System.Data.SQLite. I thought there was some test work going on in April but am not sure how to proceed with anything.

    Thanks.

  • 07-20-2007 11:01 PM In reply to

    Re: Full Text with FTS2 Engine?

    Sorry for the late reply.  There's a test in TestCases.cs in the source code distribution which shows an example of using FTS2.  I'll post it here:

    using (DbCommand cmd = cnn.CreateCommand())

    {

    cmd.CommandText = "CREATE VIRTUAL TABLE FullText USING FTS2(name, ingredients);";

    cmd.ExecuteNonQuery();


    string
    [] names = { "broccoli stew", "pumpkin stew", "broccoli pie", "pumpkin pie" };

    string[] ingredients = { "broccoli peppers cheese tomatoes", "pumpkin onions garlic celery", "broccoli cheese onions flour", "pumpkin sugar flour butter" };

     

    int n;

    cmd.CommandText = "insert into FullText (name, ingredients) values (@name, @ingredient);";

    DbParameter name = cmd.CreateParameter();

    DbParameter ingredient = cmd.CreateParameter();

     

    name.ParameterName = "@name";

    ingredient.ParameterName = "@ingredient";

    cmd.Parameters.Add(name);

    cmd.Parameters.Add(ingredient);

    for (n = 0; n < names.Length; n++)

    {

    name.Value = names[n];

    ingredient.Value = ingredients[n];

    cmd.ExecuteNonQuery();

    }

     

    cmd.CommandText = "select rowid, name, ingredients from FullText where name match 'pie';";

    int[] rowids = { 3, 4 };

    n = 0;

    using (DbDataReader reader = cmd.ExecuteReader())

    {

    while (reader.Read())

    {

    if (reader.GetInt64(0) != rowids[n++])

    throw new ArgumentException("Unexpected rowid returned");


    if
    (n > rowids.Length) throw new ArgumentException("Too many rows returned");

    }

    }

    }

    The idea is that you create a full-text index on some text, and use the rowid or some other id as a foreign key in some other table you have.

    Robert

     

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems