Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Oct 31, 2012 @ 19:44
    Morten Bock
    0

    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:

    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?

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Nov 01, 2012 @ 02:14
    Casey Neehouse
    0

    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

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Nov 01, 2012 @ 02:39
    Casey Neehouse
    0

    Oi.. GetSearchFields() is protected internal.. oi.

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Nov 01, 2012 @ 02:49
    Casey Neehouse
    0

    OK, so found this digging through the code deeper.

                var reader = searcher.GetIndexReader();
                var fields = reader.GetFieldNames(IndexReader.FieldOption.ALL);
                //exclude the special index fields
                var searchFields = fields
                    .Where(x => !x.StartsWith(LuceneIndexer.SpecialFieldPrefix))  // starts with __
                    .ToArray();             return searchFields;

    This is the GetSearchField() method from one of the searchers.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 02, 2012 @ 10:06
    Morten Bock
    0

    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.

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies