Windows Search inside XYPlorer

Discuss and share scripts and script files...
Post Reply
steponnopets
Posts: 3
Joined: 23 Sep 2014 04:20

Windows Search inside XYPlorer

Post by steponnopets »

Hello all.

I am not a big forum guy but I just got hooked on writing a script to do the following: accept a user's query, feed it to Windows Search, and display the found files in a paper folder in XYPlorer. Since I spent an inordinate length of time getting it to work, I thought I might as well share my code. For those that like the speed and convenience of the indexed search in Windows, it might be useful.

Background:
  • It is possible to write a simple VBScript to query Windows Search using "Windows Search SQL" (See the "ADO and VBScript" section here).
  • Such a script can be run from a command prompt using cscript.exe, and the resulting list of file paths can be directed into a text file.
  • The SQL query syntax is unwieldy for a human to enter, but it contains a variety of potentially useful search features (start here).
  • Some of those potentially useful features--such as automatically matching inflected word forms using FORMSOF--I could not get to work right.
  • What I could get to work are the following: i) partial string matching using LIKE in file name searches; ii) simple fulltext searching using FREETEXT; and iii) fulltext searching with boolean operators and prefix matching using CONTAINS. You'll have to check out the links I've provided above if you want to dig into the details of this SQL search syntax.
So I wrote scripts that do the following:
  1. Take a user-friendly query.
  2. Change it into the form required by the SQL syntax.
  3. Create a WinSearch.vbs file containing the VBScript (this file is created inside XYPlorer's scripts folder).
  4. Call cscript.exe from the command prompt to run the VBScript, and return the list of found files to XYPlorer.
  5. Create a paper folder called "SearchResults" containing these results, and display its contents.
The attached file WinSearch.zip file contains three script files:
  1. WinSearch.xys: contains two scripts: FREETEXT and CONTAINS (see below for what they do).
  2. ProcessNameQuery.xys: loaded by the CONTAINS script to convert the user-supplied query into SQL form for name search.
  3. ProcessContentsQuery.xys: loaded by the CONTAINS script to convert the query in to SQL form for contents search.
Four permanent variables are created to allow these scripts to share information: $perm_name_query and $perm_contents_query are filled with the SQL-like query, while $perm_freetext_query and $perm_contains_query hold the last user-specified queries so they don't need to be input again on the next call to the script.

USAGE:
I keep these three scripts in my <xypath>\Scripts directory and use them by creating a catalog item that does ::load WinSearch. Then when I click on this item I get the option to do a FREETEXT or CONTAINS search.

FREETEXT takes a simple query that is only composed of words that should appear in the document or file name, example queries could be <findthis>, <findthis findthat>, or <findthis "this phrase">. You can also specify a single extension to restrict the search by filetype, as in <findthis *.pdf>. Further instructions and comments are given in the query input box that pops up when you run the script.

CONTAINS takes more complex queries, such as <this that>, <this not that>, <this near that>, <(this and that) not theother *.txt>, and <(this or "this phrase") and oth*>. Boolean operator capitalization and missing ANDs, etc. are taken care of by the script, so that query entry is user-friendly. You may also include one file extension (e.g. *.txt) as in the previous case. The CONTAINS search is first run on file names only, where partial string matching will work (e.g. "cat" will find "scat" and "educate"). The file name matches are placed at the top of the results list. Search is then run again in full text mode, where the contents of the documents are searched. Matches from this search are placed beneath the filename matches.

In both cases the resulting paper folder shows search results sorted by the search engine's ranking. You can view the VBScript code for running the search in the WinSearch.vbs file that's created in the scripts directory.

Finally, my disclaimers: I have very limited previous experience with both of VBScript and XYPlorer scripting, so perhaps I've done something less efficiently than is possible. I have this working well on my Win 8.1 x64 system, but perhaps others will have problems I haven't encountered. Very likely you will be able to feed the script queries that it will choke on, but I've put a timeout of 10 seconds on the cscript.exe call so any bad queries should not cause major problems. I provide this code only as a courtesy to others that might find it useful, so please enjoy, use at your own risk, and modify as you see fit.

Oh and finally finally: my compliments to XYPlorer's developer for authoring such an awesome piece of software that can be user-extended in this way!
Attachments
WinSearch.zip
(5.21 KiB) Downloaded 272 times

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Windows Search inside XYPlorer

Post by admin »

Wow, looks brilliant! :appl:

Only it does not really work here. Or I did not understand it. Where is it supposed to search? The whole system or just the current windows path?

steponnopets
Posts: 3
Joined: 23 Sep 2014 04:20

Re: Windows Search inside XYPlorer

Post by steponnopets »

Hmm, I didn't think to mention that. It should search whatever locations your Windows indexing service has included in the index. So a necessary first step for those not already using Windows Search is to add the desired drives/locations to the index using Indexing Options in control panel.

If that is not the issue for you then I'm not sure what might be going on...

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Windows Search inside XYPlorer

Post by admin »

Yep, that was it. I had turned indexing off.

Back to testing...

PS: One little thing:
Instead of "<xypath>\Scripts" you should rather use "<xyscripts>".

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Windows Search inside XYPlorer

Post by admin »

It works! Fascinating! This is full of possibilities... :beer: :appl:

Unfortunately I don't have much time to play with it at the moment... I hope others will...

I have no experience with the Windows Search. Is the index reliable?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Windows Search inside XYPlorer

Post by highend »

The first thing I do when I setup a new PC -> Turn off windows indexing...

Some issues:
People don't know how to or where to configure it (correctly)
They use Outlook with huge .pst files
Every library is included by default (even new ones you'll create later on)
You have to remove them from the index manually afterwards.

-> Index file(s) get large and bloated with unnecessary information

Imho there are better alternatives, e.g. http://www.copernic.com/en/products/des ... index.html (full version)
Not cheap but better control of what get's indexed and optimal presentation of search results

But ofc this has nothing to do with the script you provided!
I'll add it to the overview thread (http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=12509) if you're ok with that.
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Windows Search inside XYPlorer

Post by admin »

For users who enabled the indexing the script is a fantastic enhancement, and a cool usage of SC runret + Paper Folders, two very recent additions, I love it! :appl: And an astonishing job for a first script! :cup:

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Windows Search inside XYPlorer

Post by highend »

And an astonishing job for a first script!
+1
One of my scripts helped you out? Please donate via Paypal

steponnopets
Posts: 3
Joined: 23 Sep 2014 04:20

Re: Windows Search inside XYPlorer

Post by steponnopets »

Thanks for your feedback highend and admin. The virtual beer you gave me made me go have a real one.

I know Windows Search (and formerly Windows Desktop Search) have been--like most Microsoft things--much maligned, but my feeling about it is that it's quite useful in its present state. Of course it needs to be configured well to work well. In my case I'm only interested in searching pdf documents and text files, and I don't really use libraries. So I set the index only to process the folders that hold my files of interest, and I turned off indexing for all file types other than .pdf and the various plain text types I might use. I agree with highend, the index gets bloated with spurious files if you don't do these steps. But after setting it up this way I get a quite useful and very fast search tool, and it's especially useful now that I can use it without leaving XYPlorer. If there ends up being 1 time out of 20 that I can't find what I'm looking for with Windows Search, I can always use other tools (or XY itself) and just wait for a non-indexed search to go through.

About the crucial issue of whether new or modified files actually get added properly to the index: so far I've only had positive experiences on this question. New or changed files become searchable basically instantly.

autocart
Posts: 1246
Joined: 26 Sep 2013 15:22

Re: Windows Search inside XYPlorer

Post by autocart »

Hi,

This is great, a really nice effort! :appl: Thank you for sharing it, dear animal rights activist :)
The only problem that I have and that limits its usage for me basically to zero is that Windows Search does not index network drives, AFAIK.

Am I right? If yes, do you guys know a solution/workaround?
Thx again, Stephan

Post Reply