        |
SearchTitlesOnly
This is my 1-cent tip for sombody's "I wish Search option of 'titles only'":
Create a new template named "searchTitle" as refs - addresses(book) - searchTitle, using SwikiBrowser
and write following code block into the edit pane:
| tokens pageFound |
tokens := (request fieldsKey: 'search' ifAbsent: [ '' ])
asLowercase
unescapePercents
substrings.
pageFound := book pages detect: [:p |
tokens allSatisfy: [:tok |
((p name asLowercase) findString: tok) > 0 ] ]
ifNone: [ book pages at: 1 ].
response
at: 'headerStatus' put: #tempMoved;
at: 'location' put: (request
referenceShelf: shelf
book: book
address: pageFound id asString).
''
To search a specific title within a swiki, type URL like:
http://your-host.com/your-swiki/searchTitle?search=subject+you+are+looking+for
Of course, you can create a HTML form page posting to above URL in somewhere your swiki.
For more complete version, you can try:
| tokens pagesMatching |
"Decrement process priority since it is a search"
Processor activeProcess priority: (ComancheService defaultSearchPriority).
[:stream |
"Put Beginning"
stream nextPutAll: (book formatBookTemplate: 'titleFoundBefore' request: request response: response shelf: shelf).
"Put Results"
tokens := (request fieldsKey: 'search' ifAbsent: [ '' ]) asLowercase unescapePercents substrings.
pagesMatching := book pages
select: [:p |
tokens allSatisfy: [:tok | ((p name asLowercase) findString: tok) > 0 ] ].
pagesMatching size > 0
ifTrue: [
stream
nextPutAll: (book
formatBookTemplate: 'titleFoundMatch'
request: request
response: response
shelf: shelf) ]
ifFalse: [
stream
nextPutAll: (book
formatBookTemplate: 'titleFoundNoMatch'
request: request
response: response
shelf: shelf) ].
stream
cr;
nextPutAll: '';
cr.
pagesMatching do: [ :p |
stream
nextPutAll: (book formatPageTemplate: 'searchListing'
request: request
response: response
shelf: shelf
page: p);
cr ].
stream
nextPutAll: ' ';
cr.
"Put End"
stream
nextPutAll: (book
formatBookTemplate: 'titleFoundAfter'
request: request
response: response
shelf: shelf) ]
In this case, you should create page templates for 'titleFoundBefore', 'titleFoundMatch', 'titleFoundNoMatch', 'searchListing', and 'titleFoundAfter', too.
You can just copy templates from 'foundBefore', 'foundMatch', ... and slightly modify them to use with new title-search feature.
Link to this Page
- Swiki Wishlist last edited on 5 November 2006 at 10:01 pm by penguin.cc.gatech.edu
|