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

Commit

Permalink
[KFI] Following API changes #2 (partial).
Browse files Browse the repository at this point in the history
  • Loading branch information
kavics committed Nov 2, 2017
1 parent 66c5a15 commit c911eac
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 256 deletions.
155 changes: 77 additions & 78 deletions src/WebPages/ContentStore/ContentStoreApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
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 +131,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,7 +145,7 @@ private static object[] GetChildrenByNodeInternal(Node node, bool includeLeafNod
}

[ODataFunction]
public static bool IsLuceneQuery(Content content, string rnd)
public static bool IsLuceneQuery(Content content, string rnd) //UNDONE: Do not use "Lucene"
{
AssertPermission(PlaceholderPath);

Expand All @@ -152,7 +154,7 @@ public static bool IsLuceneQuery(Content content, string rnd)

private static bool IsLuceneQueryInternal()
{
return StorageContext.Search.SearchEngine.GetType() == typeof(LuceneSearchEngine);
return SearchManager.IsOuterEngineEnabled;
}

[ODataFunction]
Expand All @@ -164,18 +166,15 @@ public static object[] Search(Content content, string searchStr, string searchRo
{
return SearchLucene(searchStr, searchRoot, contentTypes, simpleContent);
}
else
{
return SearchNodeQuery(searchStr, searchRoot, contentTypes, simpleContent);
}
throw new SnNotSupportedException("ContemtQuery is disabled.");
}

private static object[] SearchLucene(string searchStr, string searchRoot, string contentTypes, bool simpleContent = false)
{
var queryStr = CreateLuceneQueryString(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,76 +193,76 @@ 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 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)
{
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.Default).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
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.Default).Nodes;
}
public static IEnumerable<Node> GetCategoriesFromRepo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Xml.XPath;
using SenseNet.Portal.Virtualization;
using SenseNet.ContentRepository.Storage.Search;
using SenseNet.Search.Querying;

namespace SenseNet.Portal.Portlets
{
Expand Down Expand Up @@ -336,15 +337,15 @@ protected override object GetModel()
if (State.Skip > 0)
cdef.Skip = State.Skip;
if (!string.IsNullOrEmpty(State.SortColumn))
cdef.Sort = new[] { new SortInfo { FieldName = State.SortColumn, Reverse = State.SortDescending } };
cdef.Sort = new[] { new SortInfo ( State.SortColumn, State.SortDescending ) };

var filter = GetQueryFilter();

if (!string.IsNullOrEmpty(content.ChildrenDefinition.ContentQuery))
{
// combine the two queries (e.g. in case of a Smart Folder or a container with a custom children query)
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);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/WebPages/Portlets/ContextSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using SenseNet.ApplicationModel;
using SenseNet.ContentRepository.Workspaces;
using SenseNet.Search;
using SenseNet.Search.Querying;

namespace SenseNet.Portal.Portlets
{
Expand Down Expand Up @@ -312,13 +313,13 @@ protected override object GetModel()
var escapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)");
model.ChildrenDefinition.ContentQuery =
ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery,
ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", escapedPath), ChainOperator.And), ChainOperator.And);
ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", escapedPath), LogicalOperator.And), LogicalOperator.And);
}
}
else
{
if (!string.IsNullOrEmpty(sf.Query))
model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, sf.Query, ChainOperator.And);
model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, sf.Query, LogicalOperator.And);
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/WebPages/Portlets/SiteMenu/SiteMenuNodeEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ protected SiteMenuNodeEnumerator(string path, ExecutionHint executionHint,
_childrenFilter = filter;
}

protected override NodeQueryResult QueryChildrenFromLucene(int thisId)
{
if (string.IsNullOrEmpty(_childrenFilter))
{
return base.QueryChildrenFromLucene(thisId);
}
else
{
// We need to apply a query filter. Execute a content
// query and create a node query result on-the-fly.
var query = ContentQuery.CreateQuery("+ParentId:@0", null, thisId);
/**///protected override NodeQueryResult QueryChildrenFromLucene(int thisId)
//{
// if (string.IsNullOrEmpty(_childrenFilter))
// {
// return base.QueryChildrenFromLucene(thisId);
// }
// else
// {
// // We need to apply a query filter. Execute a content
// // query and create a node query result on-the-fly.
// var query = ContentQuery.CreateQuery("+ParentId:@0", null, thisId);

if (!string.IsNullOrEmpty(_childrenFilter))
query.AddClause(_childrenFilter);
// if (!string.IsNullOrEmpty(_childrenFilter))
// query.AddClause(_childrenFilter);

return new NodeQueryResult(query.ExecuteToIds(ExecutionHint.ForceIndexedEngine));
}
}
// return new NodeQueryResult(query.ExecuteToIds(ExecutionHint.ForceIndexedEngine));
// }
//}

protected override bool MoveToFirstChild()
{
Expand Down
2 changes: 1 addition & 1 deletion src/WebPages/Portlets/UserGroupManagerPortlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private List<Node> GetGroups()
var groups = new List<Node>();
if (!String.IsNullOrEmpty(GroupQuery))
{
var sort = new[] { new SortInfo { FieldName = "Name" } };
var sort = new[] {new SortInfo("Name")};
var settings = new QuerySettings { EnableAutofilters = FilterStatus.Disabled, EnableLifespanFilter = FilterStatus.Disabled, Sort = sort };
var query = new ContentQuery { Text = GroupQuery, Settings = settings};
query.AddClause(string.Format("-Path:({0})", string.Join(" ", Identifiers.SpecialGroupPaths)));
Expand Down
Loading

0 comments on commit c911eac

Please sign in to comment.