Esempio n. 1
0
        public int Count(NuixLogRepo repo, string queryString)
        {
            // Lucene seems to be picky about lower case for some things?
            Regex notFix = new Regex(@"\bnot\b", RegexOptions.Compiled);

            queryString = notFix.Replace(queryString, "NOT");

            // Blank query means all items
            if (string.IsNullOrWhiteSpace(queryString))
            {
                return((int)repo.Database.TotalRecords);
            }
            else
            {
                luceneDirectory = FSDirectory.Open(IndexDirectory);
                analyzer        = getAnalyzer();
                IndexSearcher searcher = new IndexSearcher(luceneDirectory);

                Query query = parseQuery(queryString);

                var hitsFound = searcher.Search(query, int.MaxValue);
                int hitCount  = hitsFound.TotalHits;

                luceneDirectory.Dispose();
                searcher.Dispose();
                analyzer.Dispose();

                return(hitCount);
            }
        }
Esempio n. 2
0
        public IList <long> Search(NuixLogRepo repo, string queryString)
        {
            // Lucene seems to be picky about lower case for some things?
            Regex notFix = new Regex(@"\bnot\b", RegexOptions.Compiled);

            queryString = notFix.Replace(queryString, "NOT");

            // Emtpy query is all items, we return a special collection that pretends to be a full list of ID values
            // but that is actually just based on the range of possible values.
            if (string.IsNullOrWhiteSpace(queryString))
            {
                return(new AllEntriesIDList((int)repo.Database.TotalRecords));
            }
            else
            {
                luceneDirectory = FSDirectory.Open(IndexDirectory);
                analyzer        = getAnalyzer();
                IndexSearcher searcher = new IndexSearcher(luceneDirectory);
                Query         query    = parseQuery(queryString);

                var hitsFound = searcher.Search(query, int.MaxValue);

                long[] ids = new long[hitsFound.TotalHits];
                for (int i = 0; i < hitsFound.TotalHits; i++)
                {
                    Document doc = searcher.Doc(hitsFound.ScoreDocs[i].Doc);
                    ids[i] = long.Parse(doc.Get("id"));
                }
                luceneDirectory.Dispose();
                searcher.Dispose();
                analyzer.Dispose();

                return(ids);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Ends InWriteMode after closing Lucene index writing related objects.
 /// </summary>
 public void EndWrite()
 {
     writer.Flush(true, true, true);
     writer.Optimize(true);
     writer.Dispose();
     luceneDirectory.Dispose();
     analyzer.Dispose();
     InWriteMode = false;
 }
Esempio n. 4
0
        public static (Analyzer analyzer, IDisposable disposable) Create(
            string defaultAnalyzer,
            IDictionary <string, string> fieldAnalyzers)
        {
            var analyzers = new ConcurrentDictionary <string, Analyzer>();
            Func <string, Analyzer> getAnalyzer = name => analyzers.GetOrAdd(name, n => s_analyzerMap[n]());
            var      perFieldAnalyzers          = fieldAnalyzers.ToDictionary(x => x.Key, x => getAnalyzer(x.Value));
            Analyzer analyzer = new PerFieldAnalyzerWrapper(
                getAnalyzer(defaultAnalyzer),
                perFieldAnalyzers);
            IDisposable disposable = new DelegateDisposable(() =>
            {
                analyzer.Dispose();
                foreach (var a in analyzers.Values)
                {
                    a.Dispose();
                }
            });

            return(analyzer, disposable);
        }