/// <summary> /// Populates a list of <see cref="TermEntry"/> with the hierarchy of terms. /// The list is ordered so that roots appear right before their child terms. public static void PopulateTermEntries(List <TermEntry> termEntries, TaxonomyField field, IEnumerable <ContentItem> contentItems, int level) { foreach (var contentItem in contentItems) { var children = Array.Empty <ContentItem>(); if (contentItem.Content.Terms is JArray termsArray) { children = termsArray.ToObject <ContentItem[]>(); } var termEntry = new TermEntry { Term = contentItem, ContentItemId = contentItem.ContentItemId, Selected = field.TermContentItemIds.Contains(contentItem.ContentItemId), Level = level, IsLeaf = children.Length == 0 }; termEntries.Add(termEntry); if (children.Length > 0) { PopulateTermEntries(termEntries, field, children, level + 1); } } }
private TermPart GetOrCreateTerm(TermEntry entry, int taxonomyId, TaxonomyField field) { var term = entry.Id > 0 ? _taxonomyService.GetTerm(entry.Id) : default(TermPart); if (term == null) { var settings = field.PartFieldDefinition.Settings.GetModel <TaxonomyFieldSettings>(); if (!settings.AllowCustomTerms || !Services.Authorizer.Authorize(Permissions.CreateTerm)) { Services.Notifier.Error(T("You're not allowed to create new terms for this taxonomy")); return(null); } var taxonomy = _taxonomyService.GetTaxonomy(taxonomyId); term = _taxonomyService.NewTerm(taxonomy); term.Container = taxonomy.ContentItem; term.Name = entry.Name.Trim(); term.Selectable = true; _taxonomyService.ProcessPath(term); Services.ContentManager.Create(term, VersionOptions.Published); Services.Notifier.Information(T("The {0} term has been created.", term.Name)); } return(term); }
public TermsWriter( TermsIndexWriterBase.FieldWriter fieldIndexWriter, FieldInfo fieldInfo, PostingsWriterBase postingsWriter, BlockTermsWriter btw) { _fieldInfo = fieldInfo; _fieldIndexWriter = fieldIndexWriter; _btw = btw; _pendingTerms = new TermEntry[32]; for (int i = 0; i < _pendingTerms.Length; i++) { _pendingTerms[i] = new TermEntry(); } _termsStartPointer = _btw._output.FilePointer; _postingsWriter = postingsWriter; _longsSize = postingsWriter.SetField(fieldInfo); }
public override void FinishTerm(BytesRef text, TermStats stats) { if (Debugging.AssertsEnabled) { Debugging.Assert(stats.DocFreq > 0); } //System.out.println("BTW: finishTerm term=" + fieldInfo.name + ":" + text.utf8ToString() + " " + text + " seg=" + segment + " df=" + stats.docFreq); bool isIndexTerm = fieldIndexWriter.CheckIndexTerm(text, stats); if (isIndexTerm) { if (pendingCount > 0) { // Instead of writing each term, live, we gather terms // in RAM in a pending buffer, and then write the // entire block in between index terms: FlushBlock(); } fieldIndexWriter.Add(text, stats, outerInstance.m_output.Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream //System.out.println(" index term!"); } if (pendingTerms.Length == pendingCount) { TermEntry[] newArray = new TermEntry[ArrayUtil.Oversize(pendingCount + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.Array.Copy(pendingTerms, 0, newArray, 0, pendingCount); for (int i = pendingCount; i < newArray.Length; i++) { newArray[i] = new TermEntry(); } pendingTerms = newArray; } TermEntry te = pendingTerms[pendingCount]; te.Term.CopyBytes(text); te.State = postingsWriter.NewTermState(); te.State.DocFreq = stats.DocFreq; te.State.TotalTermFreq = stats.TotalTermFreq; postingsWriter.FinishTerm(te.State); pendingCount++; numTerms++; }
internal TermsWriter( BlockTermsWriter outerInstance, TermsIndexWriterBase.FieldWriter fieldIndexWriter, FieldInfo fieldInfo, PostingsWriterBase postingsWriter) { this.outerInstance = outerInstance; this.fieldInfo = fieldInfo; this.fieldIndexWriter = fieldIndexWriter; pendingTerms = new TermEntry[32]; for (int i = 0; i < pendingTerms.Length; i++) { pendingTerms[i] = new TermEntry(); } termsStartPointer = outerInstance.m_output.Position; // LUCENENET specific: Renamed from getFilePointer() to match FileStream this.postingsWriter = postingsWriter; this.longsSize = postingsWriter.SetField(fieldInfo); }
internal TermsWriter( BlockTermsWriter outerInstance, TermsIndexWriterBase.FieldWriter fieldIndexWriter, FieldInfo fieldInfo, PostingsWriterBase postingsWriter) { this.outerInstance = outerInstance; this.fieldInfo = fieldInfo; this.fieldIndexWriter = fieldIndexWriter; pendingTerms = new TermEntry[32]; for (int i = 0; i < pendingTerms.Length; i++) { pendingTerms[i] = new TermEntry(); } termsStartPointer = outerInstance.m_output.GetFilePointer(); this.postingsWriter = postingsWriter; this.longsSize = postingsWriter.SetField(fieldInfo); }
private ContentItem GetTermContentItem(TermEntry entry, ContentItem taxonomy) { // var term = default(TermPart); var termContentItem = default(ContentItem); if (taxonomy == null) { return(null); } if (!string.IsNullOrEmpty(entry.ContentItemId)) { termContentItem = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, entry.ContentItemId); } return(termContentItem); }
public override void FinishTerm(BytesRef text, TermStats stats) { Debug.Assert(stats.DocFreq > 0); var isIndexTerm = _fieldIndexWriter.CheckIndexTerm(text, stats); if (isIndexTerm) { if (_pendingCount > 0) { // Instead of writing each term, live, we gather terms // in RAM in a pending buffer, and then write the // entire block in between index terms: FlushBlock(); } _fieldIndexWriter.Add(text, stats, _btw._output.FilePointer); } if (_pendingTerms.Length == _pendingCount) { var newArray = new TermEntry[ArrayUtil.Oversize(_pendingCount + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; Array.Copy(_pendingTerms, 0, newArray, 0, _pendingCount); for (var i = _pendingCount; i < newArray.Length; i++) { newArray[i] = new TermEntry(); } _pendingTerms = newArray; } var te = _pendingTerms[_pendingCount]; te.Term.CopyBytes(text); te.State = _postingsWriter.NewTermState(); te.State.DocFreq = stats.DocFreq; te.State.TotalTermFreq = stats.TotalTermFreq; _postingsWriter.FinishTerm(te.State); _pendingCount++; _numTerms++; }
private TermPart GetOrCreateTerm(TermEntry entry, int taxonomyId, TaxonomyField field) { var term = default(TermPart); if (entry.Id > 0) { term = _taxonomyService.GetTerm(entry.Id); } //Prevents creation of existing term if (term == null && !string.IsNullOrEmpty(entry.Name)) { term = _taxonomyService.GetTermByName(taxonomyId, entry.Name.Trim()); } if (term == null) { var settings = field.PartFieldDefinition.Settings.GetModel <TaxonomyFieldSettings>(); if (!settings.AllowCustomTerms || !Services.Authorizer.Authorize(Permissions.CreateTerm)) { Services.Notifier.Error(T("You're not allowed to create new terms for this taxonomy")); return(null); } var taxonomy = _taxonomyService.GetTaxonomy(taxonomyId); term = _taxonomyService.NewTerm(taxonomy); term.Name = entry.Name.Trim(); term.Selectable = true; Services.ContentManager.Create(term, VersionOptions.Published); Services.Notifier.Success(T("The {0} term has been created.", term.Name)); } return(term); }
TermsWriter( TermsIndexWriterBase.FieldWriter fieldIndexWriter, FieldInfo fieldInfo, PostingsWriterBase postingsWriter) { this.fieldInfo = fieldInfo; this.fieldIndexWriter = fieldIndexWriter; pendingTerms = new TermEntry[32]; for(int i=0;i<pendingTerms.length;i++) { pendingTerms[i] = new TermEntry(); } termsStartPointer = out.getFilePointer(); this.postingsWriter = postingsWriter; this.longsSize = postingsWriter.setField(fieldInfo); }
public static int GetLevels(this TermEntry term) { return(String.IsNullOrEmpty(term.Path) ? 0 : term.Path.Count(c => c == '/') - 1); }
public override void FinishTerm(BytesRef text, TermStats stats) { Debug.Assert(stats.DocFreq > 0); var isIndexTerm = _fieldIndexWriter.CheckIndexTerm(text, stats); if (isIndexTerm) { if (_pendingCount > 0) { // Instead of writing each term, live, we gather terms // in RAM in a pending buffer, and then write the // entire block in between index terms: FlushBlock(); } _fieldIndexWriter.Add(text, stats, _btw._output.FilePointer); } if (_pendingTerms.Length == _pendingCount) { var newArray = new TermEntry[ArrayUtil.Oversize(_pendingCount + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; Array.Copy(_pendingTerms, 0, newArray, 0, _pendingCount); for (var i = _pendingCount; i < newArray.Length; i++) { newArray[i] = new TermEntry(); } _pendingTerms = newArray; } var te = _pendingTerms[_pendingCount]; te.Term.CopyBytes(text); te.State = _postingsWriter.NewTermState(); te.State.DocFreq = stats.DocFreq; te.State.TotalTermFreq = stats.TotalTermFreq; _postingsWriter.FinishTerm(te.State); _pendingCount++; _numTerms++; }
public TermsWriter( TermsIndexWriterBase.FieldWriter fieldIndexWriter, FieldInfo fieldInfo, PostingsWriterBase postingsWriter, BlockTermsWriter btw) { _fieldInfo = fieldInfo; _fieldIndexWriter = fieldIndexWriter; _btw = btw; _pendingTerms = new TermEntry[32]; for (int i = 0; i < _pendingTerms.Length; i++) { _pendingTerms[i] = new TermEntry(); } _termsStartPointer = _btw._output.FilePointer; _postingsWriter = postingsWriter; _longsSize = postingsWriter.SetField(fieldInfo); }