Very simple use of sitecore search

I am trying to set up a very simple search index to index all items in a specific folder. I didn’t look very much, but I am trying to use ready-made functions, because this is a very simple search. I just want to index all the fields. The sitecore documentation does not really contain much information - I read several blogs, and all of them seem to offer me that I need an advanced database crawler ( http://trac.sitecore.net/AdvancedDatabaseCrawler ) - in principle, something will work "it will not work without a custom crawler."

Is it correct? I just want to create a simple index and start using it. What is the easiest way to do this without any shared modules or otherwise? I looked at the sitecore documentation, but this is not very clear (at least for me). It defines the various index configuration items in web.config, but does not really explain what they do or what values ​​are available. Maybe I'm not looking at the right place.

+6
source share
4 answers

An easy way to create a new Lucene index in Sitecore with all the elements below a specific node in just 3 steps:

1: Add the configuration below to the configuration configuration/sitecore/search/configuration/indexes in Sitecore :

 <!-- id must be unique --> <index id="my-custom-index" type="Sitecore.Search.Index, Sitecore.Kernel"> <!-- name - not sure if necessary but use id and forget about it --> <param desc="name">$(id)</param> <!-- folder - name of directory on the hard drive --> <param desc="folder">__my-custom-index</param> <!-- analyzer - reference to analyzer defined in Sitecore.config --> <Analyzer ref="search/analyzer" /> <!-- list of locations to index - each of the with unique xml tag --> <locations hint="list:AddCrawler"> <!-- first location (and the only one in this case) - specific folder from you question --> <!-- type attribute is the crawler type - use default one in this scenario --> <specificfolder type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel"> <!-- indexing itmes from master database --> <Database>master</Database> <!-- your folder path --> <Root>/sitecore/content/home/my/specific/folder</Root> </specificfolder> </locations> </index> 

2: Rebuild the new index (only once, all further changes will be detected automatically):

 SearchManager.GetIndex("my-custom-index").Rebuild(); 

3: Use the new index:

 // use id of from the index configuration using (IndexSearchContext indexSearchContext = SearchManager.GetIndex("my-custom-index").CreateSearchContext()) { // MatchAllDocsQuery will return everything. Use proper query from the link below SearchHits hits = indexSearchContext.Search(new MatchAllDocsQuery(), int.MaxValue); // Get Sitecore items from the results of the query List<Item> items = hits.FetchResults(0, int.MaxValue).Select(result => result.GetObject<Item>()).Where(item => item != null).ToList(); } 

Here is a pdf describing Sitecore Search and Indexing .

And here's a blog post about Searching and Indexing Sitecore Lucene .

Here is a Lucene query syntax tutorial

and Introducing Lucene.Net

+14
source

Sitecore Search Contrib (new name for the advanced database crawler) is the best option, you just configure its configuration in the application’s configuration folder to tell it the launch database, etc.

Then you can use your API to search folders by template type, where a specific field has a specific value. Here is a sample code.

 MultiFieldSearchParam parameters = new MultiFieldSearchParam(); parameters.Database = "web"; parameters.InnerCondition = QueryOccurance.Should; parameters.FullTextQuery = searchTerm; parameters.TemplateIds = array of pipe seperated ID's var refinements = Filters.Select(item => new MultiFieldSearchParam.Refinement(item.Value, item.Key.ToString())).ToList(); parameters.Refinements = refinements; 

// Actual search

 var returnItems = new List<Item>(); var runner = new QueryRunner(IndexName); var skinnyItems = runner.GetItems(new[] {parameters}); skinnyItems.ForEach(x => returnItems.Add(Database.GetItem(new ItemUri(x.ItemID)))); return returnItems; 

Otherwise, you can simply configure web.config for the standard lucene search and use this code to search. (Database to use "web", starting element, etc.)

 public Item[] Search(string searchterms) { var children = new List<Item>(); var searchIndx = SearchManager.GetIndex(IndexName); using (var searchContext = searchIndx.CreateSearchContext()) { var ftQuery = new FullTextQuery(searchterms); var hits = searchContext.Search(ftQuery); var results = hits.FetchResults(0, hits.Length); foreach (SearchResult result in results) { if (result.GetObject<Item>() != null) { //Regular sitecore item returned var resultItem = result.GetObject<Item>(); if (ParentItem == null) { children.Add(resultItem); } else if (resultItem.Publishing.IsPublishable(DateTime.Now, false) && ItemUtilities.IsDecendantOfItem(ParentItem, resultItem)) { children.Add(resultItem); } } } } return children.ToArray(); } 
+3
source

You can then download the Lucene Index Viewer extension for Sitecore to view the index, or you can download the Lucene Tool to view indexes. See if you can fill out documents (files in your indexes). They are called “Documents” in Lucene, and technically these documents are the content elements specified in the node that you specified.

0
source

Brian Pedersen has a good article. You will start with a simple seeker. You must download the advanced database crawler and add a link to your project after creating it.

Then you need to create the configuration files mentioned in Brian’s blog and you have to copy them (except for the id n all template). In principle, you are here.

You can then download the Lucene Index Viewer extension for Sitecore to view the index, or you can download the Lucene Tool to view indexes. See if you can fill out documents (files in your indexes). They are called “Documents” in Lucene, and technically these documents are the content elements specified in the node that you specified.

Hope this helps!

Let me google that for you.

-2
source

Source: https://habr.com/ru/post/948183/


All Articles