FQL Near, Wildcard & Boolean RRS feed

  • Question

  • How can I enable users to enter search criteria (from the Advanced Query window?) that includes near and/or wildcard and/or boolean e.g.

    fred within two words of smith but not jones and contains pott*

    Thanks, Shane

    Tuesday, June 14, 2011 9:13 AM

All replies

  • Hello Shane,

    In order to do this you would have to create a custom webpart/search page. You could either let the users write "fql" directly, or create a dropdown type ui, where you parse the choices over to fql.

    All in all, not that hard, but it will require custom programming. Which search API you choose depends on your approach of a custom search page or modify the existing ones with webparts.

    Mikael Svenson 

    Search Enthusiast - MCTS SharePoint/WCF4/ASP.Net4
    Tuesday, June 14, 2011 9:11 PM
  • Hi Mikael,

    for testing purposes it's ok to let the users write FQL directly. I'm looking for the simplest approach requiring the minimum amount of code/webpart changes. If you could point me to the code/webparts that need to be changed and how they would need to be changed I'd much appreciate it.

    Thanks, Shane

    ps As an aside for anyone from Microsoft reading this I find it quite bizarre that FS4SP is marketed as a search engine with very powerful additional search operators that are not provided as UI options OOTB.

    Wednesday, June 15, 2011 8:24 AM
  • Hi Shane,

    Take a look at on how to enable fql in your overriden Core Result web part. The solution is not optimal but I have optimized it some, but haven't published it.

    Mikael Svenson 

    Search Enthusiast - MCTS SharePoint/WCF4/ASP.Net4
    Wednesday, June 15, 2011 12:33 PM
  • Hi Mikael,

    Thanks for the pointer to Ivan's article. I wonder though if it's a bit more complicated than I need. I really only need to activate the ability to use FQL operators at query time.  I've also read Corey Roth's article

    Both reference [KeywordQuery].EnableFQL = True.

    Is this a switch I can set on in the OOTB simple search query criteria webpart so that users can directly type FQL? I really am looking for the simplest solution. Having a nice GUI for users, while ultimately necessary is less important than enabling them to use the FQL operators.

    Thanks, Shane

    Sunday, June 19, 2011 11:17 PM
  • Hi Shane

    I agree that it would have been nice if FQL was more easily accessible OOTB, but that is just how it is.

    On the other hand, I would like to mention that KQL does actually have some advanced query operators as well, although not as configurable as the FQL counterparts. Have a look at this documentation:

    If you can stick with KQL, it makes your life a whole lot easier...

    Just my 2 cents



    Thomas Svensen | Microsoft Enterprise Search Practice
    Monday, June 20, 2011 7:09 AM
  • Hi Thomas,

    I've read that article, thanks. KQL is clearly less capable than FQL but I would like to investigate this option further. Are there any webpart or other config changes required to enable it's use? Can I just type "fred near smith" (for example) to execute a proximity search of 'fred' within 8 words of 'smith'?

    I also read your article 'Running a query (FQL) from the command line' (excerpt below). Does this mean that I can enable certain power users to be able to construct FQL using powershell, and have results returned to their normal Results screen - as if they had submitted the FQL from the search box, without having to write code (other than what is in the posershell script)?

    Thanks, Shane


    # A prerequisiste
    Add-PSSnapin Microsoft.Sharepoint.PowerShell -ErrorAction SilentlyContinue
    if (!$args.Count -eq 2) {
        Write-Host `nUsage: query.ps1 "<site> <fql>" `n
        Write-Host Example: query.ps1 "" "`"xrank(or(microsoft,contoso), title:microsoft, boost=10000)`""
    # Set up query
    $site = Get-SPSite $args[0]
    $kq = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $site
    $kq.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
    $kq.RowLimit = 5
    $kq.EnableFQL = 1
    $kq.QueryText = $args[1]
    # Execute query
    $resultTableColl = $kq.Execute()
    # Render results
    Write-Host Total hits: $resultTableColl[1].TotalRows 
    $relResultTable = $resultTableColl.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
    $relDataTable = $relResultTable.Table
    $relDataTable | Format-Table -AutoSize -Property Url, Title

    Monday, June 20, 2011 8:21 AM