public SingleFieldSearchResult SingleFieldSearch(string fieldName, string query, string directoryPath)
        {
            // Create the index reader
            var directory   = _directoryFactory.GetDirectory(directoryPath);
            var indexReader = _indexReaderFactorty.GetIndexReader(directory);

            // create a index searcher
            var searcher = _indexSearcherFactory.GetIndexSearcher(indexReader);

            // Create the query to be executed
            var contentQuery = _singleFieldQueryFactory.GetSingleFieldQuery(fieldName,
                                                                            query,
                                                                            _analyzerFactory.GetAnalyzer());

            // Execute the query.
            var results = _simpleQueryExecutor.ExecuteQuery(contentQuery, searcher, indexReader);

            // Create the SingleFieldSearchResul wrapper and return it as the result of the search
            var resultWrapper = new SingleFieldSearchResult(searcher)
            {
                TopDocs = results
            };

            return(resultWrapper);
        }
Example #2
0
        /// <summary>
        /// Build a basic index writer for the index located at the given index path.
        /// </summary>
        /// <param name="indexDirectoryPath">The directory of the index.</param>
        /// <returns>Default <see cref="IndexWriter"/> object </returns>
        private IndexWriter BuildIndexWriter(string indexDirectoryPath)
        {
            // the index directoryFactory
            var fsDirectory = _directoryFactory.GetDirectory(indexDirectoryPath);

            // the index analyzer
            var baseAnalyzer = _analyzerFactory.GetAnalyzer();

            // the actual index writter
            var indexWriter = _indexWriterFactory.BuildIndexWritter(fsDirectory, baseAnalyzer);

            return(indexWriter);
        }