Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!!

share|improve this question
2  
There is the 'WHERE' missing in you query: select Title from scope() WHERE Tag = Value –  Matthias Jan 26 '12 at 12:45
    
Thank you, but doesn't work anyway! "Property doesn't exist or is used in a manner inconsistent with schema settings." –  Ziba Leah Jan 26 '12 at 13:29
1  
Remember that "value" has to be embraced by '', like this: 'Value' –  tarjeieo Jan 26 '12 at 13:51
1  
Did you create a managed property 'Tag' on the search server? –  Matthias Jan 26 '12 at 13:58
    
Embraced just now, but doesn't work! Tag in the search server works.. If i wrote down Tag:value in a search box, this returns me the right object! –  Ziba Leah Jan 26 '12 at 14:10
show 1 more comment

4 Answers 4

up vote 6 down vote accepted

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!

share|improve this answer
    
you can probably revoke the bounty offer now? –  Alexey Krasheninnikov Feb 1 '12 at 3:49
    
Well i didn't know i can revoke it! –  Ziba Leah Feb 1 '12 at 7:07
add comment

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

share|improve this answer
add comment

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)

share|improve this answer
add comment

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"')
share|improve this answer
    
It doesn't work anyway... In Search Server Tag is a Managed metadata column.. Searched, crawled and reachable by standard search box! –  Ziba Leah Jan 31 '12 at 7:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.