Question

I've got a site collection on a Sharepoint Foundation 2010. I've Search Express also installed.. When i wrote down in the search box something like "Parameter:Value" it returns me the right elements (so i've configured well column and crawler)..

Now i want (by code) write a query that gets every item with that column and respect some value.. So, make the same thing, but coding it!

        string searchQuery = "select Title from scope() WHERE Tag = 'Value' "; 

        // Execute the query.
        FullTextSqlQuery query = new FullTextSqlQuery(SPContext.Current.Site);
        query.ResultTypes = ResultType.RelevantResults;
        query.QueryText = searchQuery;
        ResultTableCollection searchResults = query.Execute();

It cannot execute the query... Tag is the field i've defined and works writing down the Tag:Value from search box!

Can anyone suggest me what's wrong with my query?

Thank you very much!!

Was it helpful?

Solution

The problem i've encountered was linked to the reference i was using.. I used

 Microsoft.SharePoint.Search.Query

instead of

 Microsoft.Office.Server.Search.Query

In the version i was using it was impossibile to query sharepoint giving him parameters and so on... But the firm of every class and method was the same..

Now it works!

Thanks to all!

OTHER TIPS

Try using the KeywordQuery class instead, that should mimic the search box behaviour as far as I'm aware.

Download Fast Search Tool from Codeplex, use UI to construct the query, and test. Repeat until you get it working. (I have nothing to do with the tool, I have just used it for similar purposes)

I'm guessing that Tag is a Managed metadata column? If so, doing an equals compare using Column = 'Value' won't work, as the actual text in the property could potentially hold more values, lookup value based managed metadata properties store the values differently in the index.

So you would have to use a CONTAINS or a LIKE. Any search using a lookup column in the WHERE clause (and taxonomy fields are lookup columns) needs to be a done like that.

The query would be something like:

SELECT Title FROM scope() WHERE CONTAINS (Tag, '"VALUE"')
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top