locked
SharePoint CrawledProperty Variant Types RRS feed

  • السؤال

  • I'm trying to come up with an accurate way of programatically creating crawled properties in code.

    The problem is the variant type.  I can't find any api in sharepoint that will map an SPFieldType to an Sql Variant type (integer) used in the GetCreateCrawledProperty method.

    In an attempt to hash this out, I compiled a list of all the SPField's on my development farm, then ran that list against all the CrawledProperties in the SearchService spitting out the variant types for each ows_FieldNameHere.

    The result, I get something like this,

    Type                       TypeDisplay                              VariantType
    ----                       -----------                              -----------
    TaxonomyFieldTypeMulti     Managed Metadata                                  31
    RatingCount                Number of Ratings                                 20
    Text                       Single line of text                               31
    Boolean                    Yes/No                                            11
    Guid                       Guid                                              31
    Choice                     Choice                                            31
    Image                      Publishing Image                                  31
    User                       Person or Group                                   31
    Currency                   Currency                                           5
    URL                        Hyperlink or Picture                              31
    Note                       Multiple lines of text                            31
    SummaryLinks               Summary Links                                     31
    Counter                    Counter                                           20
    Integer                    Integer                                           20
    Number                     Number                                             5
    Lookup                     Lookup                                            31
    Computed                   Computed                                          31
    Integer                    Integer                                           31
    DateTime                   Date and Time                                     31
    DateTime                   Date and Time                                     64
    Choice                     Choice                                             5
    Number                     Number                                            31
    TaxonomyFieldType          Managed Metadata                                  31
    Recurrence                 Recurrence                                        20
    HTML                       Publishing HTML                                   31
    File                       File                                              31
    UserMulti                  Person or Group                                   31
    AverageRating              Rating (0-5)                                       4
    Computed                   Computed                                          20
    ModStat                    Moderation Status                                 20
    AllDayEvent                All Day Event                                     11
    CrossProjectLink           Cross Project Link                                31
    
    
    
    

    The problem, is I'm getting back two values for DateTime.  There are two separate fields, one called ImageCreateDate that is a DateTime type and it comes back as variant type 31, and another called "Occured" that is coming back as variant type 64.

    I did the same thing for user profile properties, and I concluded that 31 is for single line strings and 64 is for multi line strings.  So why would date time come back with more than one variant type.

    The variant types I came up with for User Profile Properties are the following,

        public enum CorePropertyVariantValues : int
        {
            Binary = 11,
            Float = 4,
            Guid = 31,
            BigInteger = 20,
            Boolean = 11,
            Date = 64,
            DateNoYear = 64,
            DateTime = 64,
            Email = 31,
            HTML = 31,
            Integer = 20,
            Person = 31,
            String = 31,
            StringMultiValue = 4127,
            StringSingleValue = 31,
            TimeZone = 20,
            URL = 31
        }

    Each of those enum value names is an exact match to the PropertyDataType object, meaning each enum value name matches the name of a field in the PropertyDataType in the Microsoft.Office.userProfiles.UserProfile.

     

    Theres also a ManagedDataType object in the search object model that is used to created ManagedProperty to Crawled Property mappings.

    So the question is, if you know a field will be called "ows_FieldNameHere" when it is discovered on a new crawl, how can I determine what it's variant type will be without having to run the crawl first.

     

    The end goal, is to be able to create crawled properties, managed properties, and map them all in one shot whether the fields actually exist on the site or not, when they do exist, and they have data, they will be crawled.

    As of right now I've got this working about 95% of the time, but occasionally I hit a scenario above where my field isn't being crawled as the variant type I think it should be.

    Take Ratings for example, which creates fields called ows_AverageRating, and ows_RatingCount.  ows_RatingCount worked, I can query it, but ows_AverageRating which is a float, doesn't work.

    Theres got to be something in the object model that I can use to map a Field to it's variant type.  Any insight on this would be welcome.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    09/شوال/1432 07:09 م

الإجابات

  • So it turns out I had some code creating crawled properties of the wrong variant type, 31 on the datetime, 4 on the Number, etc.  Which is why the code that generated the above list was returning different variant types for the same fieldName.

    I fixed that, and more or less created an enumeration out of the above minus the 31 date time and 4 number.

    So now I can do something like

    CrawledProperty cp = SearchUtility.GetCreateCrawledProperty("SharePoint", "ows_MySiteColumnInternalName", (int)FieldToVariantTypes.Text);

    //update cp and update it again if need be.

    ManagedProperty mp = SearchUtility.CreateManagedMappedProperty("MySiteColumnInternalName", "ows_MySiteColumnInternalName", (int)FieldToVariantTypes.Text, ........ //stuff to make it usable in scopes, etc, and whether to delete existing Mappings);

    Works like a charm, not for the feint of heart though.  When I get a cleaned up version I'll blog on it or post an example here.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    10/شوال/1432 02:52 ص

جميع الردود

  • Ok I think I figured this out,

     

    Sharepoint creates crawled properties for Site Columns based on their FeildTypeDefinition.BaseRenderingTypeName .

    So what I did was I enumerated every SPField on my farm,

    For each field in my farm I try to get a crawled property via sql called ows_InternalFieldNameHere.

    If multiple crawled properties come back, then it means one of two things, to understand that consider the following.

    ---- scenario

    You have two web applications sharing the same enterprise search server

    WebApp 1

    --You have a field called Config of type Text

    WebApp 2

    --You have a field called Config of type Note

    You run a full crawl,

    The crawler will discover Both Config of type Text and Config of Type note and create two crawled properties of the same name, one with variant type 31*(guess) and one with variant type 64*(also a guess).

    Problem: You want to be able to run full text queries on the config site column on both web app 1 and web app 2.

    Solution A:  Create one managed properties called Config and map it to Both Config (type 31) and Config (type 64), tell it to use the first value only, so which ever one has a value it will use.  Because they reside on separate web apps, only one should ever have a value.

    Solutuion B: Create two managed properties and map one to Config Type 31, and the other to Config type 64 and micro manage which one to use on which site.

    --end scenario

    Now, that scenario aside, if you get multiple crawled properties back, it's possible you created one yourself and used the wrong Variant Type, then the sharepoint crawler discovered the property and created a new one with the correct variant type.  In this scenario, you have a DEAD crawled property, there is no API to delete crawled properties that I know of unless you want to delete them all.  You can only do it in SQL (not supported and considered a big no! by most administrators).

    Once you fix the dead CrawledProperty, fix your variant type mappings, and then your code should creatre the right crawled property, the new Variant Type mappings I've come up with are as follows,

    DefinitionType                                                      VariantType
    --------------                                                      -----------
    Lookup                                                                       31
    Integer                                                                      20
    Text                                                                         31
    Boolean                                                                      11
    Guid                                                                         31
    Choice                                                                       31
    Note                                                                         31
    Currency                                                                      5
    URL                                                                          31
    Counter                                                                      20
    Number                                                                        5
    Computed                                                                     31
    Integer                                                                      31
    DateTime                                                                     31
    DateTime                                                                     64
    Choice                                                                        5
    Number                                                                       31
    Recurrence                                                                   20
    Number                                                                        4 //this is a bad property, I created the wrong variant type, delete this, here as an example
    Computed                                                                     20
    Lookup                                                                       64
    ModStat                                                                      20
    AllDayEvent                                                                  11
    CrossProjectLink                                                             31
    
    
    


    As far as I know all SPField's use one of the above BaseRenderingTypeName's.  So if you have some custom FieldType, like "AverageRating" simple go into the 14 hive and look at it's FieldTypeDefinition, you'll see it's baserenderingtypename is Number, so in the above table it maps to variant type 5.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    09/شوال/1432 08:04 م
  • Note, this still doesn't explain why DateTime's are coming back with two variant types for me,

    It's possible one of those DateTime's is dead like my Number = 4 property, but I'll leave it as is and update this when I figure it out.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    09/شوال/1432 08:05 م
  • So it turns out I had some code creating crawled properties of the wrong variant type, 31 on the datetime, 4 on the Number, etc.  Which is why the code that generated the above list was returning different variant types for the same fieldName.

    I fixed that, and more or less created an enumeration out of the above minus the 31 date time and 4 number.

    So now I can do something like

    CrawledProperty cp = SearchUtility.GetCreateCrawledProperty("SharePoint", "ows_MySiteColumnInternalName", (int)FieldToVariantTypes.Text);

    //update cp and update it again if need be.

    ManagedProperty mp = SearchUtility.CreateManagedMappedProperty("MySiteColumnInternalName", "ows_MySiteColumnInternalName", (int)FieldToVariantTypes.Text, ........ //stuff to make it usable in scopes, etc, and whether to delete existing Mappings);

    Works like a charm, not for the feint of heart though.  When I get a cleaned up version I'll blog on it or post an example here.


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    10/شوال/1432 02:52 ص