The Trunk: HelpSystem-Core-mt.134.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: HelpSystem-Core-mt.134.mcz

commits-2
Marcel Taeumel uploaded a new version of HelpSystem-Core to project The Trunk:
http://source.squeak.org/trunk/HelpSystem-Core-mt.134.mcz

==================== Summary ====================

Name: HelpSystem-Core-mt.134
Author: mt
Time: 13 January 2021, 2:32:57.075665 pm
UUID: 3680a1e7-e6e0-4144-a673-66b470bd5235
Ancestors: HelpSystem-Core-mt.133

In a help browser's search results, fixes the issue with title-only matches not showing up. Also show the path to the matched topic.

=============== Diff against HelpSystem-Core-mt.133 ===============

Item was changed:
  ----- Method: SearchTopic>>find:in:results: (in category 'searching') -----
  find: term in: path results: results
 
+ | resultTemplate topic contents index |
- | resultTemplate c topic |
  topic := path last.
+ resultTemplate := Array new: 6.
+ resultTemplate at: 1 put: path.
+
+ contents := topic title asString.
+ (index := contents findString: term startingAt: 1 caseSensitive: false) > 0 ifTrue: [
+ resultTemplate at: 2 put: (index to: index + term size) ].
+
+ contents := topic contents asString withSqueakLineEndings.
+ (index := contents findString: term startingAt: 1 caseSensitive: false) > 0 ifTrue: [
+ | leadingContext trailingContext i |
+ leadingContext := 0.
+ trailingContext := 0.
+ i := index.
+ [i notNil] whileTrue: [
+ (leadingContext = 2 or: [i = 1])
+ ifTrue: [
+ leadingContext := i = 1 ifTrue: [i] ifFalse: [i+1].
+ i := nil]
+ ifFalse: [
+ ((contents at: i) = Character cr) ifTrue: [
+ leadingContext := leadingContext + 1].
+ i := i - 1] ].
+ i := index + term size.
+ [i notNil] whileTrue: [
+ (trailingContext = 2 or: [i >= contents size])
+ ifTrue: [
+ trailingContext := i = contents size ifTrue: [i] ifFalse: [i-1].
+ i := nil]
+ ifFalse: [
+ ((contents at: i) = Character cr) ifTrue: [
+ trailingContext := trailingContext + 1].
+ i := i + 1] ].
- resultTemplate := Array new: 6.
- (topic title asString findString: term startingAt: 1 caseSensitive: false) in: [:index |
- index > 0 ifTrue: [resultTemplate at: 2 put: (index to: index + term size)]].
 
+ resultTemplate
+ at: 3 put: (index - leadingContext + 1 to: index - leadingContext + term size);
+ at: 4 put: (contents copyFrom: leadingContext to: trailingContext);
+ at: 5 put: leadingContext;
+ at: 6 put: (index to: index + term size - 1) ].
- ((c := topic contents asString withSqueakLineEndings) findString: term startingAt: 1 caseSensitive: false) in: [:index |
- index > 0 ifTrue: [
- | leadingContext trailingContext i |
- leadingContext := 0.
- trailingContext := 0.
- i := index.
- [i notNil] whileTrue: [
- (leadingContext = 2 or: [i = 1])
- ifTrue: [
- leadingContext := i = 1 ifTrue: [i] ifFalse: [i+1].
- i := nil]
- ifFalse: [
- ((c at: i) = Character cr) ifTrue: [
- leadingContext := leadingContext + 1].
- i := i - 1] ].
- i := index + term size.
- [i notNil] whileTrue: [
- (trailingContext = 2 or: [i >= c size])
- ifTrue: [
- trailingContext := i = c size ifTrue: [i] ifFalse: [i-1].
- i := nil]
- ifFalse: [
- ((c at: i) = Character cr) ifTrue: [
- trailingContext := trailingContext + 1].
- i := i + 1] ].
-
- resultTemplate
- at: 1 put: path;
- at: 3 put: (index - leadingContext + 1 to: index - leadingContext + term size);
- at: 4 put: (c copyFrom: leadingContext to: trailingContext);
- at: 5 put: leadingContext;
- at: 6 put: (index to: index + term size - 1).
-
- self mutex critical: [ results add: resultTemplate ].
- self triggerUpdateContents.
-
- ] ].
 
+ (resultTemplate second notNil "match in title" or: [resultTemplate third notNil "match in contents"]) ifTrue: [
+ self mutex critical: [ results add: resultTemplate ].
+ self triggerUpdateContents].
+
  topic isSearchable ifTrue: [
  topic subtopics do: [:t | self find: term in: path, {t} results: results]].!

Item was changed:
  ----- Method: SearchTopic>>printResultEntry: (in category 'private') -----
  printResultEntry: entry
 
  | resultEntry topic |
  resultEntry := '' asText.
  topic := entry first last.
 
  entry second notNil
  ifFalse: [resultEntry append: (
  (topic title) asText
  addAttribute: TextEmphasis bold)]
  ifTrue: [resultEntry append: (
  (topic title) asText
  addAttribute: TextEmphasis bold;
  addAttribute: (TextColor color: Color green muchDarker)
  from: entry second first
  to: entry second last)].
 
  resultEntry append: ('  (open topic)' asText
  addAttribute: (PluggableTextAttribute evalBlock: [
  self changed: #searchResultSelected with: entry first.
  self changed: #searchResultContentsSelected with: entry sixth])).
 
  resultEntry append: String cr.
 
+ resultEntry append: (
+ ('> ', ((entry first allButLast collect: [:t | t title]) joinSeparatedBy: ' > ')) asText
+ addAttribute: (TextColor color: (Color gray: 0.7))).
+
+ resultEntry append: String cr.
+
+ entry fourth ifNil: [resultEntry append: '\\' withCRs] ifNotNil: [:contents |
- entry fourth in: [:contents |
  | text |
  text := contents asText.
  text
  addAttribute: (TextColor color: Color green muchDarker)
  from: entry third first
  to: entry third last;
  addAttribute: TextEmphasis bold
  from: entry third first
  to: entry third last.
  resultEntry
  append: text withBlanksTrimmed;
  append: '\\' withCRs.
 
  ].
 
  ^ resultEntry!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: HelpSystem-Core-mt.134.mcz

marcel.taeumel
Here is an example:



Best,
Marcel

Am 13.01.2021 14:33:04 schrieb [hidden email] <[hidden email]>:

Marcel Taeumel uploaded a new version of HelpSystem-Core to project The Trunk:
http://source.squeak.org/trunk/HelpSystem-Core-mt.134.mcz

==================== Summary ====================

Name: HelpSystem-Core-mt.134
Author: mt
Time: 13 January 2021, 2:32:57.075665 pm
UUID: 3680a1e7-e6e0-4144-a673-66b470bd5235
Ancestors: HelpSystem-Core-mt.133

In a help browser's search results, fixes the issue with title-only matches not showing up. Also show the path to the matched topic.

=============== Diff against HelpSystem-Core-mt.133 ===============

Item was changed:
----- Method: SearchTopic>>find:in:results: (in category 'searching') -----
find: term in: path results: results

+ | resultTemplate topic contents index |
- | resultTemplate c topic |
topic := path last.
+ resultTemplate := Array new: 6.
+ resultTemplate at: 1 put: path.
+
+ contents := topic title asString.
+ (index := contents findString: term startingAt: 1 caseSensitive: false) > 0 ifTrue: [
+ resultTemplate at: 2 put: (index to: index + term size) ].
+
+ contents := topic contents asString withSqueakLineEndings.
+ (index := contents findString: term startingAt: 1 caseSensitive: false) > 0 ifTrue: [
+ | leadingContext trailingContext i |
+ leadingContext := 0.
+ trailingContext := 0.
+ i := index.
+ [i notNil] whileTrue: [
+ (leadingContext = 2 or: [i = 1])
+ ifTrue: [
+ leadingContext := i = 1 ifTrue: [i] ifFalse: [i+1].
+ i := nil]
+ ifFalse: [
+ ((contents at: i) = Character cr) ifTrue: [
+ leadingContext := leadingContext + 1].
+ i := i - 1] ].
+ i := index + term size.
+ [i notNil] whileTrue: [
+ (trailingContext = 2 or: [i >= contents size])
+ ifTrue: [
+ trailingContext := i = contents size ifTrue: [i] ifFalse: [i-1].
+ i := nil]
+ ifFalse: [
+ ((contents at: i) = Character cr) ifTrue: [
+ trailingContext := trailingContext + 1].
+ i := i + 1] ].
- resultTemplate := Array new: 6.
- (topic title asString findString: term startingAt: 1 caseSensitive: false) in: [:index |
- index > 0 ifTrue: [resultTemplate at: 2 put: (index to: index + term size)]].

+ resultTemplate
+ at: 3 put: (index - leadingContext + 1 to: index - leadingContext + term size);
+ at: 4 put: (contents copyFrom: leadingContext to: trailingContext);
+ at: 5 put: leadingContext;
+ at: 6 put: (index to: index + term size - 1) ].
- ((c := topic contents asString withSqueakLineEndings) findString: term startingAt: 1 caseSensitive: false) in: [:index |
- index > 0 ifTrue: [
- | leadingContext trailingContext i |
- leadingContext := 0.
- trailingContext := 0.
- i := index.
- [i notNil] whileTrue: [
- (leadingContext = 2 or: [i = 1])
- ifTrue: [
- leadingContext := i = 1 ifTrue: [i] ifFalse: [i+1].
- i := nil]
- ifFalse: [
- ((c at: i) = Character cr) ifTrue: [
- leadingContext := leadingContext + 1].
- i := i - 1] ].
- i := index + term size.
- [i notNil] whileTrue: [
- (trailingContext = 2 or: [i >= c size])
- ifTrue: [
- trailingContext := i = c size ifTrue: [i] ifFalse: [i-1].
- i := nil]
- ifFalse: [
- ((c at: i) = Character cr) ifTrue: [
- trailingContext := trailingContext + 1].
- i := i + 1] ].
-
- resultTemplate
- at: 1 put: path;
- at: 3 put: (index - leadingContext + 1 to: index - leadingContext + term size);
- at: 4 put: (c copyFrom: leadingContext to: trailingContext);
- at: 5 put: leadingContext;
- at: 6 put: (index to: index + term size - 1).
-
- self mutex critical: [ results add: resultTemplate ].
- self triggerUpdateContents.
-
- ] ].

+ (resultTemplate second notNil "match in title" or: [resultTemplate third notNil "match in contents"]) ifTrue: [
+ self mutex critical: [ results add: resultTemplate ].
+ self triggerUpdateContents].
+
topic isSearchable ifTrue: [
topic subtopics do: [:t | self find: term in: path, {t} results: results]].!

Item was changed:
----- Method: SearchTopic>>printResultEntry: (in category 'private') -----
printResultEntry: entry

| resultEntry topic |
resultEntry := '' asText.
topic := entry first last.

entry second notNil
ifFalse: [resultEntry append: (
(topic title) asText
addAttribute: TextEmphasis bold)]
ifTrue: [resultEntry append: (
(topic title) asText
addAttribute: TextEmphasis bold;
addAttribute: (TextColor color: Color green muchDarker)
from: entry second first
to: entry second last)].

resultEntry append: (' (open topic)' asText
addAttribute: (PluggableTextAttribute evalBlock: [
self changed: #searchResultSelected with: entry first.
self changed: #searchResultContentsSelected with: entry sixth])).

resultEntry append: String cr.

+ resultEntry append: (
+ ('> ', ((entry first allButLast collect: [:t | t title]) joinSeparatedBy: ' > ')) asText
+ addAttribute: (TextColor color: (Color gray: 0.7))).
+
+ resultEntry append: String cr.
+
+ entry fourth ifNil: [resultEntry append: '\\' withCRs] ifNotNil: [:contents |
- entry fourth in: [:contents |
| text |
text := contents asText.
text
addAttribute: (TextColor color: Color green muchDarker)
from: entry third first
to: entry third last;
addAttribute: TextEmphasis bold
from: entry third first
to: entry third last.
resultEntry
append: text withBlanksTrimmed;
append: '\\' withCRs.

].

^ resultEntry!