2

I have small issue with search results where its showing duplicate items because it has different version created and sometimes it only shows default language version.

The code i have is as per below,

Below method returns IQueryable<>

return context.GetQueryable<SearchResult>().Where(item => item["Enable"] = "1");

After I get the results I can see different version of each item, later on i do filtering/sorting as per below,

results.AddRange(query.Where(item => item.Title.Equals("keywordinput"))
    .OrderByDescending(item => item.SortOrder)
    .ThenBy(item => item.DateTime));

Soon as i use the linq, it's only showing default language not based on context language. I've tried applying language when running GetQueryable<> but then I only get item that has language but I would also like to display other items that don't have language i.e. the default language.

Is there a way I can do this? for example suppose i have

Item1 has two version en and us

Item2 has only one version en

So if someone search "item" then im expecting two results to be displayed

Item1 - us version

Item2 - en version

2

If your solution relies on Sitecore’s content search and you want to use language fallback, you must set up the particular search index to handle item- or field-level fallback. You'll want to patch in the config updates to each index you need the functionality for then perform a full rebuild.

<index id="sitecore_master_index" …>
…
   <enableItemLanguageFallback>true</enableItemLanguageFallback>
   <enableFieldLanguageFallback>true</enableFieldLanguageFallback>
…
</index>

For more information you can read the Sitecore documentation https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/language_fallback/setting_up/configure_language_fallback for the feature.

| improve this answer | |
0

Languages

You can modify your query adding a language parameter:

// This can be also defined somewhere in config, etc.
var defaultLang = "en"

var contextLang = Sitecore.Context.Language != null ? 
        Sitecore.Context.Language.Name : DefaultLanguageName;

query.Where(item => item.Title.Equals("keywordinput") 
        && (item.Language == contextLang || item.Language == defaultLang));
...

You can also use the predicate builder to make sure the queries are more readable.


Versions

In order to achieve that you can use the inbound/outbound filter.

Please, refer to the doc

If that doesn't help, you can define a new field on the indexable:

[IndexField(“_latestversion”)]
public bool IsLatestVersion { get; set; }

And then use the following condition in your query:

.Where(item => item.IsLatestVersion)
| improve this answer | |
  • Thanks, i've tried this but its giving same results apparently – CodeBox Jan 17 '17 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.