예제 #1
0
        private void GetPayloads(ICollection <byte[]> payloads, SpanQuery query)
        {
            IDictionary <Term, TermContext> termContexts = new Dictionary <Term, TermContext>();
            var terms = new JCG.SortedSet <Term>();

            query.ExtractTerms(terms);
            foreach (Term term in terms)
            {
                termContexts[term] = TermContext.Build(context, term);
            }
            foreach (AtomicReaderContext atomicReaderContext in context.Leaves)
            {
                Spans spans = query.GetSpans(atomicReaderContext, atomicReaderContext.AtomicReader.LiveDocs, termContexts);
                while (spans.MoveNext() == true)
                {
                    if (spans.IsPayloadAvailable)
                    {
                        var payload = spans.GetPayload();
                        foreach (var bytes in payload)
                        {
                            payloads.Add(bytes);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void  GetPayloads(ICollection <byte[]> payloads, SpanQuery query)
        {
            Spans.Spans spans = query.GetSpans(reader);

            while (spans.Next() == true)
            {
                if (spans.IsPayloadAvailable())
                {
                    ICollection <byte[]> payload = spans.GetPayload();
                    foreach (byte[] bytes in payload)
                    {
                        payloads.Add(bytes);
                    }
                }
            }
        }
예제 #3
0
        public override SpanFilterResult BitSpans(IndexReader reader)
        {
            OpenBitSet bits = new OpenBitSet(reader.MaxDoc);

            Lucene.Net.Search.Spans.Spans         spans = internalQuery.GetSpans(reader);
            IList <SpanFilterResult.PositionInfo> tmp   = new List <SpanFilterResult.PositionInfo>(20);
            int currentDoc = -1;

            SpanFilterResult.PositionInfo currentInfo = null;
            while (spans.Next())
            {
                int doc = spans.Doc();
                bits.Set(doc);
                if (currentDoc != doc)
                {
                    currentInfo = new SpanFilterResult.PositionInfo(doc);
                    tmp.Add(currentInfo);
                    currentDoc = doc;
                }
                currentInfo.AddPosition(spans.Start(), spans.End());
            }
            return(new SpanFilterResult(bits, tmp));
        }
예제 #4
0
 private void GetPayloads(ICollection<sbyte[]> payloads, SpanQuery query)
 {
     IDictionary<Term, TermContext> termContexts = new Dictionary<Term, TermContext>();
     SortedSet<Term> terms = new SortedSet<Term>();
     query.ExtractTerms(terms);
     foreach (Term term in terms)
     {
         termContexts[term] = TermContext.Build(Context, term);
     }
     foreach (AtomicReaderContext atomicReaderContext in Context.Leaves())
     {
         Spans spans = query.GetSpans(atomicReaderContext, ((AtomicReader)atomicReaderContext.Reader()).LiveDocs, termContexts);
         while (spans.Next() == true)
         {
             if (spans.PayloadAvailable)
             {
                 ICollection<sbyte[]> payload = spans.Payload;
                 foreach (sbyte[] bytes in payload)
                 {
                     payloads.Add(bytes);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Fills a <c>Map</c> with <see cref="WeightedSpanTerm"/>s using the terms from the supplied <c>SpanQuery</c>.
        /// </summary>
        /// <param name="terms">Map to place created WeightedSpanTerms in</param>
        /// <param name="spanQuery">SpanQuery to extract Terms from</param>
        private void ExtractWeightedSpanTerms(IDictionary <String, WeightedSpanTerm> terms, SpanQuery spanQuery)
        {
            HashSet <String> fieldNames;

            if (fieldName == null)
            {
                fieldNames = new HashSet <String>();
                CollectSpanQueryFields(spanQuery, fieldNames);
            }
            else
            {
                fieldNames = new HashSet <String>();
                fieldNames.Add(fieldName);
            }
            // To support the use of the default field name
            if (defaultField != null)
            {
                fieldNames.Add(defaultField);
            }

            IDictionary <String, SpanQuery> queries = new HashMap <String, SpanQuery>();

            var  nonWeightedTerms = Support.Compatibility.SetFactory.CreateHashSet <Term>();
            bool mustRewriteQuery = MustRewriteQuery(spanQuery);

            if (mustRewriteQuery)
            {
                foreach (String field in fieldNames)
                {
                    SpanQuery rewrittenQuery = (SpanQuery)spanQuery.Rewrite(GetReaderForField(field));
                    queries[field] = rewrittenQuery;
                    rewrittenQuery.ExtractTerms(nonWeightedTerms);
                }
            }
            else
            {
                spanQuery.ExtractTerms(nonWeightedTerms);
            }

            List <PositionSpan> spanPositions = new List <PositionSpan>();

            foreach (String field in fieldNames)
            {
                IndexReader reader = GetReaderForField(field);
                Spans.Spans spans;
                if (mustRewriteQuery)
                {
                    spans = queries[field].GetSpans(reader);
                }
                else
                {
                    spans = spanQuery.GetSpans(reader);
                }


                // collect span positions
                while (spans.Next())
                {
                    spanPositions.Add(new PositionSpan(spans.Start(), spans.End() - 1));
                }
            }

            if (spanPositions.Count == 0)
            {
                // no spans found
                return;
            }

            foreach (Term queryTerm in nonWeightedTerms)
            {
                if (FieldNameComparator(queryTerm.Field))
                {
                    WeightedSpanTerm weightedSpanTerm = terms[queryTerm.Text];

                    if (weightedSpanTerm == null)
                    {
                        weightedSpanTerm = new WeightedSpanTerm(spanQuery.Boost, queryTerm.Text);
                        weightedSpanTerm.AddPositionSpans(spanPositions);
                        weightedSpanTerm.SetPositionSensitive(true);
                        terms[queryTerm.Text] = weightedSpanTerm;
                    }
                    else
                    {
                        if (spanPositions.Count > 0)
                        {
                            weightedSpanTerm.AddPositionSpans(spanPositions);
                        }
                    }
                }
            }
        }