Seach files based on filename format using UnifiedSearchQuery

Vote:
 
string virtualDir = "/Global/UserPetImages";
UnifiedDirectory directory = UnifiedDirectory.CreateDirectory(virtualDir);
string fileNamePattern = "User555_PetImage*";
UnifiedSearchQuery query = new UnifiedSearchQuery();
query.FileNamePattern = fileNamePattern;
UnifiedSearchHitCollection searchResult = directory.Search(query);
 
I get an error on the last line. I get

Object reference not set to an instance of an object.

[NullReferenceException: Object reference not set to an instance of an object.]
   Lucene.Net.QueryParsers.QueryParser.Escape(String s) +78
   EPiServer.Web.Hosting.Versioning.Store.LuceneQuery.Search(UnifiedSearchQuery userQuery) +144
   EPiServer.Web.Hosting.VersioningDirectory.Search(UnifiedSearchQuery query) +118
   Masterpet.Web.Templates.Masterpet.Controls.PetDetails.UploadPetImageFile(Int32 userId, String& filename) in D:\SVN\Karuba\Masterpet\masterpet.com\trunk\Site\Templates\Masterpet\Controls\PetDetails.ascx.cs:224
   Masterpet.Web.Templates.Masterpet.Controls.PetDetails.Update(Int32 userId) in D:\SVN\Karuba\Masterpet\masterpet.com\trunk\Site\Templates\Masterpet\Controls\PetDetails.ascx.cs:142
   Masterpet.Web.Templates.Masterpet.Pages.ProfilePetPage.UpdatePets_OnClick(Object sender, EventArgs e) in D:\SVN\Karuba\Masterpet\masterpet.com\trunk\Site\Templates\Masterpet\Pages\ProfilePetPage.aspx.cs:76
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
 
directory is not null and query is not null. My guess is it has something to do with initializing the UnifiedSearchQuery?


#52096
Jul 06, 2011 4:02
Vote:
 

Got it! I needed to add this:

query.FreeTextQuery = "";

#52097
Jul 06, 2011 4:37
Vote:
 

For some reason, I'm not getting the correct results anymore. It was working before.

Am I doing the search correctly?

#52227
Jul 12, 2011 23:56
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.