I'm trying to search a Sharepoint 2007 site using the FullTextSqlQuery class, but I keep getting the following error "The search request was unable to connect to the Search Service"
My code looks like this
create a new FullTextSqlQuery class - use property intializers to set query
scope = "BuySale";
FullTextSqlQuery myQuery = new FullTextSqlQuery(SPContext.Current.Site)
{
QueryText = "SELECT Path FROM SCOPE() WHERE \"SCOPE\" = '" + scope + "'",
ResultTypes = ResultType.RelevantResults
};
ResultTableCollection queryResults = myQuery.Execute();
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
Error from ULS log is this
Danish version
Log Query: Søgeanmodningen kunne ikke oprette forbindelse til
søgetjenesten. Yderligere oplysninger: Object or data matching the
name, range, or selection criteria was not found within the scope of
this operation.
English version
Log Query: The search request was unable to connect to the Search Service. Yderligere oplysninger: Object or data matching the
name, range, or selection criteria was not found within the scope of
this operation.
I've checked that all services is running and the scope exits.
I'm able to use the scope using sharepoint normal search and using the "SearchCoder" app that can help create search query.
Any ideas would be greatly appreciated.
Found the soltuion after spending a few more hours on google.
I was using the wrong dll to resolve the FullTextSqlQuery class
I was using this
Microsoft.SharePoint.Search.Query // WSS
but should have been using this
using Microsoft.Office.Server.Search.Query // MOSS
Thanks to Chris O'Connor
http://sharepointroot.com/2009/11/14/fulltextsqlquery-throwing-exception-this-site-is-not-assigned-to-an-indexer
Related
I have a requirement in which I want to get the search results programmatically. For this I am using KeyWordQuery to search programmatically. But here I am getting less results that default SharePoint search, it is omitting some records from the results.
Here is the code I am using
SPSite site = SPContext.Current.Site;
KeywordQuery objkeywordquery = new KeywordQuery(site);
objkeywordquery.QueryText = strQuery;
objkeywordquery.SelectProperties.Add("Title");
objkeywordquery.SelectProperties.Add("Path");
objkeywordquery.ResultsProvider = SearchProvider.Default;
objkeywordquery.ResultTypes = ResultType.RelevantResults;
objkeywordquery.RowLimit = 5000
ResultTableCollection queryResults = objkeywordquery.Execute();
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
If I get 100 results in sharepoint search reults page, with the same querytext I get 96-97 results.
Can someone help me with this
Have you tried "objkeywordquery.EnableStemming = true;" ?
Look like the default SharePoint search has it enabled; we had a similar issue and this resolved it.
Hope it helps.
Vincent
I'm trying to implement custom search portlet through AssetEntries. Currently AssetEntryQuery doesn't allow to search with keywords. I'm trying to search through FacetedSearcher. Search by keywords seems to be ok. But when I'm trying to search by AssetTagNames
searchContext.setAssetTagNames(assetTagNames)
it doesn't work at all.
Here's my piece of code
SearchContext searchContext = new SearchContext();
Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
assetEntriesFacet.setStatic(true);
searchContext.addFacet(assetEntriesFacet);
/*MultiValueFacet multiValueFacet=new MultiValueFacet(searchContext);
multiValueFacet.setFieldName("assetTagNames");
multiValueFacet.setStatic(false);
searchContext.addFacet(multiValueFacet);*/
searchContext.setCompanyId(themeDisplay.getCompanyId());
String []assetTagNames=new String[1];
assetTagNames[0]= assetTagName;
searchContext.setAssetTagNames(assetTagNames);
searchContext.setKeywords(keywords);
String[] entryClassName = {JournalArticle.class.getName()};
searchContext.setEntryClassNames(entryClassName);
Indexer indexer = FacetedSearcher.getInstance();
// searchContext.setAndSearch(true);
Hits hits = indexer.search(searchContext);
System.out.println("Hits: " + hits.getLength());
Resulted query for request
searchKeyword: key1key1
assetTagName: sometag
+(+(companyId:1) +((+(entryClassName:com.liferay.portlet.journal.model.JournalArticle) +(status:0)))) +(assetCategoryTitles:*key1key1* assetCategoryTitles_en_US:*key1key1* assetTagNames:*key1key1* comments:key1key1 content:key1key1 description:key1key1 properties:key1key1 title:key1key1 url:key1key1 userName:*key1key1* classPK:key1key1 content_en_US:key1key1 description_en_US:key1key1 entryClassPK:key1key1 title_en_US:key1key1 type:key1key1)
As you see AssetTag isn't applied to the query.
I've already tried to set it through
searchContext.setAttribute("assetTagNames",assetTagName);
and commented MultiValueFacet code but wih no result.
For further i need to search by dateRange and Categories. Has anybody any idea?
Fortunately solved this.
If you'd like to search through tags you've to use a separate facet for this, e.g.
MultiValueFacet assetTagsFacet = new MultiValueFacet(searchContext);
assetTagsFacet.setFieldName(Field.ASSET_TAG_NAMES);
searchContext.addFacet(assetTagsFacet);
Also use searchContext.setAttribute("assetTagNames", assetTagName); instead of searchContext.setAssetTagNames(assetTagName);
For searching through Categories the same thing:
MultiValueFacet assetCategoriesFacet = new MultiValueFacet(searchContext);
assetCategoriesFacet.setFieldName("assetCategoryTitles");
searchContext.addFacet(assetCategoriesFacet);
searchContext.setAttribute("assetCategoryTitles", assetCategoryName);
Also i wanted to search by custom type of JournalArticle, Ive created facet for this, but got "type" twice in query. As a solution i used MultiValueFacet instead of AssetEntriesFacet during setting entryClassName
MultiValueFacet assetEntriesFacet = new MultiValueFacet(searchContext);
assetEntriesFacet.setFieldName("entryClassName");
searchContext.setAttribute("entryClassName",JournalArticle.class.getName());
searchContext.addFacet(assetEntriesFacet);
I am very new to CRM development, i was trying to follow this article, i am a bit confused about below code, please check:
var xp = Xrm.Page;
function onLoad(context) {
var accountId = xp.data.entity.getId();
var mostRecentQuery = "/XRMServices/2011/organizationData.svc/ContactSet?
$select=FullName,JobTitle,EMailAddress1,Telephone1&$top=1&$orderby=CreatedOn
desc&$filter=ParentCustomerId/Id eq guid'" + accountId + "'";
getContact(mostRecentQuery, "MostRecent");
....
}
The above javascript function executes when AccountForm is opened. The first line gets the accountId. the next line is oData query.
Now check the ContactSet in this query, i am confused here, how we can retrieve the ContactEntity based on the GUID of AccountEntity?
I found the answer!
Actually there a Lookup 'Parent Customer' on ContactEntity, it represents the unique identifier of the account or contact associated with this contact, so we can select an Account/Contact as the Parent Customer of a contact.
So this given OData query actually retrieves the top 1 contact where this account is referenced.
I hope its clear.
Initially I believed these 3 to be doing more or less the same thing with just the notation being different. Until recently, when i noticed that their does exists a big difference between the results of the KeyWordQuery/FullTextQuerySearch and Web service Query.
I used both KeywordQuery and FullText method to search of the the value of a customColumn XYZ with value (ASDSADA-21312ASD-ASDASD):-
When I run this query as:- FullTextSqlQuery:-
FullTextSqlQuery myQuery = new FullTextSqlQuery(site);
{
// Construct query text
String queryText = "Select title, path, author, isdocument from scope() where freetext('ASDSADA-21312ASD-ASDASD') ";
myQuery.QueryText = queryText;
myQuery.ResultTypes = ResultType.RelevantResults;
};
// execute the query and load the results into a datatable
ResultTableCollection queryResults = myQuery.Execute();
ResultTable resultTable = queryResults[ResultType.RelevantResults];
// Load table with results
DataTable queryDataTable = new DataTable();
queryDataTable.Load(resultTable, LoadOption.OverwriteChanges);
I get the following result representing the document.
* Title: TestPDF
* path: http://SharepointServer/Shared Documents/Forms/DispForm.aspx?ID=94
* author: null
* isDocument: false
Do note the Path and isDocument fields of the above result.
Web Service Method
Then I tried a Web Service Query method. I used Sharepoint Search Service Tool available at http://sharepointsearchserv.codeplex.com/ and ran the same query i.e. Select title, path, author, isdocument from scope() where freetext('ASDSADA-21312ASD-ASDASD'). This time I got the following results:-
* Title: TestPDF
* path: http://SharepointServer/Shared Documents/TestPDF.pdf
* author: null
* isDocument: true
Again note the path. While the search results from 2nd method are useful as they provide me the file path exactly, I can't seem to understand why is the method 1 not giving me the same results?
Why is there a discrepancy between the two results?
The first item is a List item, not a document per se. A document library is essentially just another list that is specially made to hold documents in it. The list item likely has some extra metadata not held within the document and so on. The second result is the actual document, so the "isDocument" flag will be up for it.
At least that's my theory.
Scenario: Document library in SharePoint with column x of "Person or Group" type. From within a VBA macro (or VSTO add-in) we're trying to access the MetaProperty on the document to set/get the user name. Any attempt to access the value via the ContentTypeProperties collection throws a
Type MisMatch error (13).
The Type property of the MetaProperty object says it's msoMetaPropertyTypeUser. I cannot find any examples of how to work with MetaProperties of this type. Anyone have any experience with this?
Thanks!
You should be able to just do something like this:
using (SPSite site = new SPSite("http://yoursite/subsite"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["DocLibraryName"];
SPListItemCollection items = list.GetItems(list.Views["All Documents"]);
foreach (SPListItem item in items)
{
item["Modified By"] = "Updated Value";
}
}
}
Any metadata for a document should be available by indexing the column name of the SPListItem.
I did it.
The trick here is actually to know that if you put a string corresponding to the user index in MOSS users in the custom property of the Word document, MOSS will recognize it and find the corresponding user to map the field.
so you just need to call http:///_vti_bin/usergroup.asmx
use the function GetUserInfo and retrieve the user index (ID) from it.
MOSSusergroup.UserGroup userGroupService = new MOSSusergroup.UserGroup();
userGroupService.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Xml.XmlNode node = userGroupService.GetUserInfo(userLogin);
string index = node.FirstChild.Attributes["ID"].Value;