Free tech support / small logo


How can my Google site search just look in a subdirectory?

Hi Dave. Maybe I've missed this somewhere, but how do I get the search to only look at one directory in my domain? I'm looking for it to only search files in my help file, but not to look in the rest of the site. I'm unsuccessful. I looked at that bot thing, and i didn't see an answer [cf how to add a Google search box to your site]

So, for example, it currently looks at www.mywebsite.com, but I want it to look at www.mywebsite.com/directoryA. Is there a way to do that? Entering that path simply returns 0 results.


Dave's Answer:

This is a tricky problem, actually, because as you have noticed Google doesn't allow you to constrain searches to just a specific subdirectory on a site, even when you go directly to their search engine. A good way to see what you can and can't do, by the way, is to both check out the Advanced Search Page and the oh-so-helpful list of search operators.

Noodling on this, however, there are a couple of ways you could try to address the problem... :-)

First off, the operator intitle: is interesting. It lets you specify search results that contain a specific word or phrase in the title of the page. If your FAQ pages have a unique set of words in the title, perhaps "Help Pages", then you could try to use that constraint. For example, search for turkey dinner and look at the top four or five matches. Now search for turkey dinner intitle:recipe to see what I mean.

Even better, though, is if you have a specific subdirectory name, you can try using inurl: to constrain search results to just those matches in that area of your site. It's not foolproof, as a quick test with turkey dinner inurl:recipe reveals (that is, some of the matches are because the word appears in the filename, rather than as a subdirectory) but I imagine you can work around that by having a more complicated directory name. For example, instead of a potentially recurring word like "help" try "helpdir", which is unlikely to appear in the name of a file elsewhere on the site.

So that's a reasonable, workable search solution, one that will certainly let you do searches on Google itself for just that subset of files you desire.

How do you implement it as part of the search box? That's a bit more tricky because we have to splice together two strings in the Javascript (or pre-load "inurl:helpdir" into the text field, a potentially easier solution). That's something I'll address tomorrow, then come back and add a link to that article here. Stay tuned!









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments

Thanks Dave. I look forward to the solution. My directory is called V9.0, so that's at least a name that won't appear in my files. The directory does have multiple sub-directories that I'd like to also have Google search. I'm hoping the solution sets the search to that directory and all subdirectories...

Posted by: Victoria at January 4, 2008 8:41 AM

I hope you continue too. Of course, I could spend a year just reading everything you have already posted. But my votes for “keep blogging�.

Posted by: Tim at February 11, 2008 1:03 PM

Could you send me the code for including the google search in my website?

Posted by: jestin davis at July 2, 2010 4:07 AM

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.