1

I have the following configuration for storing a field.

<fieldType fieldName="Profile Id" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.Guid" nullValue="NULL" emptyString="EMPTY" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />

When I check the index with LukeAll I see the id as:

enter image description here

I don't know why the curly braces are gone and why all the characters are in lowercase. I want to store it as normal guid like in sitecore with curly braces and all chars in uppercase.

I also tried with type="System.string" but its still the same.

Kamran
  • 4,010
  • 14
  • 60
  • 112
  • 1
    It's common practice to store guids in Lucene without the brackets - Sitecore does it by default. Why would you explicitly want them in your index? – Gatogordo Jun 21 '16 at 11:20
  • Later in the code to compare two strings one from `Sitecore Item Id` and one from `Index field`. – Kamran Jun 21 '16 at 11:23
  • And why is that stopping you? You can easily compare the two strings by using the String.Contains Method – Adrian Iorgu Jun 21 '16 at 11:56
  • 1
    If you are doing a string compare, you can use the format parameter of the Guid.ToString method (https://msdn.microsoft.com/en-us/library/97af8hh4(v=vs.110).aspx) to get them in the same format. – Gatogordo Jun 21 '16 at 11:59

2 Answers2

6

Actually, because your field is TOKENIZED, Sitecore stores your ID the way it does to avoid another situation from happening. TOKENIZED means, your ID will be broken down internally in Lucene like this:

c50e5028 8eba 4ba9 854cf (you get the picture)

So if you search Lucene for 8eba it will match your profile_id field as you see it now. Which is very rarely what one would expect.

To avoid this issue; don't put a Sitecore ID in the index. Not a Guid either. (there are other workarounds, but I'm showing you the simpler approach here).

Use item.ID.ToShortID() - this generates a Guid that is without curly braces and without dashes. When you later want to compare (or query), just match it up using the same .ToShortID() method.

Mark Cassidy
  • 5,829
  • 1
  • 22
  • 33
  • 1
    See also: http://stackoverflow.com/questions/9431114/termquery-not-returning-on-a-known-search-term-but-wildcardquery-does – Mark Cassidy Jun 21 '16 at 12:36
1

To me it looks like your original value is not containing curly braces.

If the field value contains curly braces (and storageType="YES") Luke will show you the value that was indexed as apposed the index data (which may be very different based on analyzer used).

If you truly want the index data to contain curly braces either set indexType="UN_TOKENIZED" or choose something like the Lucene.Net.Analysis.WhitespaceAnalyzer for the field.

herskinduk
  • 1,187
  • 6
  • 14