www.nipeservice.com
Stefan,
In your example what is the var HS, an object, an order number?
Can these indexes be part of a single index file and be kept up automatically just like any other CDX index.
Regards,
James
Stefan,
In your example what is the var HS, an object, an order number?
Can these indexes be part of a single index file and be kept up automatically just like any other CDX index.
Regards,
James
HS_Index( <cFileName> , ;so it's an error number.
<cExpression> , ;
[<nKeySize>] , ;
[<nOpenMode>] , ;
[<nBufferSize>], ;
[<lCaseInsens>], ;
[<nFilterSet>] ) --> nErrorCode
Hello James,
>Does this include memo fields?
Did you find out if memo fields are included?
Best regards,
Otto
Thanks to all for the help!
// The example creates a new, populated HiPER-SEEK index for
// a customer database.
PROCEDURE Main
LOCAL cIndex, nHandle
CLS
USE Customer ALIAS Cust
cIndex := 'Trim(Cust->LastName) +'
cIndex += '" "'
cIndex += '+ Trim(Cust->FirstName)'
nHandle := HS_Index( "Customer.hsx", cIndex, 3, 0, 16 )
IF nHandle >= 0
? "HiPer-SEEK index successfully created with"
?? HS_KeyCount( nHandle), "index entries"
HS_Close( nHandle )
ELSE
? "HiPer-SEEK index creation failed with error:", nHandle
ENDIF
USE
RETURN// The example demonstrates the pattern matching algorithm employed
// by WildMatch() and how the function can be used as filter condition
// for a database
PROCEDURE Main
LOCAL cStr := "The xHarbour compiler"
? WildMatch( "bo?" , cStr, .F. ) // result: .F.
? WildMatch( "bo?" , cStr, .T. ) // result: .F.
? WildMatch( "*bo" , cStr, .F. ) // result: .T.
? WildMatch( "*bo" , cStr, .T. ) // result: .F.
? WildMatch( "The" , cStr, .F. ) // result: .T.
? WildMatch( "The" , cStr, .T. ) // result: .F.
? WildMatch( "The*r", cStr, .F. ) // result: .T.
? WildMatch( "The*r", cStr, .T. ) // result: .T.
? WildMatch( "The?x", cStr, .F. ) // result: .T.
? WildMatch( "The?x", cStr, .T. ) // result: .F.
USE Customer
SET FILTER TO WildMatch( "W*s", FIELD->LastName )
GO TOP
DbEval( {|| QOut( FIELD->LastName ) } )
// Output: Names starting with "W" and ending with "s"
// Walters
// Waters
CLOSE Customer
RETURNWildMatch() is a pattern matching function that searches a string for a search pattern. If the search pattern is found, the function returns .T. (true).
WildMatch() operates similarly to OrdWildSeek() but can be used as part of a SET FILTER condition on an unindexed database.
* Example 1 - Indexes the whole dbf using hs_index()
LOCAL cExpr := "test->FIRST + test->LAST + test->STREET + test->CITY"
LOCAL nCount := 0, lStrict := .F.
LOCAL cSearch := "Steve John Robert"
LOCAL GetList := {}
CLS
USE test EXCL
IF !file("TEST.HSX")
@ 0,0 "Building HiPer-SEEK Index..."
hs_Index( "TEST.HSX", cExpr, 2 )
?? "Done!"
Inkey(1)
CLS
ENDIF
WHILE .T.
cSearch := PadR( cSearch, 59 )
@ 0,0 SAY "Search Values.....:" GET cSearch
@ 1,0 SAY "Strict Match (Y/N):" GET lStrict PICTURE "Y"
READ
IF LastKey() == K_ESC
CLS
EXIT
ENDIF
cSearch := AllTrim( cSearch )
@ 3,0 SAY "Setting HiPer-SEEK Filter ..."
nCount := hs_Filter( "TEST.HSX", cSearch, iif( lStrict, cExpr, "" ))
?? "Done!"
@ 4,0 SAY LTrim( Str( nCount )) + " records meeting filter condition."
@ 6,0 SAY "Press any key to browse the matching records..."
Inkey(0)
GO TOP
Browse()
CLS
ENDDO
* Example 2 - Adds strings manually to build the index using hs_add().
local nRec, h, bExpr
use test exclusive
h := hs_Open( "TEST.HSX", 10, 1 )
bExpr := { || test->mymemo }
DO WHILE !eof()
nRec := hs_Add( h, bExpr )
IF nRec < 1 .OR. nRec != RecNo()
? "Error adding record " + LTrim( Str( RecNo() )) + "!"
ENDIF
SKIP
ENDDO
Have you looked at FTS indexes in ADS? The free local ADS version works perfectly with dbf/cdx file pairs. These indexes can be used on AOF's() and are very very fast.
Reinaldo.
Everyone,
While all these samples are interesting and very useful, I am not sure we are addressing Otto's problem.
Otto, we still need a description of what kind of search you need to do. Do you need to search for a single word in all memo fields, or maybe more than one word (AND, OR). Is there only one memo field?
I assume that if an index is needed that it needs to be maintained all the time rather than created when used?
Regards,
James
Dear James,
the WildMatch Frank descripts would match my necessity if I can include memofields.
I will do some tests with the code Frank posted.
Best regards,
Otto
static aKunden
function SearchFile( suchbeg )
local nLocation, cData
local nOffset := 0
local cDBF := ( "kunden.dbf" )
local nPos := 0
suchbeg := ALLTRIM(Upper(suchbeg))
cData := Upper(MemoRead( cDBF ))
if Len(cData ) < 1
MsgInfo("Not Data to Search","File Error")
Return Nil
endif
nOffset := 0
do while .t.
nPos := INT( AT( suchbeg, cData, nOffset ))
nLocation := INT( ( nPos - Header() ) / RecSize() ) + 1
nOffset := Header() + nLocation * RecSize() //+ RecSize()
if nPos > 0 .and. nPos < Header()
else
if nLocation < 1
Exit
else
select kunden
goto nLocation
if DELETED() = .F.
aAdd( aKunden, getrec() )
endif
endif
endif
enddo
Return Nil
//----------------------------------------------------------------------------//But it seems not possible.
Gale,
Thanks for all the info. This looks very good.
I do wonder about what is required to switch from CDX indexes to HiperSix indexes. Is this going to require a lot of code changes due to differences in syntax?
Regards,
James
