How to search text directly from database field

General TRichView support forum. Please post your questions here
Post Reply
JSH2
Posts: 7
Joined: Sat Apr 21, 2007 12:27 pm

How to search text directly from database field

Post by JSH2 »

I would like to search all records including a given text from database, which has a field containing RichViewEdit data.

A simple method is that using database scrolling function as follows:

aTbale.first;
while not aTbale.EOF do begin
if DBRichViewEdit.searchtext() then begin
...
end;
aTable.Next;
end;

But the database table is a master table, i.e., it has many detail database tables.
I think this method is not efficient.
So I want to use a cloned database table which is only for searching, and the table is not linked a DBRichViewEdit.

if there is a external text searching function like
function RVSearchText( RVDBData, aText, SearchOption) :boolean;
,this is more efficeint maybe.

Is there another method for searching a text directly from database field value?

Thanks in advance.

Seungho Jung
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's quite a complicated work to parse RVF document from database without using trichview control.
However, using TDBRichView/TDBRichViewEdit with SearchText is not the fastest way, because TDBRichView/TDBRichViewEdit formats document after loading. Formatting is the slowest operation, it takes longer than loading and searching. So if you just load document, without formatting, it would be much faster.
SearchText selects the found text, so it requires formatted trichview For unformatted trichviews, we need to use another method.

So, the procedure would be

Code: Select all

while not aTable.EOF do begin 
  Stream := aTable.CreateBlobStream(aTable.FieldByName(FieldName), bmRead);
  HiddenRichView.LoadFromStream(Stream, rvutNo);
  Stream.Free;
  if ContainsText(HiddenRichView.RVData, s) then begin 
  ... 
  end; 
  aTable.Next; 
end; 

Code: Select all

function ContainsText(RVData: TCustomRVData; const s: String);
var i,r,c: Integer;
     table: TRVTableItemInfo;
     ItemText: String;
begin
  for i := 0 to RVData.ItemCount-1 do
    if RVData.GetItemStyle(i)>=0 then begin // this is a text item
      ItemText := RVData.GetItemTextA(i);
      // you can change the next line to support search options // ignore case, etc.
      Result := AnsiPos(s, ItemText)>0;
      if Result then
        exit;
    end
    else if RVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.RowCount-1 do
        for c := 0 to table.ColCount-1 do
          if table.Cells[r,c]<>nil then begin
            Result := ContainsText(table.Cells[r,c].GetRVData, s);
            if Result then
              exit;
          end;
    end;
  Result := False;
end;
Tobias
Posts: 5
Joined: Sat Jan 30, 2010 5:55 pm

Post by Tobias »

I am tried this code, it works fine, but when there are hyper-links in text it throws exception like:

Code: Select all

Exception class EConvertError with message ''http://www.google.com' is not a valid integer value'.
Seems it in RVFReadTag function, but I can't trace as there are no sources in trial :D

Or may be there better way to fast search several documents (from database) not displaying it?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Include rvoTagsArePChars in HiddenRichView.Options.
Post Reply