I have 2 custom index sets generating with Examine in Umbraco 4.7RC. They both index all the fields I want correctly. When it comes to searching I select the provider using this line of code:
var criteria = ExamineManager.Instance.SearchProviderCollection[indexName].CreateSearchCriteria(IndexTypes.Content, BooleanOperation.Or);
I'm assuming that this should select the index search provider I specify in the variable indexName? But this doesn't happen as I only ever get results back for the correct index when I change the defaultProvider value in ExamineSettings.config.
How do you search multiple indexes? Examine seems to only use the defaultProvider and ignores the rest.
var searchProvider = ExamineManager.Instance.SearchProviderCollection["RegularSearcher"]; //RegularSearcher & PDFSearcher are the names you set up in the <ExamineSearchProviders settings in ExamineSettings.config var searchProviderPdf = ExamineManager.Instance.SearchProviderCollection["PDFSearcher"];
Thank you for the replies. I don't want to combine the search results I am just trying to search each index seperatley. So I have MethodA which searches IndexA and returns results, and MethodB which searches IndexB and returns results. It seems if MethodA uses SearcherA I get the IndexA results, but when MethobB uses SearcherB I get no results. MethodB will only return results if I change the defaultProvider field to SearcherB, but then MethodA doesn't return any results.
Both Lucene queries generated in C# return results in Luke.
I'm going to update to Umbraco 4.7 final and make sure I have the latest Examine dll. I still think you should be able to search 2 indexes with 2 different providers and get back 2 different results, or am I mistaken?
Here is my method where I pass in the indexName (plus other parameters)
public static IEnumerable<SearchResult> Search(string indexName, string[] searchTerms, string[] fields, string[] nodeTypeAliases)
{
IEnumerable<SearchResult> results = null;
if (searchTerms != null)
{
// Make sure there are no empty search terms.
var nonEmptySearchTerms = searchTerms.Where(x => !string.IsNullOrEmpty(x));
if (nonEmptySearchTerms.Count() > 0)
{
// Get the search criteria by using our searcher provider and looking only in the content tree of Umbraco.
var criteria = ExamineManager.Instance.SearchProviderCollection[indexName].CreateSearchCriteria(IndexTypes.Content, BooleanOperation.Or);
// Build the search query.
Examine.SearchCriteria.IBooleanOperation query = null;
foreach (var searchTerm in nonEmptySearchTerms)
{
// Add search fields.
foreach (var field in fields)
{
query = query == null ? criteria.Field(field, searchTerm.Escape().Value.MultipleCharacterWildcard()) :
query.Or().Field(field, searchTerm.Escape().Value.MultipleCharacterWildcard());
}
}
// Perform the search.
results = ExamineManager.Instance.Search(query.Compile());
results = results.OrderByDescending(x => x.Score); // Relevance.
// TODO: Do this in the query not sure how yet?
if (nodeTypeAliases != null)
{
results = results.Where(x => nodeTypeAliases.Contains(x.Fields["nodeTypeAlias"]));
}
}
}
return results;
}
We have a very similar method, and... it just work (latest 4.7), ie it picks results for the selected index. But I remember facing a similar issue in the past. Can you check that you do have the latest Examine DLLs?
Searching multiple indexes with Examine
I have 2 custom index sets generating with Examine in Umbraco 4.7RC. They both index all the fields I want correctly. When it comes to searching I select the provider using this line of code:
I'm assuming that this should select the index search provider I specify in the variable indexName? But this doesn't happen as I only ever get results back for the correct index when I change the defaultProvider value in ExamineSettings.config.
How do you search multiple indexes? Examine seems to only use the defaultProvider and ignores the rest.
You could for example:
Guys,
The latest version of examine has multi index search provider, not used it myself but its there see http://examine.codeplex.com/releases/view/62313
Regards
Ismail
Thank you for the replies. I don't want to combine the search results I am just trying to search each index seperatley. So I have MethodA which searches IndexA and returns results, and MethodB which searches IndexB and returns results. It seems if MethodA uses SearcherA I get the IndexA results, but when MethobB uses SearcherB I get no results. MethodB will only return results if I change the defaultProvider field to SearcherB, but then MethodA doesn't return any results.
Both Lucene queries generated in C# return results in Luke.
I'm going to update to Umbraco 4.7 final and make sure I have the latest Examine dll. I still think you should be able to search 2 indexes with 2 different providers and get back 2 different results, or am I mistaken?
Looking forward to your response :)
Here is my method where I pass in the indexName (plus other parameters)
We have a very similar method, and... it just work (latest 4.7), ie it picks results for the selected index. But I remember facing a similar issue in the past. Can you check that you do have the latest Examine DLLs?
I tried to upgrade from 4.7RC to 4.7 final. The upgrade all works except umbraco.MacroEngines.dll. I get this message on all my Razor scripts:
Error loading Razor Script *.cshtml Method not found: 'System.Collections.Generic.IEnumerable`1 umbraco.MacroEngines.DynamicNodeList.get_Items()'.
If I use the 4.7RC umbraco.MacroEngines.dll it works.
umbraco.MacroEngines.dll 4.7RC (version 1.0.0.0, size 89Kb) - this works!
umbraco.MacroEngines.dll 4.7 (version 1.0.0.0, size 97Kb) - this doesn't work!
Any one else have this problem?
You have to specify which searcher to search. Not only to create the query:
That works! Quite obvious - thank you :)
Any ideas on the umbraco.MacroEngines.dll error I'm expriencing updating?
@Morten: we indeed do that, and I failed to spot the difference... you're the boss!
Glad it worked. I don't have an answer on the razor issue. sorry.
is working on a reply...