public void AddObjectToIndex(object obj)
        {
            //TODO: if the obj is a SPListItemInstance, create a document from the list item.
            var objString   = JSONObject.Stringify(this.Engine, obj, null, null);
            var objectToAdd = JObject.Parse(objString);

            var doc = LuceneHelper.ConvertObjectToDocument(objectToAdd);

            try
            {
                m_indexWriter.AddDocument(doc);
            }
            catch (OutOfMemoryException)
            {
                LuceneHelper.CloseIndexWriterSingleton(m_targetFolder);
            }
        }
        public void RemoveFromIndex(object folder, object query)
        {
            if (query == Null.Value || query == Undefined.Value || query == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A query parameter must be specified to indicate the documents to remove from the index. Use '*' to specify all documents.");
            }

            Query lQuery;

            var queryString = query.ToString();
            var queryType   = query.GetType();

            if (queryString == "*")
            {
                lQuery = new MatchAllDocsQuery();
            }
            else if (queryType.IsSubclassOfRawGeneric(typeof(QueryInstance <>)))
            {
                var queryProperty = queryType.GetProperty("Query", BindingFlags.Instance | BindingFlags.Public);
                lQuery = queryProperty.GetValue(query, null) as Query;
            }
            else
            {
                throw new JavaScriptException(this.Engine, "Error", "The query parameter was not a query.");
            }


            try
            {
                m_indexWriter.DeleteDocuments(lQuery);
            }
            catch (OutOfMemoryException)
            {
                LuceneHelper.CloseIndexWriterSingleton(m_targetFolder);
            }
        }
        public void CloseIndexWriter(object folder)
        {
            var targetFolder = GetFolderFromObject(folder);

            LuceneHelper.CloseIndexWriterSingleton(targetFolder);
        }