Core Results Webpart - How can i check if the user search query is null?

תשובה Core Results Webpart - How can i check if the user search query is null?

  • 2012年8月7日 下午 01:16
     
     

    I'm trying to create a search page for a document library using the OOB Search Box, Advanced Search Box and Core Results webpart.  I'm using the 'Append Text to Query' option to specify the path to the documents to be searched but since adding this new search criteria the search automatically executes when the page is opened by the user.  I want the search results to remain blank until the user enters some text and clicks search.

    Is there any way I can reference the 'k' URL parameter in the core results web part and check if it's null to try and prevent the search executing. 

    For example, if I use path:lists/MyLibrary contentclass:STS_ListItem_DocumentLibrary the search returns all documents in that library when the page loads. 

    Is there someting I can add to the path to ceheck if the k parameter is null?  I've tried k<>'' but that doesn't work (unsurprisingly).  I'm just trying to figure out if this is possible?

所有回覆

  • 2012年8月8日 下午 10:31
     
     

    Might I suggest an alternate approach?

    Rather than use the 'Append Text to Query' property, I suggest creating a search scope which specifically targets the document library you wish to display as search results. Then add this search scope to the 'Search scope' property of the Search Core Results web part. This will limit the results of a keyword search (i.e. 'k' parameter) to the items in your doc library.

  • 2012年8月9日 上午 07:20
     
     已答覆

    Hi Richard

    I've already implemented what I need to do using search scopes, but have been steered away from using them because of the large number of scopes I would need.  For example, I have a site collection and each subsite below that 'belongs' to a user.  So each time I add a new user I would have a new site and a new search scope within the site collection for that user/site (the sites and scopes are created programmatically).  I wasn't sure if there is an upper limit on the number of scopes and if they would affect the performance so I was looking for an alternate simpler solution.

    The only reason I wanted to check if the user parameter is null was to prevent the query from executing when the page loads (i.e. before the user has entered any search text).  If I don't enter anything in the 'Append Text to Query' property the search page is blank on load, but once it is populated the query returns all results from that library.  For now I've got around this by adding an initial search page which only contains the search box and the user is then redirected to the 'real' search page containing the search box and results webparts.  So they will only see results once they click 'Search'.

    Thanks for your suggestion anyway, I appreciate you taking time to answer.

    Karen 

    • 已標示為解答 KarenPL 2012年8月13日 下午 12:20
    •  
  • 2012年8月9日 下午 02:55
     
     

    Ok. Sounds like a good solution and makes sense. Glad you worked it out, Karen.

    Richard