Created
May 26, 2017 06:38
-
-
Save jackinf/f88097ae7bbfb02bb1f5f6ac370828bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using ETIS.Core.Documents; | |
using ETIS.Core.Documents.Classifiers; | |
using ETIS.Core.Extensions; | |
using ETIS.Core.Indexes.Infrastructure; | |
using ETIS.RavenBundle; | |
using Lucene.Net.Analysis; | |
using Raven.Abstractions.Indexing; | |
using Raven.Client; | |
using Raven.Client.Indexes; | |
using Raven.Client.Linq; | |
using Raven.Database.Indexing; | |
using ETIS.Core.Views; | |
using ETIS.Resources; | |
using ETIS.Core.Indexes.DocumentSearchIndexes.InfoInterfaces; | |
namespace ETIS.Core.Indexes.DocumentSearchIndexes.Project | |
{ | |
/// <summary> | |
/// Et testid läbiksid, siis tuleb lisada registrisse: | |
/// reg add HKLM\SOFTWARE\Microsoft\.NETFramework /v useLegacyJit /t REG_DWORD /d 1 | |
/// </summary> | |
public class ProjectSearchIndex : AbstractIndexCreationTask<ProjectDocument, ProjectSearchIndex.Info>, | |
IEtisDocumentIndex<ProjectDocument, ProjectSearchIndex.Info> | |
{ | |
public const string Active = "a"; | |
public const string Passive = "p"; | |
public const string Archived = "x"; | |
public ProjectSearchIndex() | |
{ | |
Map = docs => | |
from doc in docs | |
where doc.General != null | |
let frascatis = doc.General.ResearchAreas | |
.Where(r => r.AreaOfStudyFrascati != null && r.AreaOfStudyFrascati.View != null) | |
.Select(r => r.AreaOfStudyFrascati.View) | |
let cercses = doc.General.ResearchAreas | |
.Select(r => new | |
{ | |
r.AreaOfStudyCercs.View.Code, | |
r.AreaOfStudyCercs.View.Name, | |
r.AreaOfStudyCercs.View.NameEng, | |
r.AreaOfStudyCercs.View.FullPath | |
}) | |
let reasearchAreas = doc.General.ResearchAreas | |
.Select(r => new | |
{ | |
r.AreaOfStudy.View.Code, | |
r.AreaOfStudy.View.Name, | |
r.AreaOfStudy.View.NameEng, | |
r.AreaOfStudy.View.FullPath | |
}) | |
let aosChildren = doc.General.ResearchAreas | |
.Select(r => r.AreaOfStudyChild.View) | |
let aosWithChildren = doc.General.ResearchAreas | |
.SelectMany(r => new[] {r.AreaOfStudy, r.AreaOfStudyChild}) | |
.Where(x => x != null) | |
let programmes = doc.General.ProgrammeInfo.Programmes | |
let responsibleExecutor = doc.General.ResponsibleExecutor.View | |
let roles = doc.Persons.AllExecutors | |
.Select(x => x.RoleReference) | |
.Where(x => x != null) | |
let executorRoleId = | |
roles.Any(r => r.View.Code == PersonRoleInProject.executor) | |
? roles.First(r => r.View.Code == PersonRoleInProject.executor).Id.ToString().Split('/').Last() | |
: null | |
let mainRoleId = | |
roles.Any(r => r.View.Code == PersonRoleInProject.main) | |
? roles.First(r => r.View.Code == PersonRoleInProject.main).Id.ToString().Split('/').Last() | |
: null | |
let responsibleRoleId = | |
roles.Any(r => r.View.Code == PersonRoleInProject.responsible) | |
? roles.First(r => r.View.Code == PersonRoleInProject.responsible) | |
.Id.ToString() | |
.Split('/') | |
.Last() | |
: null | |
let supervisorRoleId = | |
roles.Any(r => r.View.Code == PersonRoleInProject.supervisor) | |
? roles.First(r => r.View.Code == PersonRoleInProject.supervisor) | |
.Id.ToString() | |
.Split('/') | |
.Last() | |
: null | |
let allExecutors = | |
doc.Persons.AllExecutors.Select( | |
x => new {Person = x.Person.View, RoleId = x.RoleReference.Id, Id = x.Person.Id}) | |
let allExecutorDocs = allExecutors.Select(x => x.Person) | |
let executors = allExecutors.Where(x => executorRoleId == x.RoleId.ToString()).Select(x => x.Person) | |
let mainExecutors = allExecutors.Where(x => mainRoleId == x.RoleId.ToString()).Select(x => x.Person) | |
let responsibleExecutors = | |
allExecutors.Where(x => responsibleRoleId == x.RoleId.ToString()).Select(x => x.Person) | |
let scienceInstitutionsWithRole = doc.General.ScienceInstitutions.Select(x => | |
new | |
{ | |
InstitutionView = x.Institution.View, | |
Role = x.Role.View | |
} | |
) | |
let scienceInstitutions = doc.General.ScienceInstitutions | |
.Where(x => x.Institution != null) | |
.Select(x => x.Institution.View) | |
let financingInstitutions = doc.General.FinancingInstitutions | |
.Where(x => x.Institution != null) | |
.Select(x => x.Institution.View) | |
let allInstitutions = scienceInstitutions.Union(financingInstitutions) | |
let firstProgramme = programmes != null ? programmes.FirstOrDefault() : null | |
let interruptionPeriods = doc.General.InterruptionInPeriods.OrderBy(x => x.Id) | |
select new Info | |
{ | |
_ = false, | |
IndexId = doc.Id.ToString(), | |
IsActive = doc.IsActive, | |
IsPublic = doc.IsPublic, | |
ProgrammeIds = programmes.Select(x => x.Id), | |
ProgrammeNames = programmes.Select(x => x.View.Name), | |
ProgrammeCodes = programmes.Select(x => x.View.Code), | |
TaProjectNr = doc.General.TaProjectNr, | |
FinancierProjectNr = doc.General.FinancierProjectNr, | |
TaProjectNrAndFinancierProjectNr = | |
DocumentExtension.TaProjectNrAndFinancierProjectNr(doc.General.TaProjectNr, | |
doc.General.FinancierProjectNr), | |
ProjectDocumentType = doc.ProjectDocumentType, | |
Name = doc.Name, | |
ResponsibleExecutorName = responsibleExecutor != null | |
? responsibleExecutor.LastName + ", " + | |
responsibleExecutor.FirstName | |
: string.Empty, | |
ResponsibleExecutorBirthday = responsibleExecutor != null ? responsibleExecutor.BirthDay : null, | |
ResponsibleExecutorAgeDuringProjectStart = doc.General.StartDate.Value.Year - | |
responsibleExecutor.BirthDay.Value.Year, | |
ResponsibleExecutorSex = responsibleExecutor != null ? responsibleExecutor.Sex : Sex.NotSelected, | |
InstitutionFullNames = | |
scienceInstitutions != null ? scienceInstitutions.Select(x => x.FullName) : null, | |
InstitutionFullNamesEng = | |
scienceInstitutions != null ? scienceInstitutions.Select(x => x.FullNameEng) : null, | |
InstitutionFullPaths = | |
scienceInstitutions != null ? scienceInstitutions.Select(x => x.FullPath) : null, | |
ScienceInstitutionIds = | |
doc.General.ScienceInstitutions != null | |
? doc.General.ScienceInstitutions.Select(x => x.Institution.Id) | |
: new List<Guid>(), | |
CoordinatorInstitutionNames = scienceInstitutionsWithRole != null | |
? scienceInstitutionsWithRole.Where( | |
x => x.Role.Code == InsitutionRoleInProjectStatic.coord) | |
.Select(x => x.InstitutionView.FullName) | |
: new List<string>(), | |
PartnerInstitutionNames = scienceInstitutionsWithRole != null | |
? scienceInstitutionsWithRole.Where( | |
x => x.Role.Code == InsitutionRoleInProjectStatic.partner) | |
.Select(x => x.InstitutionView.FullName) | |
: new List<string>(), | |
FinancingInstitutionNames = financingInstitutions != null | |
? financingInstitutions.Select(x => x.FullName) | |
: new List<string>(), | |
FinancingInstitutionFullPaths = | |
financingInstitutions != null ? financingInstitutions.Select(x => x.FullPath) : null, | |
StartDate = doc.General.StartDate, | |
StartDateShortDateFormat = DateTimeExtension.ToDateDisplay(doc.General.StartDate), | |
StartYear = doc.General.StartDate != null ? doc.General.StartDate.Value.Year : 0, | |
EndDate = doc.General.EndDate, | |
EndDateShortDateFormat = DateTimeExtension.ToDateDisplay(doc.General.EndDate), | |
EndYear = doc.General.EndDate != null ? doc.General.EndDate.Value.Year : 0, | |
Title = doc.TitleEst, | |
TitleEng = doc.TitleEng, | |
TitleOrig = doc.TitleOrig, | |
AreaOfStudyIds = doc.General.ResearchAreas != null | |
? doc.General.ResearchAreas | |
.Where(x => x.IsActive && x.AreaOfStudy != null) | |
.Select(x => x.AreaOfStudy.Id.ToString()) | |
: new List<string>(), | |
AreaOfStudyChildIds = doc.General.ResearchAreas != null | |
? doc.General.ResearchAreas | |
.Where(x => x.IsActive &&x.AreaOfStudyChild != null) | |
.Select(x => x.AreaOfStudyChild.Id.ToString()) | |
: new List<string>(), | |
AreaOfStudyCercsIds = doc.General.ResearchAreas != null | |
? doc.General.ResearchAreas | |
.Where(x => x.IsActive && x.AreaOfStudyCercs != null) | |
.Select(x => x.AreaOfStudyCercs.Id.ToString()) | |
.Concat(doc.General.ResearchAreas.Where(x => x.AreaOfStudyCercs != null) | |
.Select(x => x.AreaOfStudyCercs.View.FullPath)).Distinct() | |
: new List<string>(), | |
AreaOfStudyFrascatiIds = doc.General.ResearchAreas != null | |
? doc.General.ResearchAreas | |
.Where(x => x.IsActive && x.AreaOfStudyFrascati != null) | |
.Select(x => x.AreaOfStudyFrascati.Id.ToString()) | |
.Concat(doc.General.ResearchAreas.Where(x => x.AreaOfStudyFrascati != null && x.AreaOfStudyFrascati.View.IsActive) | |
.Select(x => x.AreaOfStudyFrascati.View.FullPath)) | |
.Distinct() | |
: new List<string>(), | |
AreaOfStudyFrascatiIdsWithStatus = doc.General.ResearchAreas != null | |
? doc.General.ResearchAreas | |
.Where(x => x.AreaOfStudyFrascati != null) | |
.Select(x => | |
x.AreaOfStudyFrascati.View.IsPassive | |
? Passive + "|" + x.AreaOfStudyFrascati.Id | |
: x.AreaOfStudyFrascati.View.IsActive | |
? Active + "|" + x.AreaOfStudyFrascati.Id | |
: Archived + "|" + x.AreaOfStudyFrascati.Id) | |
: new List<string>(), | |
AmountFromFinancier = doc.General.AmountFromFinancier, | |
FinancingInPeriodsTotalDisplay = | |
doc.General.FinancingInPeriodsTotal != null | |
? CurrencyExtension.CurrencyToDisplay( | |
doc.General.FinancingInPeriodsTotal.Type == CurrencyType.EEK, | |
doc.General.FinancingInPeriodsTotal.Value.GetValueOrDefault(0)) | |
: string.Empty, | |
FinancingInPeriodsTotal = | |
doc.General.FinancingInPeriodsTotal != null && | |
doc.General.FinancingInPeriodsTotal.Value.HasValue | |
? doc.General.FinancingInPeriodsTotal.Type == CurrencyType.EUR | |
? doc.General.FinancingInPeriodsTotal.Value | |
: CurrencyExtension.GetRoundedValueAsEUR(false, | |
doc.General.FinancingInPeriodsTotal.Value.Value) | |
: null, | |
FinancingInPeriods = doc.General.FinancingInPeriods.Select(c => | |
string.Format("{0}-{1}", | |
c.Period.StartTime != null ? c.Period.StartTime.Value.ToString(DateTimeExtension.DatePattern) : string.Empty, | |
c.Period.EndTime != null ? c.Period.EndTime.Value.ToString(DateTimeExtension.DatePattern) : string.Empty)), | |
InterruptionInPeriods = interruptionPeriods.Select(c => | |
string.Format("{0}-{1}", | |
c.Period.StartTime != null ? c.Period.StartTime.Value.ToString(DateTimeExtension.DatePattern) : string.Empty, | |
c.Period.EndTime != null ? c.Period.EndTime.Value.ToString(DateTimeExtension.DatePattern) : string.Empty)), | |
//InterruptionInPeriodsList = interruptionPeriods.Select(x => x.Period), | |
//InterruptionInPeriodsStartDic = interruptionPeriods.ToDictionary(x => x.Id.ToString(), y => y.Period.StartTime), | |
//InterruptionInPeriodsEndDic = interruptionPeriods.ToDictionary(x => x.Id.ToString(), y => y.Period.EndTime), | |
//InterruptionInPeriodsKeysList = interruptionPeriods.Select(x => x.Id.ToString()), | |
//HasInterruptions = interruptionPeriods.Any(x => x.Start.HasValue && x.End.HasValue), | |
AllExecutorSearchNames = allExecutorDocs != null && allExecutorDocs.Any() | |
? AuthorExtension.SystemAuthorFirstNames(allExecutorDocs | |
.SelectMany(e => new List<string> {e.FirstName, e.LastName}), false) | |
: null, | |
AllExecutorSearchNameCombinations = allExecutorDocs != null && allExecutorDocs.Any() | |
? AuthorExtension.SystemAuthorNames(allExecutorDocs.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), false) | |
: null, | |
AllExecutorSearchNameCombinationsNgrams = allExecutorDocs != null && allExecutorDocs.Any() | |
? AuthorExtension.SystemAuthorNames(allExecutorDocs.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), true) | |
: null, | |
ResponsibleExecutorSearchNames = responsibleExecutors != null && responsibleExecutors.Any() | |
? AuthorExtension.SystemAuthorFirstNames(responsibleExecutors | |
.SelectMany(e => new List<string> {e.FirstName, e.LastName}), false) | |
: null, | |
ResponsibleExecutorSearchNameCombinations = | |
responsibleExecutors != null && responsibleExecutors.Any() | |
? AuthorExtension.SystemAuthorNames(responsibleExecutors.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), false) | |
: null, | |
ResponsibleExecutorSearchNameCombinationsNgrams = | |
responsibleExecutors != null && responsibleExecutors.Any() | |
? AuthorExtension.SystemAuthorNames(responsibleExecutors.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), true) | |
: null, | |
MainExecutorSearchNames = mainExecutors != null && mainExecutors.Any() | |
? AuthorExtension.SystemAuthorFirstNames(mainExecutors | |
.SelectMany(e => new List<string> {e.FirstName, e.LastName}), false) | |
: null, | |
MainExecutorSearchNameCombinations = mainExecutors != null && mainExecutors.Any() | |
? AuthorExtension.SystemAuthorNames(mainExecutors.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), false) | |
: null, | |
MainExecutorSearchNameCombinationsNgrams = mainExecutors != null && mainExecutors.Any() | |
? AuthorExtension.SystemAuthorNames(mainExecutors.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), true) | |
: null, | |
ExecutorSearchNames = executors != null && executors.Any() | |
? AuthorExtension.SystemAuthorFirstNames(executors | |
.SelectMany(e => new List<string> {e.FirstName, e.LastName}), false) | |
: null, | |
ExecutorSearchNameCombinations = executors != null && executors.Any() | |
? AuthorExtension.SystemAuthorNames(executors.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), false) | |
: null, | |
ExecutorSearchNameCombinationsNgrams = executors != null && executors.Any() | |
? AuthorExtension.SystemAuthorNames(executors.Select(ae => new List<string> | |
{ | |
ae.FirstName, | |
ae.LastName | |
}), true) | |
: null, | |
LaborSearchNames = doc.Persons != null && doc.Persons.Labors != null && doc.Persons.Labors.Any() | |
? AuthorExtension.SystemAuthorFirstNames(doc.Persons.Labors | |
.Select(lb => lb.Person), false) | |
: null, | |
LaborSearchNameCombinations = | |
doc.Persons != null && doc.Persons.Labors != null && doc.Persons.Labors.Any() | |
? AuthorExtension.SystemAuthorNames(doc.Persons.Labors.Select(lb => new List<string> | |
{ | |
lb.Person | |
}), false) | |
: null, | |
LaborSearchNameCombinationsNgrams = | |
doc.Persons != null && doc.Persons.Labors != null && doc.Persons.Labors.Any() | |
? AuthorExtension.SystemAuthorNames(doc.Persons.Labors.Select(lb => new List<string> | |
{ | |
lb.Person | |
}), true) | |
: null, | |
MainExecutorIds = allExecutors.Where(x => mainRoleId == x.RoleId.ToString()).Select(x => x.Id), | |
ResponsibleExecutorIds = | |
allExecutors.Where(x => responsibleRoleId == x.RoleId.ToString()).Select(x => x.Id), | |
SupervisorIds = allExecutors.Where(x => supervisorRoleId == x.RoleId.ToString()).Select(x => x.Id), | |
SupervisorsActiveInstitutionFullPaths = | |
allExecutors.Where(x => supervisorRoleId == x.RoleId.ToString()).SelectMany( | |
sv => | |
sv.Person.ActiveOccupations | |
.Where(x => DateTimeExtension.IsAfterNow(x.EndDate) && x.InstitutionFullPath != null) | |
.Select(o => o.InstitutionFullPath)).Distinct(), | |
ExecutorIds = allExecutors.Where(x => executorRoleId == x.RoleId.ToString()).Select(x => x.Id), | |
SearchWords = new[] | |
{ | |
doc.Id.ToString(), | |
doc.Title, | |
doc.TitleEng, | |
doc.TitleOrig, | |
doc.General.Acronym, | |
doc.General.FinancierProjectNr, | |
doc.General.FinancierSubProjectNr, | |
doc.General.TaProjectNr, | |
doc.General.AmountFromFinancier.ToString(), | |
doc.General.AmountFromFinancierInForeignCur.ToString(), | |
doc.General.Annotation, | |
doc.General.AnnotationEng, | |
string.Join(", ", doc.General.FinancingInstitutions.Select(x => x.ExternalInstitution).ToList()), | |
doc.General.Url, | |
doc.General.Comment, | |
responsibleExecutor != null ? responsibleExecutor.Name : string.Empty, | |
doc.General.ProjectFinalResults | |
}.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray(), | |
InstitutionIds = | |
doc.General.FinancingInstitutions.Where(x => x.Institution != null) | |
.Select(y => y.Institution.Id) | |
.Union( | |
doc.General.ScienceInstitutions.Where(w => w.Institution != null) | |
.Select(a => a.Institution.Id)), | |
InstitutionNames = allInstitutions != null ? allInstitutions.Select(x => x.FullName) : null, | |
InstitutionNamesTokenized = allInstitutions != null ? allInstitutions.Select(x => x.FullName) : null, | |
InstitutionNamesEng = allInstitutions != null ? allInstitutions.Select(x => x.FullNameEng) : null, | |
InstitutionNamesEngTokenized = | |
allInstitutions != null ? allInstitutions.Select(x => x.FullNameEng) : null, | |
InstitutionRegNos = allInstitutions != null ? allInstitutions.Select(x => x.BusinessRegNo) : null, | |
PersonIds = | |
doc.Persons != null && doc.Persons.AllExecutors != null | |
? doc.Persons.AllExecutors.Where(x => x.Person != null) | |
.Select(y => y.Person.Id) | |
.Union(doc.Persons != null && doc.Persons.Labors != null | |
? doc.Persons.Labors.Select(w => w.Id) | |
: new List<Guid>()) | |
: new List<Guid>(), | |
PersonNames = allExecutorDocs != null | |
? allExecutorDocs.Select(x => x.Name) | |
.Union(doc.Persons != null && doc.Persons.Labors != null | |
? doc.Persons.Labors.Select(w => w.Person) | |
: new List<string>()) | |
: new List<string>(), | |
PersonNamesTokenized = allExecutorDocs != null | |
? allExecutorDocs.Select(x => x.Name) | |
.Union(doc.Persons != null && doc.Persons.Labors != null | |
? doc.Persons.Labors.Select(w => w.Person) | |
: new List<string>()) | |
: new List<string>(), | |
PersonRoleIds = | |
doc.Persons != null && doc.Persons.AllExecutors != null | |
? doc.Persons.AllExecutors.Where(x => x.RoleReference != null) | |
.Select(y => y.RoleReference.Id) | |
: new List<Guid>(), | |
PersonRoleNames = roles.Select(x => x.View.Name), | |
PersonRoleNamesTokenized = roles.Select(x => x.View.Name), | |
PersonRoleNamesEng = roles.Select(x => x.View.NameEng), | |
PersonRoleNamesEngTokenized = roles.Select(x => x.View.NameEng), | |
Numbers = | |
new List<string> {doc.General.Number}.Union(new List<string> {doc.General.FinancierProjectNr}) | |
.Union(new List<string> {doc.General.FinancierSubProjectNr}) | |
.Union(new List<string> {doc.General.TaProjectNr}), | |
NumbersTokenized = | |
new List<string> {doc.General.Number}.Union(new List<string> {doc.General.FinancierProjectNr}) | |
.Union(new List<string> {doc.General.FinancierSubProjectNr}) | |
.Union(new List<string> {doc.General.TaProjectNr}), | |
Titles = | |
new List<string> {doc.TitleEst}.Union(new List<string> {doc.TitleOrig}) | |
.Union(new List<string> {doc.TitleEng}), | |
TitlesTokenized = | |
new List<string> {doc.TitleEst}.Union(new List<string> {doc.TitleOrig}) | |
.Union(new List<string> {doc.TitleEng}), | |
ProjectStartDate = doc.General.ProjectPeriod.StartTime, | |
ProjectEndDate = doc.General.ProjectPeriod.EndTime, | |
//ProgrammeNameTokenized = programmeDocument != null ? programmeDocument.Name : string.Empty, | |
//ProgrammeCodeTokenized = programmeDocument != null ? programmeDocument.Code : string.Empty, | |
ProgrammeNamesTokenized = programmes.Select(x => x.View.Name), | |
ProgrammeCodesTokenized = programmes.Select(x => x.View.Code), | |
OtherProgrammeName = doc.General.OtherProgramme, | |
OtherProgrammeNameEng = doc.General.OtherProgrammeEng, | |
OtherProgrammeNameTokenized = doc.General.OtherProgramme, | |
ResearchAreaEtisFullPaths = aosWithChildren.Select(r => r.View.FullPath), | |
ResearchAreaEtisCodes = reasearchAreas.Select(r => r.Code), | |
ResearchAreaEtisNames = reasearchAreas.Select(r => r.Name), | |
ResearchAreaEtisNamesEng = reasearchAreas.Select(r => r.NameEng), | |
ResearchAreaCercsFullPaths = cercses.Select(r => r.FullPath), | |
ResearchAreaCercsCodes = cercses.Select(r => r.Code), | |
ResearchAreaCercsNames = cercses.Select(r => r.Name), | |
ResearchAreaCercsNamesEng = cercses.Select(r => r.NameEng), | |
ResearchAreaFrascatiCodes = frascatis.Select(r => r.Code), | |
ResearchAreaFrascatiNames = frascatis.Select(r => r.Name), | |
ResearchAreaFrascatiNamesEng = frascatis.Select(r => r.NameEng), | |
ResearchAreaChildCodes = aosChildren.Select(r => r.Code), | |
ResearchAreaChildNames = aosChildren.Select(r => r.Name), | |
ResearchAreaChildNamesEng = aosChildren.Select(r => r.NameEng), | |
DateCreated = doc.Created != null ? (DateTime?) doc.Created.On.Date : null, | |
DateModified = doc.Updated != null ? (DateTime?) doc.Updated.On.Date : null, | |
DateArchived = doc.Deleted != null ? (DateTime?) doc.Deleted.On.Date : null, | |
PersonIdCodes = allExecutors != null ? allExecutors.Select(x => x.Person.IDCode) : null, | |
DbGuid = doc.DbGuid, | |
ExpertGroupNumbers = doc.ExpertGroups != null ? doc.ExpertGroups.Where(x => x.View != null).Select(x => x.View.Number) : null | |
}; | |
Store(x => x.IndexId, FieldStorage.Yes); | |
Store(x => x.FinancingInPeriodsTotal, FieldStorage.Yes); | |
Store(x => x.FinancingInPeriods, FieldStorage.Yes); | |
Store(x => x.ProgrammeIds, FieldStorage.Yes); | |
Index(x => x.SearchWords, FieldIndexing.Analyzed); | |
Analyze(x => x.SearchWords, typeof (LowerCaseKeywordAnalyzer).AssemblyQualifiedName); | |
//nyyd analyysib kogu lauset, mitte iga tyhikut eraldi | |
Index(x => x.MainExecutorIds, FieldIndexing.NotAnalyzed); //Guid | |
Index(x => x.ResponsibleExecutorIds, FieldIndexing.NotAnalyzed); //Guid | |
Index(x => x.ExecutorIds, FieldIndexing.NotAnalyzed); //Guid | |
Analyzers.Add(x => x.InstitutionNamesTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.InstitutionNamesEngTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.PersonNamesTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.PersonRoleNamesTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.PersonRoleNamesEngTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.NumbersTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.TitlesTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
//Analyzers.Add(x => x.ProgrammeNameTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
//Analyzers.Add(x => x.ProgrammeCodeTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
Analyzers.Add(x => x.OtherProgrammeNameTokenized, typeof (SimpleAnalyzer).AssemblyQualifiedName); | |
} | |
public override string IndexName | |
{ | |
get { return "ETIS/ProjectSearchIndex"; } | |
} | |
///// <summary> | |
///// Projektidokumendiga seotud dokumentide Id-d | |
///// </summary> | |
//public IEnumerable<Func<ProjectDocument, IEnumerable<string>>> Dependencies() | |
//{ | |
// yield return (ProjectDocument p) => p.General.Programme.DocumentId; | |
// yield return (ProjectDocument p) => p.General.ScienceInstitutions.Where(i => i.Institution != null).Select(i => i.Institution.DocumentId); | |
//} | |
/// <summary> | |
/// Lae query tulemustega ka seotud dokumendid | |
/// </summary> | |
/// <param name="session"></param> | |
/// <returns></returns> | |
public IRavenQueryable<Info> BuildQueryWithDependencies(IDocumentSession session) | |
{ | |
var q = BuildQuery(session).Customize( | |
x => | |
{ | |
//TODO: dünaamiliselt | |
// Dependencies().ForEach(dep => x.Include<ProjectDocument>(srcDoc => dep.Invoke(srcDoc))); | |
x.Include<ProjectDocument>(d => d.General.ScienceInstitutions | |
//.Where(i => i.Institution != null) | |
.Select(i => i.Institution.DocumentId)); | |
x.Include<ProjectDocument>(p => p.General.Programme.DocumentId); | |
x.Include<ProjectDocument>( | |
p => p.General.FinancingInstitutions.Select(f => f.Institution.DocumentId)); | |
x.Include<ProjectDocument>(p => p.Persons.AllExecutors.Select(e => e.Person.DocumentId)); | |
} | |
); | |
//d => d.General.ScienceInstitutions.Where(i => i.Institution != null).Select(i => i.Institution.Id))); | |
return q; | |
} | |
public IRavenQueryable<Info> BuildQuery(IDocumentSession session) | |
{ | |
return session.Query<Info, ProjectSearchIndex>(); | |
} | |
public static IEnumerable<ProjectDocument> FindByNumber(string findProjectNumber, IDocumentSession session) | |
{ | |
return | |
Queryable.Where(session.Query<Info, ProjectSearchIndex>(), | |
x => x.FinancierProjectNr == findProjectNumber).OfType<ProjectDocument>(); | |
} | |
public class Info : ExecutorsDocumentInfo, IProjectStatisticsQueryable, IHasFinancingPeriods, IProgrammeListSearchableInfo, IHasInterruptionPeriods | |
{ | |
public IEnumerable<string> ProgrammeCodes { get; set; } | |
public IEnumerable<string> ProgrammeNames { get; set; } | |
public string TaProjectNr { get; set; } //TODO: (Ain) kas saab eemaldada? | |
public string FinancierProjectNr { get; set; } | |
public string TaProjectNrAndFinancierProjectNr { get; set; } | |
public ProjectDocumentType ProjectDocumentType { get; set; } | |
public string Name { get; set; } | |
public IEnumerable<string> InstitutionFullNames { get; set; } | |
public IEnumerable<Guid> ScienceInstitutionIds { get; set; } | |
/// <summary> | |
/// Kõik asutuste ja ülemastutuste järjestatud id-d | |
/// Näiteks institution1 {parent:DEADBEEF-01..,self:DEADBEEF-02..} ja institution2 {self:DEADBEEF-03..} on salvestatud | |
/// listina neist kahest pathist | |
/// 01: DEADBEEF-01..,DEADBEEF-02.. | |
/// 02: DEADBEEF-03.. | |
/// </summary> | |
public IEnumerable<string> InstitutionFullPaths { get; set; } | |
public IEnumerable<string> CoordinatorInstitutionNames { get; set; } | |
public IEnumerable<string> PartnerInstitutionNames { get; set; } | |
public IEnumerable<string> FinancingInstitutionNames { get; set; } | |
public IEnumerable<string> FinancingInstitutionFullPaths { get; set; } | |
public DateTime? StartDate { get; set; } | |
public string StartDateShortDateFormat { get; set; } | |
public DateTime? EndDate { get; set; } | |
public string EndDateShortDateFormat { get; set; } | |
public string Title { get; set; } | |
public string TitleEng { get; set; } | |
public string TitleOrig { get; set; } | |
public IEnumerable<string> AreaOfStudyIds { get; set; } | |
public IEnumerable<string> AreaOfStudyChildIds { get; set; } | |
public IEnumerable<string> AreaOfStudyCercsIds { get; set; } | |
public IEnumerable<string> AreaOfStudyFrascatiIds { get; set; } | |
public IEnumerable<string> AreaOfStudyFrascatiIdsWithStatus { get; set; } | |
public decimal? AmountFromFinancier { get; set; } | |
public decimal? FinancingInPeriodsTotal { get; set; } | |
public string FinancingInPeriodsTotalDisplay { get; set; } | |
public IEnumerable<Guid> ResponsibleExecutorIds { get; set; } | |
public IEnumerable<Guid> MainExecutorIds { get; set; } | |
public IEnumerable<Guid> ExecutorIds { get; set; } | |
public int StartYear { get; set; } | |
public int EndYear { get; set; } | |
public IEnumerable<string> InstitutionFullNamesEng { get; set; } | |
public IEnumerable<Guid> InstitutionIds { get; set; } | |
public IEnumerable<string> InstitutionNames { get; set; } | |
public IEnumerable<string> InstitutionNamesEng { get; set; } | |
public IEnumerable<string> InstitutionNamesTokenized { get; set; } | |
public IEnumerable<string> InstitutionNamesEngTokenized { get; set; } | |
public IEnumerable<string> InstitutionRegNos { get; set; } | |
public IEnumerable<Guid> PersonIds { get; set; } | |
public IEnumerable<string> PersonNames { get; set; } | |
public IEnumerable<string> PersonNamesTokenized { get; set; } | |
public IEnumerable<Guid> PersonRoleIds { get; set; } | |
public IEnumerable<string> PersonRoleNames { get; set; } | |
public IEnumerable<string> PersonRoleNamesTokenized { get; set; } | |
public IEnumerable<string> PersonRoleNamesEng { get; set; } | |
public IEnumerable<string> PersonRoleNamesEngTokenized { get; set; } | |
public IEnumerable<string> Numbers { get; set; } | |
public IEnumerable<string> NumbersTokenized { get; set; } | |
public IEnumerable<string> Titles { get; set; } | |
public IEnumerable<string> TitlesTokenized { get; set; } | |
public DateTime? ProjectStartDate { get; set; } | |
public DateTime? ProjectEndDate { get; set; } | |
//public string ProgrammeCodeTokenized { get; set; } | |
//public string ProgrammeNameTokenized { get; set; } | |
public IEnumerable<string> ProgrammeCodesTokenized { get; set; } | |
public IEnumerable<string> ProgrammeNamesTokenized { get; set; } | |
public string OtherProgrammeName { get; set; } | |
public string OtherProgrammeNameEng { get; set; } | |
public string OtherProgrammeNameTokenized { get; set; } | |
public IEnumerable<string> ResearchAreaEtisFullPaths { get; set; } | |
public IEnumerable<string> ResearchAreaEtisCodes { get; set; } | |
public IEnumerable<string> ResearchAreaEtisNames { get; set; } | |
public IEnumerable<string> ResearchAreaEtisNamesEng { get; set; } | |
public IEnumerable<string> ResearchAreaCercsFullPaths { get; set; } | |
public IEnumerable<string> ResearchAreaCercsCodes { get; set; } | |
public IEnumerable<string> ResearchAreaCercsNames { get; set; } | |
public IEnumerable<string> ResearchAreaCercsNamesEng { get; set; } | |
public IEnumerable<string> ResearchAreaFrascatiCodes { get; set; } | |
public IEnumerable<string> ResearchAreaFrascatiNames { get; set; } | |
public IEnumerable<string> ResearchAreaFrascatiNamesEng { get; set; } | |
public IEnumerable<string> ResearchAreaChildCodes { get; set; } | |
public IEnumerable<string> ResearchAreaChildNames { get; set; } | |
public IEnumerable<string> ResearchAreaChildNamesEng { get; set; } | |
public IEnumerable<string> PersonIdCodes { get; set; } | |
public Guid? DbGuid { get; set; } | |
public DateTime? ResponsibleExecutorBirthday { get; set; } | |
public Sex ResponsibleExecutorSex { get; set; } | |
public int ResponsibleExecutorAgeDuringProjectStart { get; set; } | |
public IEnumerable<Guid> SupervisorIds { get; set; } | |
public IEnumerable<string> SupervisorsActiveInstitutionFullPaths { get; set; } | |
public IEnumerable<string> FinancingInPeriods { get; set; } | |
public IEnumerable<Guid> ProgrammeIds { get; set; } | |
public IEnumerable<string> ExpertGroupNumbers { get; set; } | |
public IEnumerable<string> InterruptionInPeriods { get; set; } | |
//public bool HasInterruptions { get; set; } | |
//public IEnumerable<TimeRange> InterruptionInPeriodsList { get; set; } | |
//public Dictionary<string, DateTime?> InterruptionInPeriodsStartDic { get; set; } | |
//public Dictionary<string, DateTime?> InterruptionInPeriodsEndDic { get; set; } | |
//public IEnumerable<string> InterruptionInPeriodsKeysList { get; set; } | |
public object _ { get; set; } | |
} | |
public interface IHasFinancingPeriods | |
{ | |
IEnumerable<string> FinancingInPeriods { get; set; } | |
} | |
public class HasFinancingPeriods : IHasFinancingPeriods | |
{ | |
public IEnumerable<string> FinancingInPeriods { get; set; } | |
} | |
public interface IHasInterruptionPeriods | |
{ | |
IEnumerable<string> InterruptionInPeriods { get; set; } | |
} | |
public class HasInterruptionPeriods : IHasInterruptionPeriods | |
{ | |
public IEnumerable<string> InterruptionInPeriods { get; set; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment