CreateDocumentFromFields() private static method

private static CreateDocumentFromFields ( Lucene.Net.Documents.Document document, IEnumerable fieldsToFetch ) : RavenJObject
document Lucene.Net.Documents.Document
fieldsToFetch IEnumerable
return RavenJObject
示例#1
0
        private JsonDocument[] GetJsonDocuments(MoreLikeThisQuery parameters, IndexSearcher searcher, Index index, string indexName, IEnumerable <ScoreDoc> hits, int baseDocId)
        {
            if (string.IsNullOrEmpty(parameters.DocumentId) == false)
            {
                var documentIds = hits
                                  .Where(hit => hit.Doc != baseDocId)
                                  .Select(hit => searcher.Doc(hit.Doc).Get(Constants.DocumentIdFieldName))
                                  .Where(x => x != null)
                                  .Distinct();

                return(documentIds
                       .Select(docId => database.Documents.Get(docId, null))
                       .Where(it => it != null)
                       .ToArray());
            }

            var fields = searcher.Doc(baseDocId).GetFields().Cast <AbstractField>().Select(x => x.Name).Distinct().ToArray();
            var etag   = database.Indexes.GetIndexEtag(indexName, null);

            return(hits
                   .Where(hit => hit.Doc != baseDocId)
                   .Select(hit => new JsonDocument
            {
                DataAsJson = Index.CreateDocumentFromFields(searcher.Doc(hit.Doc),
                                                            new FieldsToFetch(fields, false, index.IsMapReduce ? Constants.ReduceKeyFieldName : Constants.DocumentIdFieldName)),
                Etag = etag
            })
                   .ToArray());
        }
        private IEnumerable <JsonDocument> GetJsonDocuments(MoreLikeThisQueryParameters parameters, IndexSearcher searcher, string index, IEnumerable <ScoreDoc> hits, int baseDocId)
        {
            if (string.IsNullOrEmpty(parameters.DocumentId) == false)
            {
                var documentIds = hits
                                  .Where(hit => hit.doc != baseDocId)
                                  .Select(hit => searcher.Doc(hit.doc).Get(Constants.DocumentIdFieldName))
                                  .Where(x => x != null)
                                  .Distinct();

                return(documentIds
                       .Select(docId => Database.Get(docId, null))
                       .Where(it => it != null)
                       .ToArray());
            }

            var fields = searcher.Doc(baseDocId).GetFields().Cast <AbstractField>().Select(x => x.Name()).Distinct().ToArray();
            var etag   = Database.GetIndexEtag(index, null);

            return(hits
                   .Where(hit => hit.doc != baseDocId)
                   .Select(hit => new JsonDocument
            {
                DataAsJson = Index.CreateDocumentFromFields(searcher.Doc(hit.doc), fields),
                Etag = etag
            })
                   .ToArray());
        }
示例#3
0
        private JsonDocument[] GetJsonDocuments(IndexSearcher searcher, Index index, string indexName, ScoreDoc[] scoreDocs)
        {
            if (scoreDocs.Any())
            {
                // Since we don't have a document we get the fields from the first hit
                var fields = searcher.Doc(scoreDocs.First().Doc).GetFields().Cast <AbstractField>().Select(x => x.Name).Distinct().ToArray();
                var etag   = database.Indexes.GetIndexEtag(indexName, null);
                return(scoreDocs
                       .Select(hit => new JsonDocument
                {
                    DataAsJson = Index.CreateDocumentFromFields(searcher.Doc(hit.Doc),
                                                                new FieldsToFetch(fields, false, index.IsMapReduce ? Constants.ReduceKeyFieldName : Constants.DocumentIdFieldName)),
                    Etag = etag
                })
                       .ToArray());
            }

            return(new JsonDocument[0]);
        }