[SOLVED] Multiple Needles in Haystack....

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

[SOLVED] Multiple Needles in Haystack....

10 Sep 2014, 13:17

How do I search for multiple needles in a haystack?

This is my current code...

Code: Select all

	loop,read,%F1% ; Read from file to populate listview
	{	LR=%A_loopReadLine%
		StringReplace, SRC,SRC,%A_Space%, `,,A	; Make spaces from editbox SRC, wildcards, making them commas to allow search using If Haystack Contains needles
		if SRC<>
		{	if LR contains %SRC%
			{	stringsplit,C,A_LoopReadLine,%delim%
				LV_Add("",C1,C2,C3,C4)
			}
		}
		else
			continue
	}
As it sits, the string up to the first space works great, but then the first char after the space expands the listview content again. I would like the additional strings to refine the existing listview content.
Last edited by jsmain on 25 Sep 2014, 08:12, edited 2 times in total.
jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

Re: Multiple Needles in Haystack....

10 Sep 2014, 14:51

Here is a working example of the script I need to fix....

Code: Select all

#SingleInstance, Force
	e1=	
	(Ltrim Join`r`n
	What have I played this gig?
	What have I played in the last month?
	Uncategorized
	Unavailable (inaccessible) Items
	In "pop" category and rating above 4
	In "Wedding" and 'Love' in title\artist
	Both 'Beatles' and 'love' in title\artist
	Shorter than 70 seconds (ad/promo?)
	Longer than or equal to 6 minutes
	BPM between 120 and 140 (inclusive)
	Karaoke items
	Karaoke items shorter than 4 minutes
	Video items
	Video *and* ABM items
	Video *or* ABM items
	ABM with an intro *and* outro
	ABM intro *or* outro, but not both
	Clear OMQL Field
	Clear Search Field
	1- Clear OMQL & Search fields
	)
	Gui,Add, Edit,  x10 y10 w580 vSrch1 gFind hwndHFind,
	Gui,Add, listview, w580 xp y35 r9 Grid vLV1 +altsubmit -multi -Hdr ,Description
	LV_ModifyCol(1,558)
	gosub, LoadPresets
	Gui,Show, autosize
Return
;	
LoadPresets:
{	Gui,listview, LV1
	LV_Delete()
	Loop, Parse, e1, `n
		LV_Add("", A_LoopField)
	LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
	LV_Modify(1,"+Select")
	LV_Modify(1, "Vis")      ;scrolls down
Return
}
;
Find:
{	Gui,Submit, Nohide
	Gui,listview, LV1
	ex := e1
	src:= % srch1
	if (SRC=)	 ; If search is now empty, reload list with complete list
		Return
	LV_Delete()	; if Search is not empty, delete listview content, and refill will search results.
	loop,parse,ex,`n
	{	LR=%A_loopfield%
		StringReplace, SRC,SRC,%A_Space%, `,,A	; Make spaces wildcards
		if SRC<>
		{	if LR Contains %SRC%
			LV_Add("",LR)
		}
		else
			continue
	}
	LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
	LV_Modify(1,"+Select")
	LV_Modify(1, "Vis")
	if (SRC="")
	gosub, LoadPresets	
Return
}
Run it, and type in "abm or" and see what happens when you add the "or". I want to take the 4 results from "ABM", and narrow to the 2 results that contain both "ABM" & "Or", instead of expanding it to 9 results.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Multiple Needles in Haystack....

10 Sep 2014, 15:09

look a few posts down to the "boolean search" thread

jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

Re: Multiple Needles in Haystack....

10 Sep 2014, 16:59

http://ahkscript.org/boards/viewtopic.php?f=5&t=4480
Thanks! I'll have a look, and try to figure it out.
jsmain
Posts: 62
Joined: 07 Feb 2014, 08:21

Re: SOLVED: Multiple Needles in Haystack....

11 Sep 2014, 09:33

Regex was the solution.
The above test script has been modified to the following.

Code: Select all

#SingleInstance, Force
; Add some test data
	e1=	
	(Ltrim Join`r`n
	What have I played this gig?
	What have I played in the last month?
	Uncategorized
	Unavailable (inaccessible) Items
	In "pop" category and rating above 4
	In "Wedding" and 'Love' in title\artist
	Both 'Beatles' and 'love' in title\artist
	Shorter than 70 seconds (ad/promo?)
	Longer than or equal to 6 minutes
	BPM between 120 and 140 (inclusive)
	Karaoke items
	Karaoke items shorter than 4 minutes
	Video items
	Video *and* ABM items
	Video *or* ABM items
	ABM with an intro *and* outro
	ABM intro *or* outro, but not both
	Clear OMQL Field
	Clear Search Field
	1- Clear OMQL & Search fields
	)
	Gui,Add, Edit,  x10 y10 w580 vSrch1 gFind hwndHFind,
	Gui,Add, listview, w580 xp y35 r9 Grid vLV1 +altsubmit -multi -Hdr ,Description
	LV_ModifyCol(1,558)
	gosub, LoadPresets
	Gui,Show, autosize
Return
;	
LoadPresets:  ; Fill Listview
{	Gui,listview, LV1
	LV_Delete()
	Loop, Parse, e1, `n
		LV_Add("", A_LoopField)
	LV_ModifyCol(1, "Sort CaseLocale")   ; or "Sort CaseLocale"
	LV_Modify(1,"+Select")
	LV_Modify(1, "Vis")      ;scrolls down
Return
}
;
Find:  ; Ran each time a char is added to search field
{	Gui,Submit, Nohide
	Gui,listview, LV1
	Array :={}
	StringLower, SRC, e1, 
	search:= % srch1
	loop, parse, search, %A_Space%
		Array.Insert(A_LoopField)
	for index, element in Array
		Array%index% := element
	LV_Delete()	; if Search is not empty, delete listview content, and refill will search results.
	loop,parse,src,`n
	{
		if (A_LoopField ~= Array1) && (A_LoopField ~= Array2) && (A_LoopField ~= Array3) && (A_LoopField ~= Array4)
			LV_Add("",A_LoopField) 
	}
	LV_ModifyCol(1, "Sort CaseLocale")   
	LV_Modify(1,"+Select")
	LV_Modify(1, "Vis")
	if (Search="")
	gosub, LoadPresets	
Return
}
User avatar
Kellyzkorner_NJ
Posts: 84
Joined: 20 Oct 2017, 18:33

Re: [SOLVED] Multiple Needles in Haystack....

15 Nov 2018, 21:11

I have a question related to this script. I use it to search a list of doctor's names but when the window is created everything is in lowercase. I can't figure out where or what to change for it to respect the case from the file it is read from, unless that will affect or stop the script from working as it should and does now in terms of searching correctly. Thanks in advance.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 247 guests