Benutzer:MovGP0/70-489/Search

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


[Bearbeiten | Quelltext bearbeiten]
  • SQL Query does not work in SharePoint 2013!
  • http://<server>/<site>/_vti_bin/search.asmx is deprecated! do not use!

Build Search Queries using FAST Query Language (FQL)

[Bearbeiten | Quelltext bearbeiten]
  • not intended for end users
  • disabled by default - needs to be enabled at the correct scope:
    • Search Service Application (SSA)
    • Site Collection
    • Site
Aktivieren
Central AdministrationManage Service ApplicationsSearch Service ApplicationManage
Result SourcesCopyQuery Transform
replace KQL-Filter (zB. {?{searchTerms} ContentClass=urn:content-class:SPSPeople})
with FQL-Filter (zB. {?andnot({searchTerms}),filter(contentclass:"urn:content-class:SPSPeople*")})
Building FQL Queries
  • FQL query includes query terms, property specification and operators
Examples for FQL Queries[1]
Query Description
body:string("SharePoint books", mode="and") "SharePoint" AND "books" in the managed property "body"
title:"..."
author:"..."
title:DOCUMENT-*-HR using a wildcard (n characters)
title:DOCUMENT-???-HR wildcard (three characters)
write:range(2013-2-2,2013-2-28) ranges

Build search queries using Keyword Query Language (KQL)

[Bearbeiten | Quelltext bearbeiten]
Basic Syntax
Examples
Governance Planning
Gover* Planning
Governance Plan*
"Governance Planning"
"Gover* Plan*"
Author:"Brandon Atkinson"
Filetype:xlxs
Filename:gouvernance.pdf
Note: length of property is limited to 2048 characters
Combining Queries
Example Expansion
Autor:"Brandon Atkinson" Autor:"Jennie Cook" Autor:"Brandon Atkinson" OR Autor:"Jennie Cook"
Autor:"Brandon Atkinson" Filetype:pdf Autor:"Brandon Atkinson" AND Filetype:pdf
("SharePoint 2013" OR SP2013) AND ("SharePoint 2010")
Common Properties
Examples
Title:SharePoint
Author:Brandon
IsDocument:1
FileExtension:pdf
Filetype:pdf
Created<=2012-01-01
LastModifiedTime:2013-05-07
contentClass:STS_ListItem_Events
conrentClass:STS_ListItem_Tasks
Operators[2]
Examples Description
Title : Gouvernance title contains term
Autor = "Brandon Atkinson" title matches term
Created < 2025-01-01 less then
Created > 2013-01-01 more then
Lastmodified <= 2013-01-01 less then or equal
Lastmodified >= 2013-01-01 more then or equal
Fileextension <> pdf not equal
Created = 2013-01-01 .. 2025-01-01 range
term1 AND term2
term1 NOT term2
term1 OR term2
term1 NEAR term2 term1 in proximity to term2
term1 NEAR(3) term2
term1 NEAR(v=3) term2
like NEAR; separated by 0…3 other terms
term1 ONEAR term2 like NEAR; preserves order of the terms
term1 ONEAR(5) term2
term1 ONEAR(v=5) term2
like ONEAR; separated by 0…5 other terms
WORDS("SharePoint 2013", "SP2013") searching synonyms
"SharePoint 2013" XRANK(cb=100, rb=0.4, pb=0.4, avgb=0.4, stdb=0.4, nb=0.4, n=200) FileExtension=pdf custom ranking

Executing Search Queries using Managed Client-Side Object Model (CSOM)

[Bearbeiten | Quelltext bearbeiten]
using Microsoft.SharePoint.Client
using Microsoft.SharePoint.Client.Runtime
using Microsoft.Client.Search

using(var context = new ClientContext("http://server/site/"))
{
   var query = new KeywordQuery(context) {
      QueryText = "KQL QUERY"
   };
   var executor = new SearchExecutor(context)
   var results = executor.ExecuteQuery(query);
   
   // credentials needed for cross-domain queries; optional if local
   var credentials = new NetworkCredential("user", "password", "domain");
   context.Credentials = credentials;
   
   context.ExecuteQuery();

   // evaluating result
   var builder = new StringBuilder();
   int rowCount = 0;
   if(results.Value.Count > 0)
   {
      foreach(var result in results.Value[0].ResultRows)
      {
         builder.AppendFormat("<div>{0}: <a href='{2}'>{1}</a></div>", result["Title"], ShortenPath(result["Path"].ToString()) result["Path"]);
         rowCount += 1;
      }
   }

   resultsLabel.Text = resultsText.ToString();
   resultsCountLabel.Text = string.Format("{0} results.", rowCount);
}

siehe auch:

Executing Search Queries using JavaScript Client-Side Object Model (JSOM)

[Bearbeiten | Quelltext bearbeiten]
<script type="application/ecmascript" scr="/_layouts/15/sp.runtime.js"></script>
<script type="application/ecmascript" scr="/_layouts/15/sp.js"></script>
<script type="application/ecmascript" scr="/_layouts/15/sp.search.js"></script>
<script type="application/ecmascript" scr="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>

<script type="application/ecmascript">
$("#searchButton").click(function() {
   var context = SP.ClientContext.get_current();

   var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context);
   var searchText = $("#searchTextBox").val();
   keywordQuery.set_queryText(searchText);

   var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(context);
   var results = searchExecutor.executeQuery(keywordQuery);

   context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
});

function onQuerySucceeded() {
   var count = 0;

   $("#searchResults").html("");
   $("#searchResultsCount").html("");

   $.each(results.m_value.ResultTRables[0].ResultRows, function() {
      $("#searchResults").append("<div>" + this.Title + ": <a href='" + this.Path + "'>" + shortenPath(this.Path) + "</a></div>");
      count += 1;
   });
   
   $("#searchResultsCount").html(count + " results.");
}

function onQueryFailed(sender, clientRequestFailedEventArgs) {
   // ...
}
</script>

Executing Search Queries using REST[3]

[Bearbeiten | Quelltext bearbeiten]
HTTP-Verb URL Description
GET http://<server>/<site>/_api/search base URL for REST search
GET http://<server>/<site>/_api/search/query performs search query
POST http://<server>/<site>/_api/search/postquery prevents URI lenght restriction issues
GET http://<server>/<site>/_api/search/suggest retrive query suggestions
Query Examples
Example
GET http://<server>/<site>/_api/search?querytext='query'
GET http://<server>/<site>/_api/search?querytext='query'&selectproperties='Title,Author'
GET http://<server>/<site>/_api/search?querytext='query'&sortlist='LastModifiedTime:ascending'
jQuery
$("#searchButton").click(function() {
   var searchTerms = $("#searchTextBox").val();
   
   $.ajax({
      url: _spPageContextInfo.webAbsoluteUrl + "/_api/search?querytext='" + searchTerms + "'", 
      method: "GET", 
      headers: { "accept": "application/json;odata=verbose" }
   }).done(function (data, statusString, jqXHR) {
      var count = 0;
      var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
   
      $("#searchResults").html("");
      $("#searchResultsCount").html("");
   
      for(var i = 0; i < results.lenght; i += 1) {
         var label = results[i].Cells.results[3].Value;
         var url = results[i].Cells.results[6].Value;
         var title = shortenPath(url);
         $("#searchResults").append("<div>" + label + "<a href='" + url + "'>" + title + "</a></div>");
         count += 1;
      }

      $("#searchResultsCount").html(count + " results.");
   }).fail(function (jqXHR, statusString, errorString) {
      // ...
   });
});
AngularJS
myApp.value('pageContextInfo', _spPageContextInfo);
myApp.service('spQueryService', function($q, $scope, $http, pageContextInfo) {
    var url = pageContextInfo.webAbsoluteUrl + "/_api/search?querytext='" + $scope.searchTerms + "'";

    var config = { 
       headers: { 
          "accept": "application/json;odata=verbose"
       }};
    
    $http.get(url, config).success(function(data) { $scope.result = data; });
}

Executing Search Queries using Web Services

[Bearbeiten | Quelltext bearbeiten]
  • deprecated; do not use!
  • modify any code that is still using http://<sever>/<site>/_vti_bin/search.asmx.

Customize Search Results

[Bearbeiten | Quelltext bearbeiten]

Create Custom Result Sources

[Bearbeiten | Quelltext bearbeiten]
Central Website Collection Website

Central Administration
Search Administration
Queries and Results
Result Sources
New Result Source

Website Settings
Search
Result Sources
New Result Source

Website Settings
Site Collection Administration
Search Result Sources
New Result Source

Abfragetransformation
Schränkt die Suche ein. (z.B. {searchTerms} path:http://<server>/<site>/<documentlibrary>; KQL oder FAST)
Create Search Page

→ navigate to the "Enterprise Search Center", or the local Share Point instance where to host the search page

Create Search Page Create Link to Search Page

Site Contents
Pages
Files
New Document
Page
→ create page
Insert
Web Part
Search
→ compose page
Edit Web Part
→ change query settings

Site Settings
Search
Search Settings
Configure Search Navigation
Add Link

Create Display Templates

[Bearbeiten | Quelltext bearbeiten]
  • Site Settings (Websiteeinstellungen)
  • Web Sesigner Galleries (Web-Designer-Kataloge)
  • Master pages and page layouts (Gestaltungsvorlagen und Seitenlayouts)
  • Display Templates → Search
  • Template auswählen (z. B. Item_Default.html)
  • Files → Download a copy
  • Edit template; SharePoint JavaScript code is between _#= and =#_
  • Upload template to the gallery
  • Edit Search Results WebPart "Display Templates" to use the new template

Create Result Types

[Bearbeiten | Quelltext bearbeiten]
  • Site Settings
  • Search
  • Result Types
  • manage result type settings

Create Custom Refiner Definitions[4]

[Bearbeiten | Quelltext bearbeiten]
  • Create Display Template
    based on Display TemplatesFilters
    (z. B. Control_Refinement.html, Control_TaxonomyRefinement.html)
  • Modify Search page's Refiner Web Part to use the proper refiners

Implement Query Rules[5]

[Bearbeiten | Quelltext bearbeiten]

Used to promote or block search results.

  • Central Administration
  • Search Administration
  • Queries and Results
  • Query Rules
Create new Rule
  • select Source
  • New Query Rule

Customize Content Processing

[Bearbeiten | Quelltext bearbeiten]

Integrate external sources into Search

  • SharePoint Sites
  • Web Sites
  • File Shares
  • Public Exchange Folders
  • Business Connectivity Services

Feed External Content Types

[Bearbeiten | Quelltext bearbeiten]
  • Central Administration
  • Search Administration
  • Crawling
  • Content Sources
  • New Content Source

Note: crawling an external database requires an existing Business Connectivity Service connection

Implement Content Processing Extensions
(Entity Extraction)

[Bearbeiten | Quelltext bearbeiten]

Indexiert Dokumente nach Schlüsselbegriffen.[6]

  • Create a .csv file, which maps expressions (Key) to search refiners (Display form).
    Note: Quotes and tabs are not allowed in the file!
Example CSV
Key Display form
Human Resources Human Resources
HR Human Resources
Finance Finance
Training Training
Career Development Training
Development Development
ASP.NET Development
SharePoint Development
UX User Experience
UI User Experience
BSA Business Analysis
  • Import file
$PathToCsv = "c:\...\dictionary.csv"
$DictionaryName = "Microsoft.UserDictionaries.EntityExtraction.Custom.Word.1" # map to the proper Mannaged Metadata Service Set
$searchApp = Get-SPEnterpriseSearchServiceApplication
Import-SPEnterpriseSearchCustomExtractionDictionary -SearchApplication $searchApp -Filename $PathToCsv -DictionaryName $DictionaryName
  • Choose refiner in Refiner Web Part settings of search page

Configure Out-of-the-Box Content Processing

[Bearbeiten | Quelltext bearbeiten]
Content Processing[7]
Crawl → Content Processing (with Content Enrichment) → Index
Content Enrichment[8]
C# F#
using Microsoft.Office.Server.Search.ContentProcessingEnrichment;
using Microsoft.Office.Server.Search.ContentProcessingEnrichment.PropertyTypes;

class MyContenProcessingEnrichtmentService : IContentProcessingEnrichmentService
{
   public ProcessedItem ProcessItem(Item item)
   {
      ...
   }
}
open Microsoft.Office.Server.Search.ContentProcessingEnrichment
open Microsoft.Office.Server.Search.ContentProcessingEnrichment.PropertyTypes

type MyContenProcessingEnrichtmentService () =
   { new IContentProcessingEnrichmentService with
       member ProcessItem (item:Item) : ProcessedItem = 
          ...
   }
web.config Powershell
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxReceivedMessageSize="8388608"><!-- 8MB -->
                <readerQuotas maxDepth="32"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647" 
                              maxNameTableCharCount="2147483647" />
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>
# configuration settings
$config = New-SPEnterpriseSearchContentEnrichmentConfiguration
$config.Endpoint = "http://<server>/MyContentEnrichmentService.svc"
$config.InputProperties = "Author", "Filename"
$config.OutputProperties = "Author"
$config.SendRawData = $True
$config.MaxRawDataSize = 8192

#register service
Set-SPEnterpriseSearchContentEnrichmentConfiguration SearchApplication 
Get-SPEnterpriseSearchServiceApplication ContentEnrichmentConfiguration $config

#remove service
$searchApp = Get-SPEnterpriseSearchServiceApplication
Remove-SPEnterpriseSearchContentEnrichmentConfiguration SearchApplication $searchApp

Create Content Mappings

[Bearbeiten | Quelltext bearbeiten]

Mapping crawled properties to Managed Metadata Service properties.

Manual Mapping Automatic Mapping[9]
  • Central Administration
  • Search Administration
  • Queries and Results
  • Search Schema
  • Create Managed Metadata Service Site Column (Field)
  • Add Column to List (Document Library)
  1. FAST Query Language (FQL) syntax reference. In: MSDN, Office Dev Center. Microsoft, 16. Juli 2013, abgerufen am 12. Mai 2014 (englisch).
  2. Keyword Query Language (KQL) syntax reference. In: MSDN, Office Dev Center. Microsoft, 28. Februar 2014, abgerufen am 12. Mai 2014 (englisch).
  3. Use OData query operations in SharePoint REST requests. In: MSDN. Microsoft, abgerufen am 15. Mai 2014 (englisch).
  4. Configure refiners and faceted navigation in SharePoint Server 2013. In: Technet. Microsoft, 10. Februar 2014, abgerufen am 17. Juni 2014 (englisch).
  5. Manage query rules in SharePoint Server 2013. In: Technet. Microsoft, 11. April 2014, abgerufen am 17. Juni 2014 (englisch).
  6. Create and deploy custom entity extractors in SharePoint Server 2013. In: Technet. Microsoft, 16. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  7. Custom content processing with the Content Enrichment web service callout. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  8. How to: Use the Content Enrichment web service callout for SharePoint Server. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  9. Automatically created managed properties in SharePoint Server 2013. 28. August 2012, abgerufen am 17. Juni 2014 (englisch).