Changeset 333
- Timestamp:
- Aug 31, 2008, 2:01:55 PM (17 years ago)
- Location:
- branches/2.19_branch/NewView
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.19_branch/NewView/HelpTopic.pas
r290 r333 1460 1460 ): longint; 1461 1461 var 1462 WordSequence: TList;1463 SequenceStepIndex: longint;1462 tmpWordSequence: TList; 1463 tmpSequenceStepIndex: longint; 1464 1464 pSequenceStepWords: Uint32ArrayPointer; 1465 1465 … … 1476 1476 for SequenceIndex := 0 to WordSequences.Count - 1 do 1477 1477 begin 1478 WordSequence := WordSequences[ SequenceIndex ];1479 pSequenceStepWords := WordSequence[ 0 ];1478 tmpWordSequence := WordSequences[ SequenceIndex ]; 1479 pSequenceStepWords := tmpWordSequence[ 0 ]; 1480 1480 1481 1481 if pSequenceStepWords^[ GlobalDictIndex ] > 0 then 1482 1482 begin 1483 1483 // matched first step in this sequence. Look ahead... 1484 1485 SequenceStepIndex := 0; 1484 tmpSequenceStepIndex := 1; 1486 1485 1487 1486 pDataTemp := pData; 1488 1487 SlotIndexTemp := SlotIndex; 1489 1488 StateTemp := State; 1489 1490 1490 while true do 1491 1491 begin 1492 inc( SequenceStepIndex ); 1493 if SequenceStepIndex = WordSequence.Count then 1494 begin 1495 // have a match for the sequence, insert start highlight 1496 Result := WordSequence.Count; 1492 if tmpSequenceStepIndex = tmpWordSequence.Count then 1493 begin 1494 // have a match for the sequence; time to leave 1495 Result := tmpWordSequence.Count; 1497 1496 break; 1498 1497 end; 1499 1498 1500 1499 // get words for next step in sequence 1501 pSequenceStepWords := WordSequence[ SequenceStepIndex ]; 1502 1503 DictIndex := GetNextIPFTextItem( SlotIndexTemp, 1504 pDataTemp, 1505 StateTemp ); 1500 pSequenceStepWords := tmpWordSequence[ tmpSequenceStepIndex ]; 1501 1502 DictIndex := GetNextIPFTextItem( SlotIndexTemp, pDataTemp, StateTemp ); 1506 1503 if DictIndex = -2 then 1507 1504 begin … … 1518 1515 1519 1516 // s := pstring( _GlobalDictionary[ DictIndex ] )^; // for debug only 1517 1518 1519 // ignore whitespace 1520 1520 if not StrIsEmptyOrSpaces( pstring( _GlobalDictionary[ DictIndex ] )^ ) then 1521 1521 begin … … 1525 1525 break; 1526 1526 end; 1527 1528 // match; next one 1529 inc(tmpSequenceStepIndex); 1527 1530 end; 1528 1531 … … 1533 1536 end; // for sequenceindex ... 1534 1537 end; 1538 1535 1539 1536 1540 // Main translation function. Turns the IPF data into … … 1637 1641 1638 1642 if ShowWordSeparators then 1643 begin 1639 1644 Text.AddString( '{' + IntToStr( GlobalDictIndex )+ '}' ); 1645 end; 1640 1646 1641 1647 // normal lookup … … 1656 1662 // store string into "word" 1657 1663 if State.TextBlock.Length = 0 then 1664 begin 1658 1665 // store start of block 1659 1666 State.StartOfTextBlock := Text.Length; 1667 end; 1660 1668 1661 1669 State.TextBlock.AddString( StringToAdd ); … … 1672 1680 begin 1673 1681 // now finished, insert end highlight 1674 StringToAdd := StringToAdd 1675 + State.BackgroundColorTag; 1676 1682 StringToAdd := StringToAdd + State.BackgroundColorTag; 1677 1683 end; 1678 1684 end … … 1699 1705 if SequenceStepIndex = 0 then 1700 1706 // and ends it. 1701 StringToAdd := StringToAdd 1702 + State.BackgroundColorTag; 1707 StringToAdd := StringToAdd + State.BackgroundColorTag; 1703 1708 end; 1704 1709 … … 1821 1826 end; 1822 1827 State.TextBlock.Destroy; 1823 1824 end; 1828 end; 1829 1825 1830 1826 1831 function TTopic.SearchForWord( DictIndex: integer; -
branches/2.19_branch/NewView/SearchUnit.pas
r312 r333 124 124 Results: UInt32ArrayPointer ); 125 125 var 126 DictIndex: integer;126 tmpDictIndex: integer; 127 127 pDictWord: pstring; 128 128 begin 129 for DictIndex := 0 to HelpFile.DictionaryCount - 1 do 130 begin 131 pDictWord := HelpFile.DictionaryWordPtrs[ DictIndex ]; 132 Results[ DictIndex ] := CompareWord( SearchWord, 133 pDictWord^ ); 129 for tmpDictIndex := 0 to HelpFile.DictionaryCount - 1 do 130 begin 131 pDictWord := HelpFile.DictionaryWordPtrs[ tmpDictIndex ]; 132 Results[ tmpDictIndex ] := CompareWord( SearchWord, pDictWord^ ); 134 133 end; 135 134 end; … … 163 162 DictWord: string; 164 163 begin 164 if IsLogAspectsEnabled(LogSearch) then 165 begin 166 LogEvent(LogSearch, ' calling SearchDictionaryStarts "' + SearchWord + '"'); 167 end; 168 165 169 FillUInt32Array( Results, HelpFile.DictionaryCount, 0 ); 166 170 … … 169 173 DictWord := HelpFile.DictionaryWords[ DictIndex ]; 170 174 if StrStartsWithIgnoringCase(DictWord, SearchWord) then 171 Results[ DictIndex ] := MatchedWordRelevance( SearchWord, DictWord ); 172 end; 173 end; 175 begin 176 Results[ DictIndex ] := MatchedWordRelevance( SearchWord, DictWord ) 177 end; 178 end; 179 end; 180 174 181 175 182 // Search the help file dictionary for words that … … 182 189 DictWord: string; 183 190 begin 191 if IsLogAspectsEnabled(LogSearch) then 192 begin 193 LogEvent(LogSearch, ' calling SearchDictionaryEnds for "' + SearchWord + '"'); 194 end; 184 195 FillUInt32Array( Results, HelpFile.DictionaryCount, 0 ); 185 196 … … 188 199 DictWord := HelpFile.DictionaryWords[ DictIndex ]; 189 200 if StrEndsWithIgnoringCase(DictWord, SearchWord ) then 201 begin 190 202 Results[ DictIndex ] := MatchedWordRelevance( SearchWord, DictWord ); 203 end; 191 204 end; 192 205 end; … … 207 220 i : integer; 208 221 begin 222 if IsLogAspectsEnabled(LogSearch) then 223 begin 224 LogEvent(LogSearch, ' calling SearchTopicTitles for "' + SearchWord + '"'); 225 end; 226 209 227 tmpTitleWords := TStringList.Create; 210 228 … … 223 241 TitleWord := tmpTitleWords[i]; 224 242 225 WordRelevance := CompareWord( SearchWord, 226 TitleWord ); 243 WordRelevance := CompareWord( SearchWord, TitleWord ); 227 244 if WordRelevance > 0 then 228 245 begin … … 233 250 begin 234 251 // in fact it's the only word 235 TitleWordRelevance := mwOnlyTitleWord 236 * WordRelevance 252 TitleWordRelevance := mwOnlyTitleWord * WordRelevance 237 253 end 238 254 else 239 TitleWordRelevance := mwFirstTitleWord 240 * WordRelevance 255 TitleWordRelevance := mwFirstTitleWord * WordRelevance 241 256 end 242 257 else 243 258 begin 244 TitleWordRelevance := mwTitleWord 245 * WordRelevance; 259 TitleWordRelevance := mwTitleWord * WordRelevance; 246 260 end; 247 261 inc( Results[ TopicIndex ], … … 269 283 i : integer; 270 284 begin 285 if IsLogAspectsEnabled(LogSearch) then 286 begin 287 LogEvent(LogSearch, ' calling SearchIndex for "' + SearchWord + '"'); 288 end; 289 271 290 tmpIndexWords := TStringList.Create; 272 291 … … 284 303 IndexEntryWord := tmpIndexWords[i]; 285 304 286 WordRelevance := CompareWord( SearchWord, 287 IndexEntryWord ); 305 WordRelevance := CompareWord( SearchWord, IndexEntryWord ); 288 306 if WordRelevance > 0 then 289 307 begin … … 294 312 begin 295 313 // in fact it's the only word 296 IndexEntryWordRelevance := mwOnlyIndexWord 297 * WordRelevance 314 IndexEntryWordRelevance := mwOnlyIndexWord * WordRelevance 298 315 end 299 316 else 300 IndexEntryWordRelevance := mwFirstIndexWord 301 * WordRelevance 317 IndexEntryWordRelevance := mwFirstIndexWord * WordRelevance 302 318 end 303 319 else 304 320 begin 305 IndexEntryWordRelevance := mwIndexWord 306 * WordRelevance; 321 IndexEntryWordRelevance := mwIndexWord * WordRelevance; 307 322 end; 308 323 inc( Results[ Topic.Index ], … … 327 342 WordSequences: TList ); 328 343 var 329 TopicCount: longint;330 Topic: TTopic;331 TopicIndex: longint;332 TermIndex: longint;333 Term: TSearchTerm;344 tmpTopicCount: longint; 345 tmpTopic: TTopic; 346 tmpTopicIndex: longint; 347 tmpTermIndex: longint; 348 tmpTerm: TSearchTerm; 334 349 335 350 DictionaryRelevances: UInt32ArrayPointer; … … 353 368 TermWordSequence: TList; 354 369 begin 370 LogEvent(LogSearch, 'SearchHelpFile'); 371 Query.Log; 372 355 373 if HelpFile.SearchTable = nil then 356 374 begin … … 359 377 360 378 // Reset flags per topic 361 TopicCount := HelpFile.TopicCount;379 tmpTopicCount := HelpFile.TopicCount; 362 380 363 381 // Get memory for topic relevance arrays 364 382 365 AllocUInt32Array( TopicsMatchingDictWord, 366 TopicCount ); 367 AllocUInt32Array( TopicsMatchingTermPart, 368 TopicCount ); 369 AllocUInt32Array( TopicsMatchingTerm, 370 TopicCount ); 371 AllocUInt32Array( TopicRelevances, // functions as a flag and a cumulative relevance 372 TopicCount ); 373 AllocUInt32Array( TopicsExcluded, // Exclusions are treated as boolean only 374 TopicCount ); 375 376 ClearUInt32Array( TopicRelevances, 377 TopicCount ); 378 ClearUInt32Array( TopicsExcluded, 379 TopicCount ); 380 381 for TermIndex := 0 to Query.TermCount - 1 do 382 begin 383 Term := Query.Term[ TermIndex ]; 384 385 LogEvent(LogSearch, 'Searching for term "' 386 + Term.Text 383 AllocUInt32Array( TopicsMatchingDictWord, tmpTopicCount ); 384 AllocUInt32Array( TopicsMatchingTermPart, tmpTopicCount ); 385 AllocUInt32Array( TopicsMatchingTerm, tmpTopicCount ); 386 AllocUInt32Array( TopicRelevances, tmpTopicCount ); // functions as a flag and a cumulative relevance 387 388 AllocUInt32Array( TopicsExcluded, tmpTopicCount ); // Exclusions are treated as boolean only 389 390 391 ClearUInt32Array( TopicRelevances, tmpTopicCount ); 392 ClearUInt32Array( TopicsExcluded, tmpTopicCount ); 393 394 for tmpTermIndex := 0 to Query.TermCount - 1 do 395 begin 396 tmpTerm := Query.Term[ tmpTermIndex ]; 397 398 if IsLogAspectsEnabled(LogSearch) then 399 begin 400 LogEvent(LogSearch, 'Searching for term "' 401 + tmpTerm.Text 387 402 + '", ' 388 + IntToStr( Term.Parts.Count )403 + IntToStr( tmpTerm.Parts.Count ) 389 404 + ' parts' ); 405 end; 390 406 391 407 // look thru all parts of the term. eg. CAKE_SAUSAGE … … 394 410 395 411 if WordSequences <> nil then 396 if Term.CombineMethod <> cmExcluded then 412 if tmpTerm.CombineMethod <> cmExcluded then 413 begin 397 414 // this term is an inclusive one, so we want to remember the matches 398 415 WordSequences.Add( TermWordSequence ); 399 400 for TermPartIndex := 0 to Term.Parts.Count - 1 do 401 begin 402 TermPart := Term.Parts[ TermPartIndex ]; 403 404 LogEvent(LogSearch, ' Searching for [' + TermPart + ']' ); 405 406 AllocUInt32Array( DictionaryRelevances, 407 HelpFile.DictionaryCount ); 416 end; 417 418 for TermPartIndex := 0 to tmpTerm.Parts.Count - 1 do 419 begin 420 TermPart := tmpTerm.Parts[ TermPartIndex ]; 421 422 if IsLogAspectsEnabled(LogSearch) then 423 begin 424 LogEvent(LogSearch, ' Searching for TermPart [' + TermPart + ']' ); 425 end; 426 427 AllocUInt32Array( DictionaryRelevances, HelpFile.DictionaryCount ); 408 428 409 429 TermWordSequence.Add( DictionaryRelevances ); … … 412 432 // alpha numeric match 413 433 414 if Term.Parts.Count = 1 then 434 if tmpTerm.Parts.Count = 1 then 435 begin 436 if IsLogAspectsEnabled(LogSearch) then 437 begin 438 LogEvent(LogSearch, ' Term has only one part...' ); 439 LogEvent(LogSearch, ' SearchDictionary [' + TermPart + ']' ); 440 end; 441 415 442 // general match allowing all kinds of partial matches 416 SearchDictionary( HelpFile, 417 TermPart, 418 DictionaryRelevances ) 443 SearchDictionary( HelpFile, TermPart, DictionaryRelevances ) 444 end 419 445 420 446 else if TermPartIndex = 0 then 447 begin 448 if IsLogAspectsEnabled(LogSearch) then 449 begin 450 LogEvent(LogSearch, ' Term has more then one part... we are at first' ); 451 LogEvent(LogSearch, ' SearchDictionaryEnd [' + TermPart + ']' ); 452 end; 453 421 454 // first term part: word must match end of a topic word e.g. must end in "cake" 422 SearchDictionaryEnds( HelpFile, 423 TermPart, 424 DictionaryRelevances ) 425 426 else if TermPartIndex = Term.Parts.Count - 1 then 455 SearchDictionaryEnds( HelpFile, TermPart, DictionaryRelevances ) 456 end 457 458 else if TermPartIndex = tmpTerm.Parts.Count - 1 then 459 begin 460 if IsLogAspectsEnabled(LogSearch) then 461 begin 462 LogEvent(LogSearch, ' Term has more then one part... we are at last' ); 463 LogEvent(LogSearch, ' SearchDictionaryEnd [' + TermPart + ']' ); 464 end; 465 427 466 // last term part: word must match start of a topic word e.g. must start with "sausage" 428 SearchDictionaryStarts( HelpFile, 429 TermPart, 430 DictionaryRelevances ) 467 SearchDictionaryStarts( HelpFile, TermPart, DictionaryRelevances ) 468 end 431 469 432 470 else 471 begin 472 if IsLogAspectsEnabled(LogSearch) then 473 begin 474 LogEvent(LogSearch, ' Term has more then one part... we are inside' ); 475 LogEvent(LogSearch, ' SearchDictionaryEnd [' + TermPart + ']' ); 476 end; 477 433 478 // intermediate term part: word must match exactly e.g. must be "_" 434 SearchDictionaryExact( HelpFile, 435 TermPart, 436 DictionaryRelevances ); 479 SearchDictionaryExact( HelpFile, TermPart, DictionaryRelevances ) 480 end; 437 481 438 482 // For each word in the dictionary that matches … … 440 484 441 485 LogEvent(LogSearch, ' Dictionary search done' ); 442 ClearUInt32Array( TopicsMatchingTermPart, 443 TopicCount ); 486 ClearUInt32Array( TopicsMatchingTermPart, tmpTopicCount ); 444 487 445 488 for DictIndex := 0 to HelpFile.DictionaryCount - 1 do … … 460 503 OrUInt32Array( TopicsMatchingDictWord, 461 504 TopicsMatchingTermPart, 462 TopicCount );505 tmpTopicCount ); 463 506 end 464 507 end; 465 508 466 LogEvent(LogSearch, ' Topic searches done' );509 LogEvent(LogSearch, ' Topic searches done' ); 467 510 468 511 if TermPartIndex = 0 then … … 470 513 CopyUInt32Array( TopicsMatchingTermPart, 471 514 TopicsMatchingTerm, 472 TopicCount )515 tmpTopicCount ) 473 516 else 474 517 // and with previous term part results 475 518 AndUInt32Array( TopicsMatchingTermPart, 476 519 TopicsMatchingTerm, 477 TopicCount );520 tmpTopicCount ); 478 521 479 522 // loop for next term part (IPF word) … … 484 527 485 528 LogEvent(LogSearch, 'Checking for sequences' ); 486 for TopicIndex := 0 toTopicCount - 1 do487 begin 488 if TopicsMatchingTerm[ TopicIndex ] > 0 then489 begin 490 Topic := HelpFile.Topics[TopicIndex ];529 for tmpTopicIndex := 0 to tmpTopicCount - 1 do 530 begin 531 if TopicsMatchingTerm[ tmpTopicIndex ] > 0 then 532 begin 533 tmpTopic := HelpFile.Topics[ tmpTopicIndex ]; 491 534 // Topic text contained a match for the all the parts 492 535 // of the term. … … 495 538 // - count occurrences for relevance. 496 539 497 TopicRelevanceForTerm := 498 Topic.SearchForWordSequences( TermWordSequence, 499 false ); // don't stop at first match 500 501 TopicRelevanceForTerm := 502 TopicRelevanceForTerm div Term.Parts.Count; // divide to bring back into scale 503 504 TopicsMatchingTerm[ TopicIndex ] := TopicRelevanceForTerm; 540 TopicRelevanceForTerm := tmpTopic.SearchForWordSequences( TermWordSequence, false ); // don't stop at first match 541 542 TopicRelevanceForTerm := TopicRelevanceForTerm div tmpTerm.Parts.Count; // divide to bring back into scale 543 544 TopicsMatchingTerm[ tmpTopicIndex ] := TopicRelevanceForTerm; 505 545 506 546 end; … … 518 558 519 559 LogEvent(LogSearch, ' Searching titles' ); 520 SearchTopicTitles( HelpFile, Term.Text, TopicsMatchingTerm );560 SearchTopicTitles( HelpFile, tmpTerm.Text, TopicsMatchingTerm ); 521 561 522 562 LogEvent(LogSearch, ' Searching index' ); 523 SearchIndex( HelpFile, Term.Text, TopicsMatchingTerm );563 SearchIndex( HelpFile, tmpTerm.Text, TopicsMatchingTerm ); 524 564 525 565 LogEvent(LogSearch, ' Combining' ); 526 case Term.CombineMethod of566 case tmpTerm.CombineMethod of 527 567 cmOptional: 568 begin 569 LogEvent(LogSearch, ' Combining optional'); 528 570 AddUInt32Array( TopicsMatchingTerm, 529 571 TopicRelevances, 530 TopicCount ); 572 tmpTopicCount ); 573 end; 531 574 532 575 cmRequired: 533 576 begin 577 LogEvent(LogSearch, ' Combining required'); 534 578 // if zero then add to exclusions 535 579 NotOrUInt32Array( TopicsMatchingTerm, 536 580 TopicsExcluded, 537 TopicCount );581 tmpTopicCount ); 538 582 539 583 AddUInt32Array( TopicsMatchingTerm, 540 584 TopicRelevances, 541 TopicCount );585 tmpTopicCount ); 542 586 end; 543 587 544 588 cmExcluded: 589 begin 590 LogEvent(LogSearch, ' Combining excluded'); 545 591 OrUInt32Array( TopicsMatchingTerm, 546 592 TopicsExcluded, 547 TopicCount ); 593 tmpTopicCount ); 594 end; 548 595 end; 549 596 … … 557 604 // Now convert to list form. 558 605 559 for TopicIndex := 0 toTopicCount - 1 do560 begin 561 if TopicsExcluded[ TopicIndex ] = 0 then562 begin 563 Topic := HelpFile.Topics[TopicIndex ];564 Topic.SearchRelevance := TopicRelevances[TopicIndex ];565 if Topic.SearchRelevance > 0 then566 begin 567 Results.Add( Topic );606 for tmpTopicIndex := 0 to tmpTopicCount - 1 do 607 begin 608 if TopicsExcluded[ tmpTopicIndex ] = 0 then 609 begin 610 tmpTopic := HelpFile.Topics[ tmpTopicIndex ]; 611 tmpTopic.SearchRelevance := TopicRelevances[ tmpTopicIndex ]; 612 if tmpTopic.SearchRelevance > 0 then 613 begin 614 Results.Add( tmpTopic ); 568 615 end; 569 616 end; … … 571 618 572 619 LogEvent(LogSearch, 'Freeing arrays' ); 573 FreeUInt32Array( TopicRelevances, TopicCount );574 FreeUInt32Array( TopicsExcluded, TopicCount );575 FreeUInt32Array( TopicsMatchingTerm, TopicCount );576 FreeUInt32Array( TopicsMatchingTermPart, TopicCount );577 FreeUInt32Array( TopicsMatchingDictWord, TopicCount );620 FreeUInt32Array( TopicRelevances, tmpTopicCount ); 621 FreeUInt32Array( TopicsExcluded, tmpTopicCount ); 622 FreeUInt32Array( TopicsMatchingTerm, tmpTopicCount ); 623 FreeUInt32Array( TopicsMatchingTermPart, tmpTopicCount ); 624 FreeUInt32Array( TopicsMatchingDictWord, tmpTopicCount ); 578 625 579 626 LogEvent(LogSearch, 'Done' );
Note:
See TracChangeset
for help on using the changeset viewer.