<commit_before>﻿using DotOPDS.Models;
using Lucene.Net.Analysis.Ru;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Version = Lucene.Net.Util.Version;

namespace DotOPDS.Utils
{
    class LuceneIndexStorage : IDisposable
    {
        public const int VERSION = 1;
        private IndexWriter writer;
        private RussianAnalyzer analyzer;
        private SimpleFSDirectory directory;
        private Stopwatch watch;

        public long Time => watch.ElapsedMilliseconds;
        public string Query { get; private set; }

        public string Escape(string s)
        {
            return QueryParser.Escape(s);
        }

        public List<Book> Search(out int count, string query, string field = "", int page = 1)
        {
            var take = Settings.Instance.Pagination;
            var skip = (page - 1) * Settings.Instance.Pagination;
            using (var analyzer = new RussianAnalyzer(Version.LUCENE_30))
            {
                var parser = new QueryParser(Version.LUCENE_30, field, analyzer);
                var q = parser.Parse(query);
                return Search(q, take, skip, out count);
            }
        }<commit_msg>Fixed StopWatch not being initialized.<commit_after>﻿using DotOPDS.Models;
using Lucene.Net.Analysis.Ru;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Version = Lucene.Net.Util.Version;

namespace DotOPDS.Utils
{
    class LuceneIndexStorage : IDisposable
    {
        public const int VERSION = 1;
        private IndexWriter writer;
        private RussianAnalyzer analyzer;
        private SimpleFSDirectory directory;
        private Stopwatch watch = Stopwatch.StartNew();

        public long Time => watch.ElapsedMilliseconds;
        public string Query { get; private set; }

        public string Escape(string s)
        {
            return QueryParser.Escape(s);
        }

        public List<Book> Search(out int count, string query, string field = "", int page = 1)
        {
            var take = Settings.Instance.Pagination;
            var skip = (page - 1) * Settings.Instance.Pagination;
            using (var analyzer = new RussianAnalyzer(Version.LUCENE_30))
            {
                var parser = new QueryParser(Version.LUCENE_30, field, analyzer);
                var q = parser.Parse(query);
                return Search(q, take, skip, out count);
            }
        }
{'fraction_non_alphanumeric': 0.08628158844765343, 'fraction_numerical': 0.005054151624548736, 'mean_word_length': 2.4508094645080947, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6941187', 'n_tokens_mistral': 790, 'n_tokens_neox': 754, 'n_words': 215}