Urvesh
Urvesh

Reputation: 23

SearchManager.GetIndex is not working - using lucene search

I am applying search functionality in my system using Sitecore 7.0 (actually I am converting my code from Sitecore 6.5 to sitecore 7.0). When I try to get index using Sitecore.Search.SearchManager.GetIndex method, I find configuration property with null value.

My sample code in 6.5 is as below

webDb = Sitecore.Context.Database;
Sitecore.Data.Indexing.Index indx = webDb.Indexes["system"]; //Getting warning  - deprecated method
Item bucketItem = Sitecore.Context.Item;

IndexSearcher indexSearcher = indx.GetSearcher(webDb);

topDocs = GetContent(keyWords, webDb, indexSearcher, year, regionName);

if (topDocs != null)
{
    int totalMatchItemCount = topDocs.TotalHits;
    if (totalMatchItemCount > 0)
    {
       returnValues = new Item[totalMatchItemCount];

       int i = 0;
       foreach (ScoreDoc scoreDoc in topDocs.ScoreDocs)
       {
          Document doc = indexSearcher.Doc(scoreDoc.Doc);
          Item item = Index.GetItem(doc, webDb);//Getting warning  - deprecated method
          returnValues[i++] = item;
       }
     }
}

Its works fine but gives error of deprecated method on below lines,

Sitecore.Data.Indexing.Index indx = webDb.Indexes["system"];

and

Item item = Index.GetItem(doc, webDb);

My converted code of Sitecore 7.0 is as below,

   var children = new List<Item>();

   Sitecore.Search.Index searchIndx = Sitecore.Search.SearchManager.GetIndex("system");//Shows SearchManager._Configuration with NULL value, hence all methods and property getting with exception.

   using (var searchContext = searchIndx.CreateSearchContext())
   {
     var ftQuery = new Sitecore.Search.FullTextQuery(keyWords);
     var hits = searchContext.Search(ftQuery);
     var results = hits.FetchResults(0, hits.Length);

     foreach (Sitecore.Search.SearchResult result in results)
     {
          //My stuff
     }
   }

When I am trying to fetch value using Sitecore 7.0, get the below exception

Could not create instance of type: Lucene.Net.Analysis.Standard.StandardAnalyzer. No matching constructor was found.

Thanks.

Upvotes: 1

Views: 3082

Answers (3)

Yogesh Sharma
Yogesh Sharma

Reputation: 2017

Use below code to get index in Sitecore 7.

// Index
public static string IndexName 
{
    get
        {
        return (Sitecore.Context.Database.Name.ToLower()) == "master" ? "sitecore_master_index" : "sitecore_web_index";
        }
}



public static ISearchIndex _index;
        public static ISearchIndex Index
        {
            get
            {
                if (_index == null) { _index = ContentSearchManager.GetIndex(IndexName); }

                return _index;
            }
        }

Upvotes: 1

Steve McGill
Steve McGill

Reputation: 501

Could not create instance of type: Lucene.Net.Analysis.Standard.StandardAnalyzer. No matching constructor was found.

I've seen this error occur when there are DLLs from multiple Sitecore versions in your /bin folder, so I'd agree with @TwentyGotoTen: it sounds like you either missed out a step in the upgrade process, or you need to check your deploy process to make sure your solution isn't referencing older versions of Sitecore assemblies.

Upvotes: 0

Martin Davies
Martin Davies

Reputation: 4456

I have a feeling this is because you're still using the pre-Sitecore 7 Sitecore.Search API rather than the newer Sitecore.ContentSearch.

Try this for some further help: Searching with the new Sitecore 7 API

Upvotes: 1

Related Questions