Jump to content


Photo

Crazy Scripting : wikiSearch - Auto-Complete ComboBox


  • Please log in to reply
13 replies to this topic

#1 SKAN

SKAN
  • Administrators
  • 9063 posts

Posted 22 September 2010 - 09:50 AM

Inspired by keyboardfreak's Input box with Wikipedia completion..
.. but using an entirely different approach.



Posted Image         Posted Image

Posted Image         Posted Image



[color=#225588]/*               _ __    _ ____                 __
         _    __(_) /__ (_) __/__ ___ _________/ /              by SKAN - Suresh Kumar A N
        | |/|/ / /  '_// /\ \/ -_) _ `/ __/ __/ _ \             ( arian.suresh@gmail.com )
        |__,__/_/_/\_\/_/___/\__/\_,_/_/  \__/_//_/                   Created: 22-Sep-2010
        A U T O - C O M P L E T E  C O M B O B O X               Last Modifed: 23-Sep-2010
      www.autohotkey.com/forum/viewtopic.php?t=62794
*/[/color]

wiki := "http://[color=red]en.[/color]wikipedia.org"                   [color=black]; alter country code like[/color] [color=red]de. fr. it.[/color]
#SingleInstance, Force
Gui, +AlwaysOnTop +ToolWindow +LastFound
Gui, Margin,0,0
Gui, Font, S9
Gui, Add, ComboBox, w275 R10 Simple vQuery gCheckQuery hwndhCombo1
ControlGet, hEdit1, hWnd,, Edit1, ahk_id %hCombo1%
Gui, Font
Gui, Add, Text, y+1 wp 0x201 vStatus, Enter Query
Gui, Add, Text, y+1 wp h1
Gui, Show,, %wiki%
Gui, Add, Button, Default gOpenWiki, OpenWiki
OnMessage( 0x102, "WM_CHAR" )
Return ;                                                 // End of Auto-Execute Section //

WM_CHAR( wParam ) {
 Global A_LastKey := wParam
}

Deref_Umlauts( w, n=1 ) {
 while n := instr( w, "\u",1,n )
  stringreplace, w, w, % ww := substr( w,n,6 ), % chr( "0x" substr( ww,3 ) ), all
return w
}

CheckQuery:
  IfEqual,A_LastKey,8, Return                                             ; 8 is BackSpace
  GuiControlGet, Query
  If ( QueryLen := StrLen( Query ) ) && InStr( chkList, "|" Query ) {
    GuiControl, ChooseString, Query, %Query%
    GuiControlGet, Query
    SendMessage, 0xB1, QueryLen, StrLen(Query),, ahk_id %hEdit1%           ; EM_SETTEXT
    Return
} IfGreater,QueryLen,2, SetTimer, CheckWiki, -500
Return

CheckWiki:
  GuiControl,, Status, Please wait....
  URLDownloadToFile, %wiki%/w/api.php?action=opensearch&search=%query%,%A_Temp%\wiki.query
  If ( ErrorLevel ) {
    GuiControl,, Status, Internet connection error!
    Return
} FileRead, Result, %A_Temp%\wiki.query
  Result := Deref_Umlauts( RegExReplace( Result, "\[|\]" ) )  
  Loop, Parse, Result, CSV
    WL .= ( A_Index > 1 ) ? "|" A_LoopField :
  Sort, WL, D|
  If ( FirstMatch := SubStr( WL, 2, ( F := InStr( WL,"|",0,2) ) ? F-2 : StrLen( WL ) ) ) {
   GuiControl,, Query, % chkList := WL
   ControlSetText,, % FirstMatch, ahk_id %hEdit1%
   SendMessage, 0xB1, StrLen(query), StrLen(FirstMatch),, ahk_id %hEdit1%  ; EM_SETTEXT
} GuiControl,, Status, % ( FirstMatch ? "" : "No entries found!" ) . ( WL := "" )
Return

OpenWiki:
  ControlGetText, Query,, ahk_id %hEdit1%
  IfNotEqual, Query,, Run, %wiki%/wiki/%query%
GuiEscape:
GuiClose:
 ExitApp


#2 wn98er

wn98er
  • Guests

Posted 22 September 2010 - 10:04 AM

Very nice. I think like this better than the other wikipiedia auto-complete, but both are appeciated.

#3 keyboardfreak

keyboardfreak
  • Members
  • 217 posts

Posted 22 September 2010 - 01:27 PM

Cool, though it feels a bit slower than mine. Maybe because you're trying to parse the results more correctly? I used naive parsing intentionally to make it as quick as possible.

Limitation: BackSpace would not work ( seemingly ). To workaround use Shift+BackSpace


Backspace is a major feature, so for the time being I still prefer my version. ;)

#4 SKAN

SKAN
  • Administrators
  • 9063 posts

Posted 22 September 2010 - 11:42 PM

it feels a bit slower than mine.


That was because of
SetTimer, CheckWiki, -1000
You may reduce it to your need. It is now changed to -500.

Backspace is a major feature


No problem, I have implemented it.

For record, the major features of my script are :

1) 'Autocomplete' feature - no need to select an item from list.
2) Uses an auto-expiry timer rather than a non-stop one.
3) UrlDownloadToFile is called only when the search item is not already in the list.

Thanks for testing my script :)

#5 keyboardfreak

keyboardfreak
  • Members
  • 217 posts

Posted 23 September 2010 - 05:43 AM

Thanks for testing my script :)


I was kind of hoping people would improve the concept that's why I posted the script in the first place. Now that you've improved it I can incorporate some of your improvements into my script. But of course, I'll give you credit in the source. :)

#6 hoppfrosch

hoppfrosch
  • Members
  • 344 posts

Posted 23 September 2010 - 06:02 AM

Cool ...

One issue when using some special characters:

Adapting it to german wikipedia (de.wikipedia.org ....) and trying to find some words with Umlauts does not work - since Umlauts are converted automatically to standard ascii character by your script ...

For example:
Typing in "Sä" is accepted, but it's immediately converted into "Sa" - and this does not lead to the correct search result ("Säge" is something completly different as "Sage")

Where can I change this automatic conversion behaviour? (Or: where can I expand the accepted character class?)

#7 SKAN

SKAN
  • Administrators
  • 9063 posts

Posted 23 September 2010 - 08:20 AM

hoppfrosch, here is the code with neccessary alterations ( changes highlighted in dark-red )

[color=red]Redundant - Removed - Title post updated![/color]

:)

#8 hoppfrosch

hoppfrosch
  • Members
  • 344 posts

Posted 23 September 2010 - 10:55 AM

hoppfrosch, here is the code with neccessary alterations ( changes highlighted in dark-red )


You are my (at least current) hero! :wink:

Thanks for the fast solution. Works like a charm ...

#9 SKAN

SKAN
  • Administrators
  • 9063 posts

Posted 23 September 2010 - 03:08 PM

Thanks for the fast solution


No... Thanks to you :)..
I've updated the original code to be reusable with non-english languages.

#10 Guests

  • Guests

Posted 15 November 2010 - 02:52 PM

Is it possible to make this script suggest strings from an existing list in another file or var? but to be smarter then where it suggest matches even if they are in the middle of a word.

Thanks anyway

#11 SKAN

SKAN
  • Administrators
  • 9063 posts

Posted 16 November 2010 - 11:33 AM

Is it possible to make this script suggest strings from an existing list in another file or var?


Yes..

smarter then where it suggest matches even if they are in the middle of a word.


I guess it is called fuzzy search, and have seen it implemented in nDroid
My implementation ( more or less ) relies on GuiControl, ChooseString, ControlID, String

#12 Guests

  • Guests

Posted 17 November 2010 - 10:18 AM

Skan,

I looked "fuzzy search" functions on the forum, pretty hard to understand how to use it, is it possible you create a new thread demonstrating that?

Thanks anyway

#13 SoLong&Thx4AllTheFish

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts

Posted 17 November 2010 - 11:05 AM

@guest: <!-- m -->http://www.autohotke...pic2534-15.html<!-- m --> see modification k++ (note: I should be able to post a new app based on this in the next few weeks, just ironing out a final kink or two)

#14 Guests

  • Guests

Posted 17 November 2010 - 11:28 AM

@hugov,

That is REALLY.. REALLY.. REALLY nice
I wonder what more you will be adding to it :D
Bookmarked

Thanks