コード例 #1
0
        /// <summary>
        /// Updates the specified object in the IndexWriter.
        /// </summary>
        /// <typeparam name="T">
        /// The type of the object to update.
        /// </typeparam>
        /// <param name="writer">
        /// The IndexWriter to update the object in.
        /// </param>
        /// <param name="obj">
        /// The new object to write.
        /// </param>
        /// <param name="kind">
        /// The kind of type to restrict the update operation to.
        /// </param>
        /// <param name="settings">
        /// The MappingSettings to use when creating the Document to add to the index.
        /// </param>
        /// <param name="selection">
        /// The Query which selects the item in the index.
        /// </param>
        /// <param name="analyzer">
        /// The Analyzer to use.
        /// </param>
        public static void Update <T>(this IndexWriter writer, T obj, DocumentObjectTypeKind kind, MappingSettings settings, Query selection, Analyzer analyzer)
        {
            if (null == writer)
            {
                throw new ArgumentNullException("writer");
            }
            else if (null == obj)
            {
                throw new ArgumentNullException("obj");
            }
            else if (null == settings)
            {
                throw new ArgumentNullException("settings");
            }
            else if (null == selection)
            {
                throw new ArgumentNullException("selection");
            }
            else if (null == analyzer)
            {
                throw new ArgumentNullException("analyzer");
            }

            writer.DeleteDocuments <T>(kind, selection);
            writer.AddDocument(obj.ToDocument <T>(settings), analyzer);
        }
コード例 #2
0
ファイル: ObjectMapping.cs プロジェクト: adwaitya/LogR
        /// <summary>
        /// Gets a Filter to restrict results to documents that are mapped from objects of the given type.
        /// </summary>
        /// <param name="type">
        /// The Type to get the filter for.
        /// </param>
        /// <param name="kind">
        /// The kind of type to restrict the filter on.
        /// </param>
        /// <returns>
        /// An instance of Filter.
        /// </returns>
        public static Filter GetTypeFilter(Type type, DocumentObjectTypeKind kind)
        {
            switch (kind)
            {
            case DocumentObjectTypeKind.Actual:
                return(new TermsFilter(new Term(Documents.ObjectMappingExtensions.FieldActualType, Utils.GetTypeName(type))));

            case DocumentObjectTypeKind.Static:
                return(new TermsFilter(new Term(Documents.ObjectMappingExtensions.FieldStaticType, Utils.GetTypeName(type))));

            default:
                Debug.Fail("Unsupported DocumentObjectType: " + kind);
                throw new NotSupportedException(String.Format("The DocumentObjectType '{0}' is not supported.", kind));
            }
        }
コード例 #3
0
 /// <summary>
 /// Gets a Filter to restrict results to documents that are mapped from objects of the given type.
 /// </summary>
 /// <typeparam name="T">
 /// The Type to get the filter for.
 /// </typeparam>
 /// <param name="kind">
 /// The kind of type to restrict the filter on.
 /// </param>
 /// <returns>
 /// An instance of Filter.
 /// </returns>
 public static Filter GetTypeFilter <T>(DocumentObjectTypeKind kind)
 {
     return(GetTypeFilter(typeof(T), kind));
 }
コード例 #4
0
        /// <summary>
        /// Deletes the documents for objects of the given type matching the given selection.
        /// </summary>
        /// <typeparam name="TObject">
        /// The type of the object to delete documents for.
        /// </typeparam>
        /// <param name="writer">
        /// The IndexWriter to delete the documents from.
        /// </param>
        /// <param name="kind">
        /// The kind of type to restrict the search to.
        /// </param>
        /// <param name="selection">
        /// The Query which selects the documents to delete.
        /// </param>
        public static void DeleteDocuments <TObject>(this IndexWriter writer, DocumentObjectTypeKind kind, Query selection)
        {
            Query deleteQuery = new FilteredQuery(selection, ObjectMapping.GetTypeFilter <TObject>(kind));

            writer.DeleteDocuments(deleteQuery);
        }
コード例 #5
0
 /// <summary>
 /// Updates the specified object in the IndexWriter.
 /// </summary>
 /// <typeparam name="T">
 /// The type of the object to update.
 /// </typeparam>
 /// <param name="writer">
 /// The IndexWriter to update the object in.
 /// </param>
 /// <param name="obj">
 /// The new object to write.
 /// </param>
 /// <param name="kind">
 /// The kind of type to restrict the update operation to.
 /// </param>
 /// <param name="selection">
 /// The Query which selects the item in the index.
 /// </param>
 /// <param name="analyzer">
 /// The Analyzer to use.
 /// </param>
 public static void Update <T>(this IndexWriter writer, T obj, DocumentObjectTypeKind kind, Query selection, Analyzer analyzer)
 {
     Update <T>(writer, obj, kind, MappingSettings.Default, selection, analyzer);
 }
コード例 #6
0
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query.
 /// </summary>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="type">
 /// The type of the object to search documents for.
 /// </param>
 /// <param name="kind">
 /// The kind of type to restrict the search to.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="numResults">
 /// The number of results to return.
 /// </param>
 /// <returns>
 /// An instance of TopDocs.
 /// </returns>
 public static TopDocs Search(this Searcher searcher, Type type, DocumentObjectTypeKind kind, Query query, int numResults)
 {
     return(searcher.Search(query, ObjectMapping.GetTypeFilter(type, kind), numResults));
 }
コード例 #7
0
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query and Collector.
 /// </summary>
 /// <typeparam name="TObject">
 /// The type of the object to search documents for.
 /// </typeparam>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="kind">
 /// The kind of type to restrict the search to.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="results">
 /// The Collector to use to gather results.
 /// </param>
 public static void Search <TObject>(this Searcher searcher, DocumentObjectTypeKind kind, Query query, Collector results)
 {
     searcher.Search(query, ObjectMapping.GetTypeFilter <TObject>(kind), results);
 }
コード例 #8
0
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query.
 /// </summary>
 /// <typeparam name="TObject">
 /// The type of the object to search documents for.
 /// </typeparam>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="kind">
 /// The kind of type to restrict the search to.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="numResults">
 /// The number of results to return.
 /// </param>
 /// <param name="sort">
 /// A Sort object that defines how to sort the results.
 /// </param>
 /// <returns>
 /// An instance of TopDocs.
 /// </returns>
 public static TopDocs Search <TObject>(this Searcher searcher, DocumentObjectTypeKind kind, Query query, int numResults, Sort sort)
 {
     return(searcher.Search(query, ObjectMapping.GetTypeFilter <TObject>(kind), numResults, sort));
 }
コード例 #9
0
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query and Collector.
 /// </summary>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="type">
 /// The type of the object to search documents for.
 /// </param>
 /// <param name="kind">
 /// The kind of type to restrict the search to.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="results">
 /// The Collector to use to gather results.
 /// </param>
 public static void Search(this IndexSearcher searcher, Type type, DocumentObjectTypeKind kind, Query query, ICollector results)
 {
     searcher.Search(query, ObjectMapping.GetTypeFilter(type, kind), results);
 }