Domanda

sto sviluppando una Web Part per SharePoint 2010 che utilizza FullTextSqlQuery per eseguire People Search utilizzando una clausola CONTAINS sulle PastProjects proprietà gestita.

Io non sto ottenendo alcun risultato indietro. query simili per altre proprietà gestite fanno dati di ritorno (Responsabilità, capacità, interessi), quindi il mio problema sembra essere specifico per le PastProjects gestite proprietà. So che ci sono risultati nell'indice, dal momento che il fuori della ricerca scatola gente fa ritorno il mio profilo corrente quando ho cercare un elemento che appare nella mia proprietà del profilo utente "progetti passato" (che dimostra anche l'indice è fino ad oggi) .

questo articolo che dice che è necessario garantire le proprietà gestite hanno impostato FullTextQueriable su true. Ho scoperto che PastProjects non ha questo, ma dal momento che il fuori dalla scatola People Search fa restituire i risultati attesi mi dicono che dovrei essere in grado di raggiungere il mio obiettivo senza impostare a true FullTextQueriable su PastProjects.

Ho incluso un codice web part di sotto del quale si spera possa essere utilizzato per riprodurre il problema. Vi sarei grato se qualcuno potesse eseguire questo codice sul loro ambiente dev e fatemi sapere quello che il web part ha reso.

Prima di eseguire la parte web, assicuratevi di avere la vostra proprietà del profilo seguente utente popolato con più valori:. I progetti passati, conoscenze, interessi Ask Me About

Assicurarsi inoltre che l'indice sia aggiornato, e confermare l'utente viene restituito dal fuori dalla scatola gente di ricerca quando si esegue una ricerca per una delle parole chiave inserite nel profilo utente (compresi i valori in passato progetti).

Grazie!

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server.Search.Administration;
using System.Collections.Specialized;
using Microsoft.SharePoint.Administration;
using System.Collections;
using System.Data;
using Microsoft.Office.Server.Search.Query;
using System.Text;

namespace SampleCode
{
    [ToolboxItemAttribute(false)]
    public class SearchDemoWebPart1 : WebPart
    {
        protected Literal literalMessage;

        protected override void CreateChildControls()
        {
            this.literalMessage = new Literal();
            this.literalMessage.ID = "literalMessage";
            this.Controls.Add(this.literalMessage);
        }

        protected override void  OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            string searchProxyName = "Search Default SA"; // make sure this matches the name of your SharePoint Search Application

            UserProfileManager manager = new UserProfileManager(SPServiceContext.Current);

            UserProfile profile = manager.GetUserProfile(false);

            SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();

            SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>(searchProxyName);

            NameValueCollection pairs = new NameValueCollection();
            pairs.Add("SPS-Responsibility", "Responsibility");
            pairs.Add("SPS-PastProjects",   "PastProjects");
            pairs.Add("SPS-Skills",         "Skills");
            pairs.Add("SPS-Interests",      "Interests");

            StringBuilder messages = new StringBuilder();

            foreach (string key in pairs.AllKeys)
            {
                string profilePropertyName = key;
                string managedPropertyName = pairs[key];

                this.ProcessUserProfileProperty(searchProxy, profile, profilePropertyName, managedPropertyName, messages);
            }

            this.EnsureChildControls();

            this.literalMessage.Text = messages.ToString();
        }

        public void ProcessUserProfileProperty(SearchServiceApplicationProxy searchProxy, UserProfile profile, string profilePropertyName, string managedPropertyName, StringBuilder messages)
        {
            IEnumerator allValues = profile[profilePropertyName].GetEnumerator();

            while (allValues.MoveNext())
            {
                string keyword = allValues.Current.ToString();

                DataTable resultsDataTable = new DataTable();

                FullTextSqlQuery sqlQuery = new FullTextSqlQuery(searchProxy);

                StringBuilder queryText = new StringBuilder();

                sqlQuery.QueryText = String.Format(@"SELECT Title, AccountName, {0} FROM SCOPE() WHERE CONTAINS({0}, '{1}') AND (""Scope""='People')", managedPropertyName, keyword);
                sqlQuery.ResultsProvider = SearchProvider.Default;
                sqlQuery.ResultTypes = ResultType.RelevantResults;

                ResultTableCollection resultsTableCollection = sqlQuery.Execute();

                using (ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults])
                {
                    resultsDataTable.TableName = keyword;
                    resultsDataTable.Load(searchResultsTable, LoadOption.OverwriteChanges);
                }

                string color = resultsDataTable.Rows.Count == 0 ? "red" : "green";

                messages.AppendFormat(@"<div style=""color: {3}"">Found {0} result(s) for '{1}' in Managed Property '{2}'.</div>", resultsDataTable.Rows.Count, keyword, managedPropertyName, color);
            }
        }
    }
}
È stato utile?

Soluzione

Try using a KeywordQuery and setting the RankingModeID to "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1"

This PowerShell code works for me

Add-PSSnapin Microsoft.SharePoint.PowerShell

$site = get-spsite "http://localhost"
$kq = new-object Microsoft.Office.Server.Search.Query.KeywordQuery($site)

$kq.ResultTypes= [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$kq.RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1"
$kq.QueryText = 'gamma'
$kq.HiddenConstraints = 'scope:"People"'
$res = $kq.Execute()

$table = new-object System.Data.DataTable
$table.Load($res[$kq.ResultTypes],[System.Data.LoadOption]::OverwriteChanges)

echo $table

The full list of ranking models can be found with this powershell.

Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchRankingModel

Altri suggerimenti

One thing to check is that the name of the field matches. (You probably have but just in case)

I see that you refer to "PastProjects" and "Past projects".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top