public static Document ToDocument(this IXDescriptor descriptor, string uniqueIdentifierField) { Document doc = new Document(); bool uq = false; foreach (IXDescriptorProperty p in descriptor.Properties) { if ((p.Flags & FieldFlags.UNIQUEID) == FieldFlags.UNIQUEID) { if (uq) { throw new InvalidOperationException("UNIQUEID not found"); } else { doc.Add(new Field(uniqueIdentifierField, p.Name, Field.Store.YES, Field.Index.NOT_ANALYZED )); uq = true; } } doc.Add(p.ToField()); } return(doc); }
public IndexerSetupResult Setup(IXDescriptor descriptor) { if (setup) { return(IndexerSetupResult.Failure); } hashFactory = new System.Security.Cryptography.SHA256Managed(); string _v = Convert.ToBase64String(hashFactory.ComputeHash(System.Text.UTF8Encoding.UTF8.GetBytes(descriptor.ToString()))); int df = indexSearcher.DocFreq(new Term(indexerDocumentDescriptorVersion, _v)); // set up searcher TermDocs term = indexSearcher.IndexReader.TermDocs(); List <Document> docs = new List <Document>(); while (term.Next()) { docs.Add(indexSearcher.Doc(term.Doc)); } return(IndexerSetupResult.Okay); }
/// <summary> /// add/update an item to the index /// </summary> /// <param name="dataItem"></param> /// <param name="waitForIndex"></param> /// <returns></returns> public bool AddUpdateLuceneIndex(IXDescriptor dataItem, bool waitForIndex = false) { return(AddUpdateLuceneIndex(new IXDescriptor[] { dataItem }, waitForIndex)); }