Copied to clipboard

Flag this post as spam?

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


  • olst 69 posts 88 karma points
    Nov 20, 2011 @ 17:47
    olst
    0

    examine search

    Hi.

    I'm trying to perform a search using the following code, but search results are always empty.

    I have searched for a simple "a" in the search term and got 0 matches.

    to simplify the example I have a simple filter:

    SearchTerm = Request.QueryString["s"];
                if (string.IsNullOrEmpty(SearchTerm)) return;
    
                var criteria = ExamineManager.Instance
                .SearchProviderCollection["MySearcher"]
                .CreateSearchCriteria(IndexTypes.Content);
    
                var filter = criteria
                .Field("pageTitle",SearchTerm)
                .Not()
                .Field("umbracoNaviHide", "1")
                .Compile();
    
    
                SearchResultsCollection =
                ExamineManager.Instance
                .SearchProviderCollection["MySearcher"]
                .Search(filter);
    
                SearchResultListing.DataSource = SearchResultsCollection;
                SearchResultListing.DataBind();
  • olst 69 posts 88 karma points
    Nov 20, 2011 @ 17:50
    olst
    0

    (Sorry for the extra post, but it won't let me edit)

    How do I know if the index has been created properly ?

  • Thomas 49 posts 78 karma points c-trib
    Nov 20, 2011 @ 18:53
    Thomas
    0

    Hi - I found this quite useful when working with Examine http://www.getopt.org/luke/

    You can point that to your index (note that there's some locking, so do this when you site is not publishin/indexing) - and you can actually see what fields are in the index - a good starting point for debugging.

     

    Also - in case it helps you, some simple search code that I (am pretty sure) was working at some point.

     

               ISearchCriteria criteria = ExamineManager.Instance
                    .SearchProviderCollection[MY_SEARCHER_NAME]
                    .CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
    
                results.Text = "";
                string q = searchQuery.Text.Trim();
                ISearchCriteria filter = criteria
                         .NodeTypeAlias("myAlias").And().GroupedOr(new string[] { "name", "street", "town", "postcode" }, q).Compile();
    
                IEnumerable<SearchResult> searchResults = ExamineManager.Instance.SearchProviderCollection[MY_SEARCHER_NAME].Search(filter);
    
    However you'll find hundreds of Examine questions and examples on here, not my favourite part of Umbraco I have to say ;0)
  • olst 69 posts 88 karma points
    Nov 20, 2011 @ 20:35
    olst
    0

    Hi thomas,

    I used your code, but when I debug and put a watch on filter I get null null null null for the fields ?

    What does it mean ? Do I have a problem with the indexing ?

  • Thomas 49 posts 78 karma points c-trib
    Nov 21, 2011 @ 00:02
    Thomas
    0

    Hi - I think the first thing to try and do is use the Luke examiner I mentioned (http://www.getopt.org/luke/) - download and run the main .jar file, then point that to the folder you have your index in.

    That will tell you if you have data in your index (and you will be able to see the field names and values), then you will know if you're problem is 1) configuring the indexing, or 2) the code interrogating this (above).

    Likely it's the first - there's indexing events (ongatheringnodedata) you can hook into and debug - hope that helps...

  • olst 69 posts 88 karma points
    Nov 21, 2011 @ 10:33
    olst
    0

    Thanks, I downloaded luke and pointed it to my index, seems like my index is empty, since it says it has 0 fields, 0 documents etc.

    My question is... how do I fill the index with data ? in what event does the index get filled ? I tried publishing the whole website, but the index remains empty...

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Nov 21, 2011 @ 10:39
    Ismail Mayat
    0

    olst,

    download the excellent http://our.umbraco.org/projects/developer-tools/examine-dashboard that will allow you to rebuild indexes.

    Regards

    Ismal

  • olst 69 posts 88 karma points
    Nov 21, 2011 @ 12:56
    olst
    0

    Hi Ismail,

    I downloaded the examine-dashboard, thanks for that, and the problem is that there is a file at the queue, I tried deleting the queue and rebuilding the index but there's always a file at the queue:

    "1 file in queue -> Last update 11/21/2011 1:41:09 PM - 634574796690742435-DESKTOP2.del ..."

  • olst 69 posts 88 karma points
    Nov 21, 2011 @ 13:45
    olst
    0

    The InternalIndexer and InternalMemberIndexer build just fine and at the end of the rebuilding process, the queus are cleared, what can be the cause of the hanging of the queue ? somebody ?

  • Thomas 49 posts 78 karma points c-trib
    Nov 21, 2011 @ 14:52
    Thomas
    0

    Hi - that's a "delete request" for the Lucene indexer - if you open it in notepad you can see what it's asking Lucene to delete.

    If this is failing then perhaps you have write permission issue, check the IIS app pool identity has write perms on your folder.

    More generally - try and hook into the Examine events and see if you can debug the issue - some code for you:

     

       public class UmbracoExamineEvents : ApplicationBase
    {
    private const string SOMETHING_INDEXER_NAME = "somethingIndexer";
    private const string SOMETING_ELSE_INDEXER_NAME = "SomethingElseIndexer";
    private const string YET_ANOTHER_INDEXER_NAME = "YetAnotherIndexer";

    public UmbracoExamineEvents()
    {
    foreach (BaseIndexProvider indexer in ExamineManager.Instance.IndexProviderCollection)
    {
    indexer.IndexingError += new EventHandler<IndexingErrorEventArgs>(UmbracoExamine_IndexingError);
    indexer.NodesIndexed += new EventHandler<IndexedNodesEventArgs>(indexer_NodesIndexed);
    indexer.NodesIndexing += new EventHandler<IndexingNodesEventArgs>(indexer_NodesIndexing);
    }

    var somethingIndexer = ExamineManager.Instance.IndexProviderCollection[SOMETHING_INDEXER_NAME];
    if (somethingIndexer != null)
    somethingIndexer.GatheringNodeData += SomethingIndexer_OnGatheringNodeData;



    var clIndexer = ExamineManager.Instance.IndexProviderCollection[SOMETING_ELSE_INDEXER_NAME];
    if (clIndexer != null)
    {
    clIndexer.NodeIndexed += clIndexer_NodeIndexed;
    clIndexer.IndexingError += clIndexer_IndexingError;
    }

    }

    void clIndexer_IndexingError(object sender, IndexingErrorEventArgs e)
    {
    string s = e.Message;
    }

    void clIndexer_NodeIndexed(object sender, IndexedNodeEventArgs e)
    {
    string s = e.NodeId.ToString();
    }

    void indexer_NodesIndexing(object sender, IndexingNodesEventArgs e)
    {
    ExceptionManager.LogInfoEvent(
    String.Format("UmbracoExamine NodesIndexing Type: {0}, using XPATH: '{1}'", e.Type,e.XPath),
    "UmbracoExamineEvents");
    }

    void indexer_NodesIndexed(object sender, IndexedNodesEventArgs e)
    {
    ExceptionManager.LogInfoEvent(
    String.Format("UmbracoExamine Indexed {0} nodes, using Criteria: '{1}'",
    e.Nodes == null ? 0 : e.Nodes.Count(), e.IndexData.ToString()),
    "UmbracoExamineEvents");
    }

    void UmbracoExamine_IndexingError(object sender, IndexingErrorEventArgs e)
    {
    string s = e.Message;
    ExceptionManager.LogExceptionEvent(
    e.InnerException ?? new Exception("Innerexception NULL"),
    "IndexingError: " + e.Message,
    Library.Logger.Source.Umbraco);
    }



    void SomethingElse_OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
    if (e.IndexType != IndexTypes.Media)
    return;
    }

    /// <summary>
    /// Handles the OnGatheringNodeData event of the MagazineIndexer.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="Examine.IndexingNodeDataEventArgs"/> instance containing the event data.</param>
    void SomethingIndexer_OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
    if (e.IndexType != IndexTypes.Media)
    return;

    e.Fields.Add("_parentID", e.Node.Attribute("parentID").Value);
    }
    }
Please Sign in or register to post replies

Write your reply to:

Draft