locked
Sharepoint search api on custom fields written in c# RRS feed

  • Question

  • Hi I have created a content type called Con1. The Con1 consists of fields Title,Field1
    I have bound the content type to a list called TestList and put the following data

    Title        Field1
    Name1    Field1Name1
    Name2    Field1Name2

    I have started the crawl on all sites and did a quick search on sharepoint for value Field1Name2 and it has found this.

    Now I want to create a .net c# application to a simple search using the Field1 . I am using this code

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.Search.Query;

    SPSite site = SPContext.Current.Site;
    StringBuilder queryText = new StringBuilder();
    queryText.Append("SELECT Title, Path, Size, Description, Rank ");
    queryText.Append("FROM SCOPE() ");
    queryText.Append("WHERE CONTAINS(\"Title\",'Name2')");
           
    FullTextSqlQuery query = new FullTextSqlQuery(site);
    query.QueryText = queryText.ToString();
    query.ResultTypes = ResultType.RelevantResults;
    query.RowLimit = 5000;

    ResultTableCollection results = query.Execute();
    ResultTable rt = results[ResultType.RelevantResults];
           
    DataTable dt = new DataTable();
    dt.Load(rt, LoadOption.OverwriteChanges);

    grdView.DataSource = dt;
    grdView.DataBind();

    and it works for Title criteria but I cant seem to write the query for Field1 as it says property does not exist.
    How can you do this ?
    • Moved by Mike Walsh FIN Friday, April 16, 2010 3:35 AM search q (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Thursday, April 15, 2010 9:20 PM

Answers

  • You need to go into your Shared Services Adminstration application --> Search Administration --> Metadata Properties and set up a managed property for the Field1 field. You can find this under "SharePoint" crawled properties category named "ows_Field1". After you create the new managed property and map it to the "ows_Field1" crawled property do a full crawl. Then add the managed property to your FullTextSqlQuery.QueryText.
    certdev.com
    • Marked as answer by Chengyi Wu Tuesday, April 20, 2010 2:31 AM
    Thursday, April 15, 2010 9:51 PM

All replies

  • I think you'll need to add a managed property for your custom field if you're going to use the Contains dictate on it.

    In the search administration pages, click on Metadata Properties, New Managed Property, Give the property a name, choose "Include values from a single crawled property.....", then click Add Mapping.

    Select the category SharePoint, then search for your property. If you've done a crawl, then you should be able to find it.

    Once the property is mapped, run a full crawl again, then try your code once more.

    Paul.


    Overweight SharePoint addict!
    Thursday, April 15, 2010 9:50 PM
  • You need to go into your Shared Services Adminstration application --> Search Administration --> Metadata Properties and set up a managed property for the Field1 field. You can find this under "SharePoint" crawled properties category named "ows_Field1". After you create the new managed property and map it to the "ows_Field1" crawled property do a full crawl. Then add the managed property to your FullTextSqlQuery.QueryText.
    certdev.com
    • Marked as answer by Chengyi Wu Tuesday, April 20, 2010 2:31 AM
    Thursday, April 15, 2010 9:51 PM