Ejemplo n.º 1
0
        /// <summary>
        /// Add terms in collection of all terms TermDocumentCountColl.
        /// Try find term, if not exist, add with count 1 or add counter to existing term.
        /// </summary>
        /// <param name="terms"></param>
        /// <returns></returns>
        public int PutTermDocumentCounts(List <TermData> terms)
        {
            //TODO: document it why we lock if we user (Connection = ConnectionType.Shared) or we have plan not use share or LiteDB have bug about it? - 2020-12-22T09:18:47
            lock (_lockerTermDocumentCountColl)
            {
                List <TermDocumentCountData> termDocumentCounts = new List <TermDocumentCountData>();
                foreach (TermData term in terms)
                {
                    TermDocumentCountData termDocumentCountData = GetTermDocumentCount(term.Term);
                    if (termDocumentCountData == null)
                    {
                        termDocumentCountData = new TermDocumentCountData
                        {
                            Term  = term.Term,
                            Count = 1
                        };
                        termDocumentCounts.Add(termDocumentCountData);
                        //coll.Insert(tdcd);
                    }
                    else
                    {
                        termDocumentCountData.Count++;
                        termDocumentCounts.Add(termDocumentCountData);
                        //coll.Update(tdcd);
                    }
                }

                return(PutTermDocumentCounts(termDocumentCounts));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Reduce number for each count in TermDocumentCountColl {term, count}
 /// Delete  {Document, List<TermData>} from  DocumentTermsColl
 /// ?Delete { term, documentId} from TermDocumentColl
 /// 2020-12-23T10:12:38
 /// </summary>
 /// <param name="documentId"></param>
 /// <returns></returns>
 public bool DeleteDocument(string documentId)
 {
     lock (_lockerDocumentTermsColl)
     {
         DocumentTermsData documentTermsData = DocumentTermsColl.FindOne(d => d.Document == documentId);
         if (documentTermsData != null)
         {
             //Reduce number for each count in TermDocumentCountColl {term, count}
             lock (_lockerTermDocumentCountColl)
             {
                 foreach (TermData termData in documentTermsData.Terms)
                 {
                     TermDocumentCountData termDocumentCountData = TermDocumentCountColl.FindOne(d => d.Term == termData.Term);
                     if (termDocumentCountData != null)
                     {
                         termDocumentCountData.Count--;
                         TermDocumentCountColl.Update(termDocumentCountData);
                     }
                 }
                 //Delete  {Document, List<TermData>} from  DocumentTermsColl
                 return(DocumentTermsColl.Delete(documentTermsData.Id));
             }
         }
         return(false);
     }
 }