I've got a requirement to search in just a part of the tree. And I also want to searhc in all the fields of the documents. This seems to fall between two chairs.
To search in all fields, I could do this:
var searcher = ExamineManager.Instance.SearchProviderCollection["OurIndexSearcher"];
var results = searcher.Search("my words", true);
But to search a specific parrt of the tree, I need to do something like a raw query with:
+__Path:\-1,1234,2345*
Is there a way to combine the two? Can I easily search all fields wit the raw query, or will I need to create my own searcher implementation to be able to get all the available fields from the index?
Looking at the Examine Source, the Search method is simply doing the following:
var sc = this.CreateSearchCriteria();
if (useWildcards) {
var wildcardSearch = new ExamineValue(Examineness.ComplexWildcard, searchText.MultipleCharacterWildcard().Value);
sc = sc.GroupedOr(GetSearchFields(), wildcardSearch).Compile();
} else {
sc = sc.GroupedOr(GetSearchFields(), searchText).Compile();
}
return Search(sc);
Thus, you can create the search criteria and add the additional search into it.
var searcher =ExamineManager.Instance.SearchProviderCollection["OurIndexSearcher"]; var sc = searcher.CreateSearchCriteria(); var wildcardSearch = new ExamineValue(Examineness.ComplexWildcard, searchText.MultipleCharacterWildcard().Value);
sc = sc.GroupedOr(GetSearchFields(), wildcardSearch).And().Field("__Path", "-1,1234,2345".Escape().MultipleCharacterWildcard().Value); var results = searcher.Search(sc.Compile());
I am piecing this together and not testing.... so, take with a grain of salt :P
OK, so found this digging through the code deeper.
var reader = searcher.GetIndexReader();
var fields = reader.GetFieldNames(IndexReader.FieldOption.ALL);
//exclude the special index fieldsvar searchFields = fields
.Where(x => !x.StartsWith(LuceneIndexer.SpecialFieldPrefix)) // starts with __ .ToArray();
return searchFields;
This is the GetSearchField() method from one of the searchers.
Thanks Casey. I managed to get it working. to some extent, but as it often is with search, the requirements now changed, so I don't need _all_ the fields.
Searching in subtree with Examine
Hi examine experts :-)
I've got a requirement to search in just a part of the tree. And I also want to searhc in all the fields of the documents. This seems to fall between two chairs.
To search in all fields, I could do this:
But to search a specific parrt of the tree, I need to do something like a raw query with:
Is there a way to combine the two? Can I easily search all fields wit the raw query, or will I need to create my own searcher implementation to be able to get all the available fields from the index?
Looking at the Examine Source, the Search method is simply doing the following:
Thus, you can create the search criteria and add the additional search into it.
I am piecing this together and not testing.... so, take with a grain of salt :P
Oi.. GetSearchFields() is protected internal.. oi.
OK, so found this digging through the code deeper.
This is the GetSearchField() method from one of the searchers.
Thanks Casey. I managed to get it working. to some extent, but as it often is with search, the requirements now changed, so I don't need _all_ the fields.
is working on a reply...