Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge changes from develop (IR module refactor).
Browse files Browse the repository at this point in the history
  • Loading branch information
tusmester committed Mar 5, 2018
2 parents 036e0c3 + 2cf00be commit f73086c
Show file tree
Hide file tree
Showing 104 changed files with 291 additions and 7,050 deletions.
117 changes: 22 additions & 95 deletions src/WebPages/ContentStore/ContentStoreApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
using SenseNet.ContentRepository;
using SenseNet.ContentRepository.Storage.Security;
using SenseNet.Search;
using SenseNet.ContentRepository.Storage.Search;
using SenseNet.ContentRepository.Storage.Schema;
using SenseNet.ApplicationModel;
using SenseNet.Configuration;
using SenseNet.ContentRepository.Search;
using SenseNet.Search.Querying;

namespace SenseNet.Portal.ContentStore
{
Expand Down Expand Up @@ -129,7 +129,7 @@ private static object[] GetChildrenByNodeInternal(Node node, bool includeLeafNod

// add content type filter if needed
if (!string.IsNullOrEmpty(filter))
content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, ChainOperator.And);
content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, LogicalOperator.And);

// in case of SmartFolder: do not override the settings given on the content
if (!(folderParent is SmartFolder))
Expand All @@ -143,39 +143,37 @@ private static object[] GetChildrenByNodeInternal(Node node, bool includeLeafNod
}

[ODataFunction]
[Obsolete("Use IsContentQuery instead.")]
public static bool IsLuceneQuery(Content content, string rnd)
{
AssertPermission(PlaceholderPath);

return IsLuceneQueryInternal();
return IsContentQuery(content, rnd);
}

private static bool IsLuceneQueryInternal()
[ODataFunction]
public static bool IsContentQuery(Content content, string rnd)
{
return StorageContext.Search.SearchEngine.GetType() == typeof(LuceneSearchEngine);
AssertPermission(PlaceholderPath);

return SearchManager.IsOuterEngineEnabled;
}

[ODataFunction]
public static object[] Search(Content content, string searchStr, string searchRoot, string contentTypes, string rnd, bool simpleContent = false)
{
AssertPermission(PlaceholderPath);

if (IsLuceneQueryInternal())
if (SearchManager.IsOuterEngineEnabled)
{
return SearchLucene(searchStr, searchRoot, contentTypes, simpleContent);
}
else
{
return SearchNodeQuery(searchStr, searchRoot, contentTypes, simpleContent);
return SearchContentQuery(searchStr, searchRoot, contentTypes, simpleContent);
}
throw new SnNotSupportedException("ContentQuery is disabled.");
}

private static object[] SearchLucene(string searchStr, string searchRoot, string contentTypes, bool simpleContent = false)
private static object[] SearchContentQuery(string searchStr, string searchRoot, string contentTypes, bool simpleContent = false)
{
var queryStr = CreateLuceneQueryString(searchStr, searchRoot, contentTypes);
var queryStr = CreateContentQueryString(searchStr, searchRoot, contentTypes);
var query = ContentQuery.CreateQuery(queryStr, new QuerySettings
{
Sort = new List<SortInfo> { new SortInfo { FieldName = "DisplayName" } },
Sort = new List<SortInfo> { new SortInfo("DisplayName") },
EnableAutofilters = FilterStatus.Disabled,
EnableLifespanFilter = FilterStatus.Disabled
});
Expand All @@ -194,89 +192,18 @@ private static object[] SearchLucene(string searchStr, string searchRoot, string
}
}

private static object[] SearchNodeQuery(string searchStr, string searchRoot, string contentTypes, bool simpleContent = false)
{
if (!string.IsNullOrEmpty(searchStr))
{
// simple nodequery
var query = new NodeQuery();
query.Add(new SearchExpression(searchStr));
var nodes = query.Execute().Nodes;

// filter with path
if (!string.IsNullOrEmpty(searchRoot))
nodes = nodes.Where(n => n.Path.StartsWith(searchRoot));

// filter with contenttypes
if (!string.IsNullOrEmpty(contentTypes))
{
var contentTypesArr = GetContentTypes(contentTypes);
nodes = nodes.Where(n => contentTypesArr.Contains(n.NodeType.Name));
}

if (simpleContent)
{
var contents = nodes.Where(n => n != null).Select(n => new cs.SimpleServiceContent(n));
return contents.ToArray();
}
else
{
var contents = nodes.Where(n => n != null).Select(n => new cs.Content(n, true, false, false, false, 0, 0));
return contents.ToArray();
}
}
else
{
if (string.IsNullOrEmpty(searchRoot) && string.IsNullOrEmpty(contentTypes))
return null;

var query = new NodeQuery();
var andExpression = new ExpressionList(ChainOperator.And);
query.Add(andExpression);

// filter with path
if (!string.IsNullOrEmpty(searchRoot))
andExpression.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, searchRoot));

// filter with contenttypes
if (!string.IsNullOrEmpty(contentTypes))
{
var contentTypesArr = GetContentTypes(contentTypes);
var orExpression = new ExpressionList(ChainOperator.Or);
foreach (var contentType in contentTypesArr)
{
orExpression.Add(new TypeExpression(NodeType.GetByName(contentType), true));
}
andExpression.Add(orExpression);
}

var nodes = query.Execute().Nodes;

if (simpleContent)
{
var contents = nodes.Select(n => new cs.SimpleServiceContent(n));
return contents.ToArray();
}
else
{
var contents = nodes.Select(n => new cs.Content(n, true, false, false, false, 0, 0));
return contents.ToArray();
}
}
}

private static bool IsLuceneSyntax(string s)
private static bool IsContentQuerySyntax(string s)
{
return s.Contains(":") || s.Contains("+") || s.Contains("*");
}

private static string CreateLuceneQueryString(string searchStr, string searchRoot, string contentTypesStr)
private static string CreateContentQueryString(string searchStr, string searchRoot, string contentTypesStr)
{
var queryStr = string.Empty;

if (!string.IsNullOrEmpty(searchStr))
{
if (!IsLuceneSyntax(searchStr))
if (!IsContentQuerySyntax(searchStr))
{
// more than one word: _Text:<kifejezés>
// one word without quotation marks: _Text:<kifejezés>*
Expand All @@ -298,20 +225,20 @@ private static string CreateLuceneQueryString(string searchStr, string searchRoo
// -> +(_Text:user1 _Text:user2) +(<ancestor and contentype queries>)
// ie.: +_Text:user1 +_Text:user2
// -> +(+_Text:user1 +_Text:user2) +(<ancestor and contentype queries>)
searchStr = string.Format("+({0})", searchStr);
searchStr = $"+({searchStr})";

queryStr = searchStr;
}

if (!string.IsNullOrEmpty(searchRoot))
{
var pathQuery = string.Format("+InTree:\"{0}\"", searchRoot.ToLower());
var pathQuery = $"+InTree:\"{searchRoot.ToLower()}\"";
queryStr = string.Concat(queryStr, " ", pathQuery);
}

if (!string.IsNullOrEmpty(contentTypesStr))
{
queryStr = string.Format("{0} +({1})", queryStr, GetContentTypesFilter(contentTypesStr));
queryStr = $"{queryStr} +({GetContentTypesFilter(contentTypesStr)})";
}

return queryStr;
Expand Down
36 changes: 12 additions & 24 deletions src/WebPages/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
using SenseNet.ContentRepository.Storage;
using SenseNet.ContentRepository.Storage.Data;
using SenseNet.ContentRepository.Storage.Search;
using SenseNet.ContentRepository.Storage.Search.Internal;
using SenseNet.ContentRepository.Storage.Security;
using SenseNet.Portal.Virtualization;
using SenseNet.Diagnostics;
using System.Xml;
using SenseNet.ContentRepository.Search;
using SenseNet.Search;
using SenseNet.ContentRepository.Search.Querying;

namespace SenseNet.Portal
{
Expand Down Expand Up @@ -49,18 +51,14 @@ private void SetPageData()

if (this.SmartUrl != String.Empty)
{
NodeQueryResult result;
QueryResult result;
using (new SystemAccount())
{
if (RepositoryInstance.ContentQueryIsAllowed)
if (SearchManager.ContentQueryIsAllowed)
{
// this NodeQuery will be compiled to LucQuery because the outer engine is enabled
var pageQuery = new NodeQuery();
pageQuery.Add(new TypeExpression(ActiveSchema.NodeTypes[typeof(Page).Name]));
pageQuery.Add(new StringExpression(ActiveSchema.PropertyTypes["SmartUrl"], StringOperator.Equal, this.SmartUrl));
pageQuery.Add(new NotExpression(new StringExpression(StringAttribute.Path, StringOperator.Equal, this.Path)));

result = pageQuery.Execute();
result = ContentQuery.Query(SafeQueries.SmartUrlCollision,
QuerySettings.AdminSettings,
typeof(Page).Name, this.SmartUrl, this.Path);
}
else
{
Expand Down Expand Up @@ -264,31 +262,22 @@ public override IEnumerable<ContentType> AllowedChildTypes

#region OfflineExecution

internal static NodeQueryResult GetAllPage()
{
NodeQuery query = new NodeQuery();
query.Add(new TypeExpression(ActiveSchema.NodeTypes["Page"], true));
return query.Execute();
}

public static string[] RunPagesBackground(HttpContext context, out Exception[] exceptions)
{
var pages = GetAllPage();
string[] result = new string[pages.Count];
List<string> pageList = new List<string>();
List<Exception> exceptionList = new List<Exception>();
var pagesNodes = ContentQuery.Query(ContentRepository.SafeQueries.TypeIs, QuerySettings.AdminSettings, typeof(Page).Name).Nodes;

foreach (Node pageItem in pages.Nodes)
foreach (var pageItem in pagesNodes)
{
Exception exc = null;
Page p = (Page)pageItem;
if (p != null && p.HasTemporaryPortletInfo)
{
Site site = p.Site;

if (site != null)
{
Page.RunPage(HttpContext.Current, p.Path, p, out exc);
Page.RunPage(HttpContext.Current, p.Path, p, out var exc);
pageList.Add(p.Path);

if (exc != null)
Expand All @@ -297,9 +286,8 @@ public static string[] RunPagesBackground(HttpContext context, out Exception[] e
}
}
}
pageList.CopyTo(result, 0);
exceptions = exceptionList.ToArray();
return result;
return pageList.ToArray();
}

internal static void RunPage(HttpContext context, string path, Page pageNode, out Exception exception)
Expand Down
11 changes: 5 additions & 6 deletions src/WebPages/PageTemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using SenseNet.ContentRepository.Storage.Search;
using SenseNet.Portal.UI;
using SenseNet.ContentRepository;
using SenseNet.ContentRepository.Search;
using SenseNet.Search;

namespace SenseNet.Portal
{
Expand Down Expand Up @@ -307,13 +309,10 @@ private static int GetSmallest(string pageTmp, int pos, out string posType)

private IEnumerable<Node> LoadPageList()
{
if (RepositoryInstance.ContentQueryIsAllowed)
if (SearchManager.ContentQueryIsAllowed)
{
// this NodeQuery will be compiled to LucQuery because the outer engine is enabled
NodeQuery query = new NodeQuery();
query.Add(new TypeExpression(ActiveSchema.NodeTypes[typeof(Page).Name], false));
query.Add(new ReferenceExpression(ActiveSchema.PropertyTypes["PageTemplateNode"], _pageTemplate));
return query.Execute().Nodes;
var cql = $"+TypeIs:{typeof(Page).Name} + PageTemplateNode:{_pageTemplate.Id}";
return ContentQuery.Query(cql, QuerySettings.AdminSettings).Nodes;
}
// we need to execute a direct database query because the outer engine is disabled
return NodeQuery.QueryNodesByReferenceAndType("PageTemplateNode", this.PageTemplateNode.Id, ActiveSchema.NodeTypes[typeof(Page).Name], false).Nodes;
Expand Down
46 changes: 12 additions & 34 deletions src/WebPages/PortletFramework/DropDownPartField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,16 @@ private void BuildList()
if (this.DropdownOptions.CommonType == DropDownCommonType.ContentTypeDropdown)
{
// special use-case, content type list is defined in webconfig
NodeQueryResult contentTypeNames = GetWebContentTypeList();
if (contentTypeNames.Count > 0)
{
foreach (var ctContent in contentTypeNames.Nodes.Select(Content.Create))
{
this.Items.Add(new ListItem(ctContent.DisplayName, ctContent.Name));
}
}
var contentTypeNodes = GetWebContentTypeList();
foreach (var ctContent in contentTypeNodes.Select(Content.Create))
this.Items.Add(new ListItem(ctContent.DisplayName, ctContent.Name));
}

if (!string.IsNullOrEmpty(this.DropdownOptions.Query))
{
// the list is built up from a query
var sortinfo = new List<SortInfo>() { new SortInfo() { FieldName = "Name", Reverse = false } };
var settings = new QuerySettings() { EnableAutofilters = FilterStatus.Disabled, Sort = sortinfo };
var sortinfo = new List<SortInfo> {new SortInfo("Name")};
var settings = new QuerySettings { EnableAutofilters = FilterStatus.Disabled, Sort = sortinfo };
var query = ContentQuery.CreateQuery(this.DropdownOptions.Query, settings);
var result = query.Execute();
if (result.Count == 0)
Expand Down Expand Up @@ -148,36 +143,19 @@ private static bool IsValidContentType(string ctdName)
{
return ActiveSchema.NodeTypes.ToNameArray().Contains(ctdName);
}
public static NodeQueryResult GetWebContentTypeList()
public static IEnumerable<Node> GetWebContentTypeList()
{
var contentTypeNames = WebApplication.WebContentNameList;
if (string.IsNullOrEmpty(contentTypeNames))
contentTypeNames = DefaultContentTypeName;

var list = contentTypeNames.Split(',');
var validCtdNames = list.Where(c => IsValidContentType(c.Trim())).Select(c => c.Trim()).ToList();

var expressionList = new ExpressionList(ChainOperator.Or);
var query = new NodeQuery();
foreach (var ctd in validCtdNames)
{
var stringExpressionValue = RepositoryPath.Combine(Repository.ContentTypesFolderPath, string.Concat(ActiveSchema.NodeTypes[ctd].NodeTypePath, "/"));
expressionList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, stringExpressionValue));
}

if (validCtdNames.Count == 0 && IsValidContentType(DefaultContentTypeName))
{
var stringExpressionValue = RepositoryPath.Combine(Repository.ContentTypesFolderPath, string.Concat(ActiveSchema.NodeTypes[DefaultContentTypeName].NodeTypePath, "/"));
expressionList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, stringExpressionValue));
}

// no expressions, nothing to query for
if (expressionList.Expressions.Count == 0)
return new NodeQueryResult(new int[0]);

query.Add(expressionList);
var validCtdNames = contentTypeNames.Split(',').Select(c => c.Trim()).Where(IsValidContentType).ToArray();
if (validCtdNames.Length == 0)
return new Node[0];

return query.Execute();
var namesClause = string.Join(" ", validCtdNames);
var cql = $"+TypeIs:ContentType +Name:({namesClause})";
return ContentQuery.Query(cql, QuerySettings.AdminSettings).Nodes;
}
}
}
9 changes: 3 additions & 6 deletions src/WebPages/PortletFramework/PortletInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using SenseNet.ContentRepository.Storage.Schema;
using System.Text.RegularExpressions;
using SenseNet.Configuration;
using SenseNet.Search;
using SenseNet.Tools;

namespace SenseNet.Portal.UI.PortletFramework
Expand Down Expand Up @@ -78,12 +79,8 @@ public static List<PortletCategory> GetCategories(List<PortletInventoryItem> por
}
public static IEnumerable<Node> GetPortletsFromRepo()
{
var query = new NodeQuery();
var expression = new ExpressionList(ChainOperator.And);
expression.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, PortletsFolderPath));
expression.Add(new TypeExpression(NodeType.GetByName("Portlet")));
query.Add(expression);
return query.Execute().Nodes;
var cql = $"+TypeIs:{NodeType.GetByName("Portlet").Name} +InTree:{PortletsFolderPath}";
return ContentQuery.Query(cql, QuerySettings.AdminSettings).Nodes;
}
public static IEnumerable<Node> GetCategoriesFromRepo()
{
Expand Down
Loading

0 comments on commit f73086c

Please sign in to comment.