Gravatar for

Question by rloeb, Sep 20, 2016 7:58 PM

Sitecore field suffix hash issues

We are sending coveo-rest queries ourselves via json, and thus need to convert "friendly" field names to their coveo counterparts. Eg. "myfield" = "fmyfield1234"

We found the utility function that does the conversion works but for some reason was nonperformant and since we were converting the same field names every time we just cached the first result.

The problem though is it seems like sometimes those hashes change, or otherwise don't match the field names in the source we want to hit? For example, we might have cached @fmyfield1234 but we see the field missing, we go look at the index and see it's @myfield4567 or something. We suspect someone did an index rebuild or something that reset that hash, but we're not sure. It seems like if we bounce IIS (our application is to clear our cache, everything is fine (for a while….).

Can you tell us: a) does the suffix hash # ever change? we thought maybe sometimes doing an index rebuild via the sitecore interface or something can occasionally change that #? b) does this sound like a familiar cm/cd issue? how can we assure that multiple coveo indexes share the same suffix? c) recommended or not, can we turn the suffixing off altogether? d) is there some method call to determine the suffix programatically?


1 Reply
Gravatar for

Answer by Sébastien Belzile, Sep 21, 2016 8:20 AM

a) No. The field hash is computed from the source name. This means that if your source changes in name, the hash will change.

b) By explicitely setting the source name in your Coveo indexes configurations. The name has to be the same for every CMs and CDs.

<index [...]

c) No

d) Yes, the ToCoveoFieldName method. For the hash only, no, there is none. If you want to implement one, you can still look at the code in the CoveoIndexNamesBuilder from the Framework assembly.

This translation has been ported client-side (next release? I will have to confirm). Maybe this will solve some of your performance issues.

Gravatar for

Comment by rloeb, Sep 24, 2016 2:35 PM

For the ToCoveoFieldName method, it seems to rely on the sitecore session to determine which index's fields to return. We have an issue where the user could:

a) start the browser and log into sitecore and make edits in master.

b) open a separate tab and use our own application to run a search wherein we create our own json coveo-rest query solely against web index, but rely upon the ToCoveoFieldName method to give us field names, and end up with the master suffix on field names returned.

c) (couldn't this also happen if we used linq?)

Is there some way to "fool" ToCoveoFieldName into applying to a particular index, e.g. wrapping it in some kind of using block? Any other suggestions on how to deal with this scenario?

We're quite concerned about this and we believe it is causing us some latent bugs.

Gravatar for

Comment by Sébastien Belzile, Sep 26, 2016 9:16 AM

a) ? I don't see what could go wrong here.

b) I do not know your setup. But in that case, since you query only one index, you could implement your own ToCoveoFieldName method quite easily.

c) Not an issue, when using LINQ, you explicitely specify which index you want to use.

There are currently no way of doing what you ask for. I added the story on our side to investigate what it would represent to add what you are asking for.

Gravatar for

Comment by rloeb, Sep 26, 2016 11:11 AM

With respect to b) our own ToCoveoFieldName method, I agree it would be easy but what would be your's/Coveo's suggestion on how to resolve the numerical suffix given index name and service information? We have some ideas but would appreciate Coveo's input. Thanks.

Gravatar for

Comment by Sébastien Belzile, Sep 26, 2016 11:15 AM

This is how it is done in our code:

private int ComputeHashCode(string p_SourceName)
    uint hash = 0;
    foreach (byte b in Encoding.Unicode.GetBytes(p_SourceName)) {
        hash += b;
        hash += (hash << 10);
        hash ^= (hash >> 6);
    hash += (hash << 3);
    hash ^= (hash >> 11);
    hash += (hash << 15);

    return (int) (hash % 100000);
Gravatar for

Comment by rloeb, Sep 26, 2016 2:57 PM

What is p_SourceName? I'm guessing it must be some combination of both the source name and service name?

We were thinking of either doing something of what you described, or else just looking at the suffix in the admin and sort-of hardcoding some kind of regex fail-safe.

Gravatar for

Comment by Sébastien Belzile, Sep 26, 2016 3:45 PM

p_SourceName is just the name of the source. Sorry, I thought it would be intuitive. It is whatever you set as sourceName on your source, or the name generated if not specified ([index name] - [FarmName or instance name]).

What do you mean by "service name"?

Ask a question