Converts poco model to lucene document, or converts lucene document to poco model.
A poco model is converted to document with these rules: 1. For simple property (e.g., Int32, String, Decimal) - Create a normal lucene field (or numeric field) 2. For list/set/array property - Create a multi-valued field 3. For dictionary property - Create a field for each key, and the field name format is PropertyName[DictionaryKey] - The dictionary value can be a simple type or a list/set, if it's a list/set, a multi-valued field is created for each key
Exemple #1
0
        public void Index(object model)
        {
            var doc          = ModelConverter.ToDocument(model);
            var keyFieldName = GetKeyFieldName();

            _writer.DeleteDocuments(new Term(keyFieldName, doc.GetField(keyFieldName).StringValue));
            _writer.AddDocument(doc);
        }
Exemple #2
0
        public Pagination Paginate(int pageIndex, int pageSize)
        {
            Sort sort = null;

            if (_sortFields != null && _sortFields.Count > 0)
            {
                sort = new Sort(_sortFields.ToArray());
            }

            TopDocs docs;

            if (sort == null)
            {
                docs = _searcher.Search(_nativeQuery, null, Int32.MaxValue);
            }
            else
            {
                docs = _searcher.Search(_nativeQuery, null, Int32.MaxValue, sort);
            }

            var items = new List <object>();
            var start = pageIndex * pageSize;
            var bound = start + pageSize;

            if (bound > docs.TotalHits)
            {
                bound = docs.TotalHits;
            }

            for (var i = start; i < bound; i++)
            {
                var doc = docs.ScoreDocs[i];
                items.Add(ModelConverter.ToModel(_searcher.Doc(doc.Doc), ModelType));
            }

            return(new Pagination(items, pageIndex, pageSize, docs.TotalHits));
        }