I've got a lot of persons inside the content tree and I'll create a new index for that. This is for improve the performance of the web application when searching for a specific person.
I've made a new index in the examine manager from Umbraco 7.7 named PersonIndexer
to index all the persons. This includes only the node types of a person.
For this I've made this code:
ExamineSettings.config
Inside the file ExamineSettings.config
inside the Examine
→ ExamineIndexProviders
→ providers
tag:
<add name="PersonsIndexer"
type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
supportUnpublished="false"
supportProtected="true"
indexSet="Persons"
analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
And inside the same file I've also added this but inside the Examine
→ ExamineSearchProviders
→ providers
tag:
<add name="PersonsSearcher"
type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
supportUnpublished="false"
supportProtected="true"
indexSet="Persons"
analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
ExamineIndex.config
Inside the file ExamineIndex.config
inside the ExamineLuceneIndexSets
tag:
<IndexSet SetName="Persons" IndexPath="~/App_Data/TEMP/ExamineIndexes/Persons/" >
<IndexAttributeFields>
<add Name="knowledge" />
<add Name="photo" />
<add Name="name"/>
<add Name="firstName"/>
<add Name="lastName"/>
</IndexAttributeFields>
<IncludeNodeTypes>
<add Name="person" />
</IncludeNodeTypes>
</IndexSet>
When I build this index, it got 7 documents inside the index.
How can I get all this documents inside my view. I've tried this code:
var indexer = ExamineManager.Instance.IndexProviderCollection["PersonsIndexer"];
This gives me all properties of that index.
This isn't what I need. So my question is: How could I get the typed documents from that index?
After @Marks answer I've tried his code but when I watch searchResults
I've got this:
When I do a Lucene search of *
, I've got 7 results.
When I do a text search xor I text xor lucene search on an empty string, I've got nothing.
You'll want to use the searcher to retrieve the documents.
Here's a little example of some code I used to retrieve documents from the index, hope it helps you.
var searcher = ExamineManager.Instance.SearchProviderCollection["PersonsSearcher"];
var searchCriteria = searcher.CreateSearchCriteria();
var query = searchCriteria.Field("nodeTypeAlias", "person").Compile();
var searchResults = searcher.Search(query);
Edit
I've taken a look at my ExamineIndex.config
and you'll have to define the default Umbraco properties and user defined properties seperately in the XML.
A little example of my CustomIndexSet
.
<IndexSet SetName="CustomIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Custom/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName"/>
<add Name="updateDate" />
<add Name="nodeTypeAlias" />
</IndexAttributeFields>
<IndexUserFields>
<add Name="category" />
<add Name="title" />
<add Name="description" />
<add Name="status" />
<add Name="keywords" />
</IndexUserFields>
<IncludeNodeTypes>
<add Name="item"/>
<add Name="category"/>
</IncludeNodeTypes>
</IndexSet>