How to Filter ContentItem by Field using Lucene. #11262
Unanswered
jaypeemayo
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Here is a small helper method that I use for Lucene in a Controller : private async Task<OrchardCore.Lucene.LuceneQueryResults> LuceneQueryAsync(string queryName, Dictionary<string, object> parameters)
{
var contentItems = new List<ContentItem>();
var query = await _queryManager.GetQueryAsync(queryName);
var queryResult = new OrchardCore.Lucene.LuceneQueryResults();
if (query != null)
{
queryResult = (OrchardCore.Lucene.LuceneQueryResults)await _queryManager.ExecuteQueryAsync(query, parameters);
if (queryResult.Items != null)
{
foreach (var item in (IEnumerable)queryResult.Items)
{
if (!(item is ContentItem contentItem))
{
contentItem = null;
if (item is JObject jObject)
{
contentItem = jObject.ToObject<ContentItem>();
}
}
// If input is a 'JObject' but which not represents a 'ContentItem',
// a 'ContentItem' is still created but with some null properties.
if (contentItem?.ContentItemId == null)
{
continue;
}
contentItems.Add(contentItem);
}
}
queryResult.Items = contentItems;
}
return queryResult;
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have this code and my objective is just to get all of the content items (with type Episode) that have a o?.Content?.Episode?.Series?.ContentItemIds.First?.Value field that matches the seriesId value.
I find the Where clause slow because it loops through all of the Episodes. I was thinking to do this in Lucene.
I tried to search for Ochard Core Lucene implementation but cannot find a good one. Can anyone help me with this?
Beta Was this translation helpful? Give feedback.
All reactions