tags:

views:

186

answers:

2

Hey guys,

The following query takes a while to return:

db.Query<Person>(x => x.StartsWith("Chr", StringComparison.CurrentCultureIgnoreCase))

is there a way to get this working correctly? ie faster?

A: 

adding and index on the column you're comparing would probably help.

http://developer.db4o.com/Documentation/Reference/db4o-7.4/net35/tutorial/docs/Indexes.html#outline219

John Boker
Hi John, when you take out the StringComparison it works instantly again..
ChrisKolenko
+1  A: 

Hi John

Maybe you ran into a limitation of db4o’s query-optimization. Normally Native Queries and LINQ-Queries are translated into a low level SODA-query. When this optimization fails, db4o instantiates the objects in the database in order to execute the query. As you can imagine this can be quite slow.

The best current solution is to use a SODA directly for this case. For example a class with one property:

 public class SimpleObject
 {
     private string name;
     public string Name
     {
         get { return name; }
        set { name = value; }
     }
 }

The native query like this:

var result = db.Query<SimpleObject>(x => x.Name.StartsWith ("Chr",StringComparison.CurrentCultureIgnoreCase));

Can be represented by this SODA-Query:

IQuery query = db.Query();
query.Constrain(typeof (SimpleObject)); // restrict to a certain class
query.Descend("name").Constrain("Chr").StartsWith(false); // the field 'name' starts with  'chr', case-insensitive

foreach (var s in query.Execute())
{
    // 
}

I hope future versions of the Query-Optimizer support this case directly.

Gamlor
Where does "funny" come from?
Erik Forbes
D'oh, copy and past error, I've fixed it. The original example used 'funny' as search-term ;)
Gamlor
who are you Gamlor.. you've replied to a few Db4o questions i've posted :D thanks very much.before you posted this i actually move my code to a SODA query which made it 10000000x faster.. it was just pain full moving to an IList rather than IList<>.. In the doc it stats Linq queries are translated into SODA queries.. maybe there is a fix for this issue inside the expression translation.. might have a look to see if i can fix it and contribute some how :Dthanks for the help guys much appreciated
ChrisKolenko
Both LINQ and Native Query are normally into SODA. For the LIQ-implementation of StartWith/EndWith there's a suggested patch available. But it's not (yet) integrated into the regular source: http://developer.db4o.com/Forums/tabid/98/aff/4/aft/9669/afv/topic/Default.aspx
Gamlor
Thanks for pointing that out Gamlor, I'm learning towards using Lucene to do all my full text searching in the future which should solve a lot of my current searching issues
ChrisKolenko