Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 13 total
Thread FindKey vs Locate
Mon, Jun 8 2009 11:46 PMPermanent Link

"David Cornelius"
I've been using Locate to provide incremental search support for on an
indexed field in my application.  A customer brought it to my attention
that sometimes, when there are two values that start with the same
characters, the longer is selected first.

For example if the customer was searching for invoice numbers and there
was an invoice with a couple of derivitives like this:
 15602
 15602-COMMISSION
then sometimes the "-COMMISSION" one would get highlighted first (if
the customer had typed "15602"), but other times the regular one would.
After doing some research, I realized that in the cases where
15602-COMMISSION came up first, that record had actually been entered
physically in the database before the 15602 one had.

So I deduced that Locate finds the first physical record in the
database that partially matches, even if it shouldn't be the "real"
first one found.  (The first of these two, of course, should be 15602.).

Next, I used FindKey.  FindKey doesn't find any of the partial matches
and the application just sits there blinking until a complete match is
made.  In this case, of course, 15602 is found first--correctly.

So now I have to decide between incremental search or properly keyed
search, right?

While typing this, I just saw FindNearest and will try that as well,
but am wondering if this is a side-effect of using a EDBTable over a
EDBQuery?  Anyway, I'd appreciate comments as I'd like to give my
customer their cake and let them eat it, too!

Thanks,

--
David Cornelius
CorneliusConcepts.com
Tue, Jun 9 2009 2:18 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

David


In the .Locate do you have the loPartialKey specified and is there an index on the keyfields?

I've just read Tim's pdf manual and the D2006 help and neither are clear on what should happen if an index exists, but "common sense" says that the result should be according to the index. If no index (but I'm guessing there is one otherwise you can't use FindKey) then it is in physical table order which matches what you're seeing.

Roy Lambert [Team Elevate]
Tue, Jun 9 2009 9:59 AMPermanent Link

"David Cornelius"
1> In the .Locate do you have the loPartialKey specified and is there an
> index on the keyfields?
>
> I've just read Tim's pdf manual and the D2006 help and neither are
> clear on what should happen if an index exists, but "common sense"
> says that the result should be according to the index. If no index
> (but I'm guessing there is one otherwise you can't use FindKey) then
> it is in physical table order which matches what you're seeing.

Yes, I forgot to mention it, but the field I'm searching on is
definitely indexed.  It's a single-field index and when I run a query
in EDB Manager the fields are sorted correctly, IOW: 15602 comes before
15602-COMMISSION.

--
David Cornelius
CorneliusConcepts.com
Tue, Jun 9 2009 10:57 AMPermanent Link

Sean
David,

You can code a work around:

In pseudo code:

DisableControls;
try
  Locate;
  if FieldMatchesLocateText then begin
    repeat
      Prior;
    until BOF or (FieldMatchesLocateText = False);
    Next;
  end;
finally
  EnableControls;
end;

-Sean



David Cornelius wrote:
> I've been using Locate to provide incremental search support for on an
> indexed field in my application.  A customer brought it to my attention
> that sometimes, when there are two values that start with the same
> characters, the longer is selected first.
>
> For example if the customer was searching for invoice numbers and there
> was an invoice with a couple of derivitives like this:
>   15602
>   15602-COMMISSION
> then sometimes the "-COMMISSION" one would get highlighted first (if
> the customer had typed "15602"), but other times the regular one would.
> After doing some research, I realized that in the cases where
> 15602-COMMISSION came up first, that record had actually been entered
> physically in the database before the 15602 one had.
>
> So I deduced that Locate finds the first physical record in the
> database that partially matches, even if it shouldn't be the "real"
> first one found.  (The first of these two, of course, should be 15602.).
>
> Next, I used FindKey.  FindKey doesn't find any of the partial matches
> and the application just sits there blinking until a complete match is
> made.  In this case, of course, 15602 is found first--correctly.
>
> So now I have to decide between incremental search or properly keyed
> search, right?
>
> While typing this, I just saw FindNearest and will try that as well,
> but am wondering if this is a side-effect of using a EDBTable over a
> EDBQuery?  Anyway, I'd appreciate comments as I'd like to give my
> customer their cake and let them eat it, too!
>
> Thanks,
>
Tue, Jun 9 2009 2:03 PMPermanent Link

"David Cornelius"
> You can code a work around:
>
> In pseudo code:
>
> DisableControls;
> try
>   Locate;
>   if FieldMatchesLocateText then begin
>     repeat
>       Prior;
>     until BOF or (FieldMatchesLocateText = False);
>     Next;
>   end;
> finally
>   EnableControls;
> end;

That's a really good suggestion.  And it's pretty obvious too, now that
I'm stepping back away from the problem a bit.  Thanks very much!

--
David Cornelius
CorneliusConcepts.com
Tue, Jun 9 2009 3:20 PMPermanent Link

"Lucian Radulescu"
David Cornelius wrote:

> > You can code a work around:
> >
> > In pseudo code:
> >
> > DisableControls;
> > try
> >   Locate;
> >   if FieldMatchesLocateText then begin
> >     repeat
> >       Prior;
> >     until BOF or (FieldMatchesLocateText = False);
> >     Next;
> >   end;
> > finally
> >   EnableControls;
> > end;


Sorry to intervene, there's an extreme corner case, how does this work
when the record found is the first in the table?
Prior won't do anything, repeat exits because BOF is true, than Next
jumps on a non-matching record ... !!!KPOW!!!

Lucian
Tue, Jun 9 2009 4:01 PMPermanent Link

Sean
Lucian,

Good catch. Prior actually does do something - it sets BOF=True - BOF is
false after the successful locate even if the record found is the first
one in the ordered dataset. As you pointed out Next should not be called
when BOF is detected. This should take care of it:

DisableControls;
try
  Locate;
  if FieldMatchesLocateText then begin
  repeat
    Prior;
    if FieldMatchesLocateText = False then begin
      Next;
      Break;
    end;
  until BOF;
finally
  EnableControls;
end;

-Sean

Lucian Radulescu wrote:
> David Cornelius wrote:
>
>>> You can code a work around:
>>>
>>> In pseudo code:
>>>
>>> DisableControls;
>>> try
>>>   Locate;
>>>   if FieldMatchesLocateText then begin
>>>     repeat
>>>       Prior;
>>>     until BOF or (FieldMatchesLocateText = False);
   if FieldMatchesLocateText = False then begin
          Next;
   end;
>>>   end;
>>> finally
>>>   EnableControls;
>>> end;
>
>
> Sorry to intervene, there's an extreme corner case, how does this work
> when the record found is the first in the table?
> Prior won't do anything, repeat exits because BOF is true, than Next
> jumps on a non-matching record ... !!!KPOW!!!
>
> Lucian
Wed, Jun 10 2009 3:02 AMPermanent Link

"David Cornelius"
Awesome!  Thanks both of you!

I even added one more tiny step: a keystroke timer.

Everytime a change is made to the search characters, I restart the
keystroke timer for 300 ms.  Once the keystroke timer goes off, I do
the incremental search, which allows the user to type in a bunch of
characters before it tries to search on any of them.

The customer will love this!

--
David Cornelius
CorneliusConcepts.com
Wed, Jun 10 2009 4:22 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

David,

<< I've been using Locate to provide incremental search support for on an
indexed field in my application.  A customer brought it to my attention that
sometimes, when there are two values that start with the same characters,
the longer is selected first.

For example if the customer was searching for invoice numbers and there was
an invoice with a couple of derivitives like this:
 15602
 15602-COMMISSION
then sometimes the "-COMMISSION" one would get highlighted first (if the
customer had typed "15602"), but other times the regular one would. After
doing some research, I realized that in the cases where 15602-COMMISSION
came up first, that record had actually been entered physically in the
database before the 15602 one had.

So I deduced that Locate finds the first physical record in the database
that partially matches, even if it shouldn't be the "real" first one found.
(The first of these two, of course, should be 15602.). >>

The only time Locate will behave like you want is if the Locate is using the
active index for the search.  Any other time, the search must be done using
a row scan or an index scan of another index, and there really is no way for
EDB to reconcile the those two with the active index in any sort of quick
fashion, which is why it doesn't even try.

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Jun 10 2009 5:42 PMPermanent Link

"David Cornelius"
> The only time Locate will behave like you want is if the Locate is
> using the active index for the search.  Any other time, the search
> must be done using a row scan or an index scan of another index, and
> there really is no way for EDB to reconcile the those two with the
> active index in any sort of quick fashion, which is why it doesn't
> even try.

But it *is* using the active index!  That's why I asked this
question--because I didn't expect it to do what it did.  In fact, I
pass in the IndexFieldNames property of the dataset as the first
parameter of the call to Locate so that if the index changes, it still
searches on the proper field.

By the way, under the edit box where the user types in the incremental
search characters, is a grid showing the rows of the dataset being
searched.  Below that is a combo box that allows the user to select a
different index.  When the index is changed, the grid immediately
reflects the new sort order and the search edit box is cleared.  As
characters are typed, the highlighted row in the grid jumps down to
what is matching their typed characters so far.

--
David Cornelius
CorneliusConcepts.com
Page 1 of 2Next Page »
Jump to Page:  1 2
Image