예제 #1
0
        public override int NextBatchId(string processName) {
            if (!TflBatchRecordsExist(processName)) {
                return 1;
            }
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(processName))) {

                var query = new TermQuery(new Term("process", processName));
                var sort = new Sort(new SortField("id", SortField.INT, true));
                var hits = searcher.Search(query, null, 1, sort);

                if (hits.TotalHits <= 0)
                    return 1;

                var doc = searcher.Doc(0);
                return Convert.ToInt32(doc.GetField("id").StringValue) + 1;
            }
        }
예제 #2
0
        public override void LoadEndVersion(Entity entity)
        {
            using (var searcher = LuceneSearcherFactory.Create(this, entity)) {
                var query    = new MatchAllDocsQuery();
                var sortType = LuceneWriter.SortMap.ContainsKey(entity.Version.SimpleType) ? LuceneWriter.SortMap[entity.Version.SimpleType] : LuceneWriter.SortMap["*"];
                var sort     = new Sort(new SortField(entity.Version.Alias, sortType, true));
                var hits     = searcher.Search(query, null, 1, sort);

                entity.HasRows = hits.TotalHits > 0;

                if (!entity.HasRows)
                {
                    return;
                }

                var doc = searcher.Doc(0);
                entity.End = Common.GetObjectConversionMap()[entity.Version.SimpleType](doc.Get(entity.Version.Alias));
            }
        }
예제 #3
0
        public override void LoadBeginVersion(Entity entity)
        {
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(entity.ProcessName))) {
                var parser = new MultiFieldQueryParser(LuceneVersion(), new[] { "process", "entity" }, new KeywordAnalyzer());
                var query  = parser.Parse(string.Format("process:\"{0}\" AND entity:\"{1}\"", entity.ProcessName, entity.Alias));
                var sort   = new Sort(new SortField("id", SortField.INT, true));
                var hits   = searcher.Search(query, null, 1, sort);

                entity.HasRange = hits.TotalHits > 0;

                if (!entity.HasRange)
                {
                    return;
                }

                var doc  = searcher.Doc(0);
                var type = doc.GetField("version_type").StringValue;
                entity.Begin = Common.GetObjectConversionMap()[type](doc.GetField("version").StringValue);
            }
        }
예제 #4
0
        public override int NextBatchId(string processName)
        {
            if (!TflBatchRecordsExist(processName))
            {
                return(1);
            }
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(processName))) {
                var query = new TermQuery(new Term("process", processName));
                var sort  = new Sort(new SortField("id", SortField.INT, true));
                var hits  = searcher.Search(query, null, 1, sort);

                if (hits.TotalHits <= 0)
                {
                    return(1);
                }

                var doc = searcher.Doc(0);
                return(Convert.ToInt32(doc.GetField("id").StringValue) + 1);
            }
        }
		/// <summary> A search implementation allowing sorting which spans a new thread for each
		/// Searchable, waits for each search to complete and merges
		/// the results back together.
		/// </summary>
		public override TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort)
		{
            if (sort == null) throw new ArgumentNullException("sort");

		    FieldDocSortedHitQueue hq = new FieldDocSortedHitQueue(nDocs);
            object lockObj = new object();

            Task<TopFieldDocs>[] tasks = new Task<TopFieldDocs>[searchables.Length];
            for (int i = 0; i < searchables.Length; i++) // search each searchable
            {
                int cur = i;
                tasks[i] =
                    Task<TopFieldDocs>.Factory.StartNew(
                        () => MultiSearcherCallableWithSort(ThreadLock.MonitorLock, lockObj, searchables[cur], weight, filter, nDocs, hq, sort, cur,
                                                      starts));
            }

		    int totalHits = 0;
		    float maxScore = float.NegativeInfinity;

            Task.WaitAll(tasks);
            foreach (TopFieldDocs topFieldDocs in tasks.Select(x => x.Result))
            {
                totalHits += topFieldDocs.TotalHits;
                maxScore = Math.Max(maxScore, topFieldDocs.MaxScore);
            }

            ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
            for (int i = hq.Size() - 1; i >= 0; i--)
                scoreDocs[i] = hq.Pop();

		    return new TopFieldDocs(totalHits, scoreDocs, hq.GetFields(), maxScore);
		}
예제 #6
0
		/// <summary>Search implementation with arbitrary sorting.  Finds
		/// the top <c>n</c> hits for <c>query</c>, applying
		/// <c>filter</c> if non-null, and sorting the hits by the criteria in
		/// <c>sort</c>.
		/// 
		/// <p/>NOTE: this does not compute scores by default; use
		/// <see cref="IndexSearcher.SetDefaultFieldSortScoring(bool,bool)" /> to enable scoring.
		/// 
		/// </summary>
		/// <throws>  BooleanQuery.TooManyClauses </throws>
		public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
		{
			return Search(CreateWeight(query), filter, n, sort);
		}
예제 #7
0
		public abstract TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);
예제 #8
0
        public override void LoadBeginVersion(Entity entity) {
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(entity.ProcessName))) {

                var parser = new MultiFieldQueryParser(LuceneVersion(), new[] { "process", "entity" }, new KeywordAnalyzer());
                var query = parser.Parse(string.Format("process:\"{0}\" AND entity:\"{1}\"", entity.ProcessName, entity.Alias));
                var sort = new Sort(new SortField("id", SortField.INT, true));
                var hits = searcher.Search(query, null, 1, sort);

                entity.HasRange = hits.TotalHits > 0;

                if (!entity.HasRange)
                    return;

                var doc = searcher.Doc(0);
                var type = doc.GetField("version_type").StringValue;
                entity.Begin = Common.GetObjectConversionMap()[type](doc.GetField("version").StringValue);
            }
        }
예제 #9
0
        public override void LoadEndVersion(Entity entity) {
            using (var searcher = LuceneSearcherFactory.Create(this, entity)) {
                var query = new MatchAllDocsQuery();
                var sortType = LuceneWriter.SortMap.ContainsKey(entity.Version.SimpleType) ? LuceneWriter.SortMap[entity.Version.SimpleType] : LuceneWriter.SortMap["*"];
                var sort = new Sort(new SortField(entity.Version.Alias, sortType, true));
                var hits = searcher.Search(query, null, 1, sort);

                entity.HasRows = hits.TotalHits > 0;

                if (!entity.HasRows)
                    return;

                var doc = searcher.Doc(0);
                entity.End = Common.GetObjectConversionMap()[entity.Version.SimpleType](doc.Get(entity.Version.Alias));
            }
        }
예제 #10
0
		/// <summary> Just like <see cref="Search(Weight, Filter, int, Sort)" />, but you choose
		/// whether or not the fields in the returned <see cref="FieldDoc" /> instances
		/// should be set by specifying fillFields.
		/// <p/>
		/// NOTE: this does not compute scores by default. If you need scores, create
		/// a <see cref="TopFieldCollector" /> instance by calling
		/// <see cref="TopFieldCollector.Create" /> and then pass that to
		/// <see cref="Search(Weight, Filter, Collector)" />.
		/// <p/>
		/// </summary>
		public virtual TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort, bool fillFields)
		{
            nDocs = Math.Min(nDocs, reader.MaxDoc);

			TopFieldCollector collector2 = TopFieldCollector.Create(sort, nDocs, fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.GetScoresDocsOutOfOrder());
			Search(weight, filter, collector2);
			return (TopFieldDocs) collector2.TopDocs();
		}
예제 #11
0
		public override TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort)
		{
			return Search(weight, filter, nDocs, sort, true);
		}
예제 #12
0
		static Sort()
		{
			INDEXORDER = new Sort(SortField.FIELD_DOC);
		}
예제 #13
0
		public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
		{
			var hq = new FieldDocSortedHitQueue(n);
			int totalHits = 0;
			
			float maxScore = System.Single.NegativeInfinity;

		    var lockObj = new object();
			for (int i = 0; i < searchables.Length; i++)
			{
				// search each searcher
                // use NullLock, we don't care about synchronization for these
                TopFieldDocs docs = MultiSearcherCallableWithSort(ThreadLock.NullLock, lockObj, searchables[i], weight, filter, n, hq, sort,
			                                          i, starts);
			    totalHits += docs.TotalHits;
				maxScore = System.Math.Max(maxScore, docs.MaxScore);
			}
			
			ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()];
			for (int i = hq.Size() - 1; i >= 0; i--)
			// put docs in array
				scoreDocs2[i] = hq.Pop();
			
			return new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields(), maxScore);
		}
예제 #14
0
			public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
			{
				throw new System.NotSupportedException();
			}