lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] ahmad-devlop opened a new issue #403: How to use HIGH_COMPRESSION in Lucene.Net 4.8
Date Fri, 22 Jan 2021 06:29:00 GMT

ahmad-devlop opened a new issue #403:
URL: https://github.com/apache/lucenenet/issues/403


   I'm trying to compress the index size as much as possible, Any help please? 
   [https://lucenenet.apache.org/docs/4.8.0-beta00013/api/core/Lucene.Net.Codecs.Compressing.CompressionMode.html#Lucene_Net_Codecs_Compressing_CompressionMode_HIGH_COMPRESSION](https://lucenenet.apache.org/docs/4.8.0-beta00013/api/core/Lucene.Net.Codecs.Compressing.CompressionMode.html#Lucene_Net_Codecs_Compressing_CompressionMode_HIGH_COMPRESSION)
   
   ```csharp
   public class LuceneIndexer
       {
           private Analyzer _analyzer = new ArabicAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);
           private string _indexPath;
           private Directory _indexDirectory;
           public IndexWriter _indexWriter;
   
           public LuceneIndexer(string indexPath)
           {
               this._indexPath = indexPath;
               _indexDirectory = new SimpleFSDirectory(new System.IO.DirectoryInfo(_indexPath));
           }
   
           public void BuildCompleteIndex(IEnumerable<Document> documents)
           {
               IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48,
_analyzer) { OpenMode = OpenMode.CREATE_OR_APPEND };
               indexWriterConfig.MaxBufferedDocs = 2;
               indexWriterConfig.RAMBufferSizeMB = 128;
               indexWriterConfig.MaxThreadStates = 2;
   
               _indexWriter = new IndexWriter(_indexDirectory, indexWriterConfig);
   
               _indexWriter.AddDocuments(documents);
   
               _indexWriter.Flush(true, true);
               _indexWriter.Commit();
   
               _indexWriter.Dispose();
           }
   
           
           public IEnumerable<Document> Search(string searchTerm, string searchField,
int limit)
           {
               IndexReader indexReader = DirectoryReader.Open(_indexDirectory);
               var searcher = new IndexSearcher(indexReader);
               var termQuery = new TermQuery(new Term(searchField, searchTerm)); // Lucene.Net.Util.LuceneVersion.LUCENE_48,
searchField, _analyzer
               var hits = searcher.Search(termQuery, limit).ScoreDocs;
   
               var documents = new List<Document>();
               foreach (var hit in hits)
               {
                   documents.Add(searcher.Doc(hit.Doc));
               }
   
               _analyzer.Dispose();
               return documents;
           }
   
       }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message