2017-12-12 5 views
0

Sagen wir, ich habe 2 Dokumente mit je 2 Tags.Lucene.net 4.8: Reihenfolge des Hinzufügens von Facetten von Bedeutung?

Doc 1: Tag 1, Tag 2 Doc 2: Tag 2, Tag 1

ich ein Dokument in lucene wie dieses Gebäude:

 var doc = new Document 
     { 
      new StoredField("Id", blogPost.Id), 
      new Int32Field("ModuleId", blogPost.ModuleId, Field.Store.YES), 
      new TextField("Title", blogPost.Title, Field.Store.YES), 
      new StringField("Slug", blogPost.Slug, Field.Store.YES), 
      new StoredField("ImagePath", blogPost.ImagePath), 
      new TextField("Intro", blogPost.Intro, Field.Store.YES), 
      new TextField("Html", blogPost.Title, Field.Store.YES), 
      new Int64Field("PublishDate", blogPost.PublishDate.Ticks, Field.Store.YES), 
      new FacetField("PublishDateTag", blogPost.PublishDate.Year.ToString(), blogPost.PublishDate.Month.ToString(), blogPost.PublishDate.Year.ToString()) 
     }; 

     foreach (var tag in blogPost.TagObjects) 
     { 
      doc.Add(new Int32AssociationFacetField(1,"Tags", tag.Name)); 
      doc.Add(new StringField("Tag", tag.Name, Field.Store.YES)); 

      doc.Add(new Int32AssociationFacetField(1, "TagSlugs", tag.Slug)); 
      doc.Add(new StringField("TagSlug", tag.Slug, Field.Store.YES)); 

Facetten bekommen arbeiten, wie ich nicht will hart sein. Wenn ich eine Suche wie folgt tun:

 var facetsConfig = ConfigFacets(); 

     IList<FacetResult> results = new List<FacetResult>(); 

     using (var indexReader = DirectoryReader.Open(IndexDir)) 
     using (var taxoReader = new DirectoryTaxonomyReader(TaxoDir)) 
     { 
      var searcher = new IndexSearcher(indexReader); 
      var facetsCollector = new FacetsCollector(); 

      // MatchAllDocsQuery is for "browsing" (counts facets 
      // for all non-deleted docs in the index); normally 
      // you'd use a "normal" query: 
      FacetsCollector.Search(searcher, new MatchAllDocsQuery(), 10, facetsCollector); 

      // Retrieve results 
      Facets tags = new TaxonomyFacetSumInt32Associations("$tag", taxoReader, facetsConfig, facetsCollector); 
      results.Add(tags.GetTopChildren(10, "Tags")); 

     } // Disposes indexReader and taxoReader 

     if (results[0] == null) 
      return new Dictionary<string, int>(); 

     return results.Where(x => x.Dim == "Tags").SelectMany(x => x.LabelValues).ToDictionary(x => x.Label, x => Convert.ToInt32(x.Value)); 

Das Ergebnis ist wie folgt: Tag 1 (1), Tag 1 (1), Tag 2 (1), Tag 2 (1)

Es sieht Wie die Reihenfolge der Tags spielt irgendwie eine Rolle, die ich gar nicht möchte. Wie kann ich das beheben?

+0

Niemand, der mir helfen kann? :( – brechtvhb

Antwort

0

Gottverdammt! Stellt sich als ein dummer Fehler heraus.

Ich habe eine Saite geteilt, aber danach nicht geschnitten. Also habe ich "Tag 1", "Tag 2" für das erste Dokument und "Tag 2", "Tag 1" für das zweite hinzugefügt.

Verwandte Themen