+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Adding custom meta data to pages and indexing custom meta data

Adding custom meta data to pages and indexing custom meta data

8 posts, 0 answered
  1. Annie
    Annie avatar
    123 posts
    Registered:
    08 Apr 2009
    12 Oct 2011
    Link to this post
    Hi,

    Is there a way I can add custom meta tags to pages and have these metatags indexed by search in sitefinity 3.7 sp4

    Thanks,
    Annie
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Oct 2011
    Link to this post
    Hello Annie,

    You need to implement a custom search manager to do this. The default manager gets only the fields that are currently presented in create/edit page screen

    • "title"
    •  "path"
    •  "keywords"
    •  "description"

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Annie
    Annie avatar
    123 posts
    Registered:
    08 Apr 2009
    13 Oct 2011
    Link to this post
    Hi Ivan,

    So would we be able to accomplish this using a custom indexer? Or do we have to implement a completely new search

    Thanks,
    Annie
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Oct 2011
    Link to this post
    Hello Annie,

    You will need a new implementation of the SearchManager.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Annie
    Annie avatar
    123 posts
    Registered:
    08 Apr 2009
    19 Oct 2011
    Link to this post
    Hi Ivan,

    Do you have code that I can use to implement a new search manager

    Thanks,
    Annie
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Oct 2011
    Link to this post
    Hello Annie,

    Create a class that inherits from SearchManager and then implement a search method in it

    public static IList<ResultItem> SearchExtender(string searchQuery, string indexName, int startIndex, int max, string mode, bool escapeChars, out int totalItems)
          {
             
              IList<ResultItem> result = new List<ResultItem>();
              string[] fields = SearchManager.GetFields(indexName);
              string indexDirectory = PathUtil.GetIndexPhysicalPath(indexName);
              IndexSearcher searcher = new IndexSearcher(indexDirectory);
      
              QueryParser.Operator searchMode = QueryParser.AND_OPERATOR;
      
              MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
      
              if (!String.IsNullOrEmpty(mode)
                  && mode == "AnyWord")
              {
                  searchMode = QueryParser.OR_OPERATOR;
              }
              parser.SetDefaultOperator(searchMode);
      
              if (escapeChars)
              {
                  searchQuery = QueryParser.Escape(searchQuery);
              }
      
              Query query = searcher.Rewrite(parser.Parse(searchQuery));
              Query query = searcher.Rewrite(parser.GetFuzzyQuery(p1, p2, p3));
              Highlighter highlighter = new Highlighter(new QueryScorer(query));
              Hits hits = searcher.Search(query);
      
              totalItems = hits.Length();
              if (max == 0)
                  max = totalItems;
              else if (startIndex + max > totalItems)
                  max = totalItems;
              else
                  max = startIndex + max;
      
              for (int i = startIndex; i < max; i++)
              {
                  Document doc = hits.Doc(i);
                  ResultItem item = new ResultItem();
                  item.Title = doc.Get("title");
                  item.Url = ResolveUrl(doc.Get("path"));
                  item.Score = hits.Score(i);
      
                  StringBuilder snippet = new StringBuilder();
                  bool lastAppendedIsSeparator = false;
                  for (int k = 0; k < fields.Length; k++)
                  {
                      string field = fields[k];
                      switch (field.ToLower())
                      {
                          case "title":
                          case "path":
                          case "keywords":
                          case "description":
                              continue;
                      }
                      string[] values = doc.GetValues(field);
                      if (values != null && values.Length > 0)
                      {
                          for (int j = 0; j < values.Length; j++)
                          {
                              if (values[j].Length > 0)
                              {
                                  snippet.Append(values[j]);
                                  lastAppendedIsSeparator = false;
                                  if (j < values.Length - 1)
                                  {
                                      snippet.AppendLine(SEARCH_RESULTS_SEPARATOR);
                                      lastAppendedIsSeparator = true;
                                  }
                              }
                          }
                      }
                      if (k < fields.Length - 1 && !lastAppendedIsSeparator)
                      {
                          snippet.AppendLine(SEARCH_RESULTS_SEPARATOR);
                          lastAppendedIsSeparator = true;
                      }
                  }
                  string[] bestFragments = highlighter.GetBestFragments(new StandardAnalyzer(), fields[0], snippet.ToString(), 5);
                  item.Snippet = String.Join(SEARCH_RESULTS_SEPARATOR, bestFragments);
                  item.Snippet.TrimEnd(' ', '.');
                  item.Snippet += SEARCH_RESULTS_SEPARATOR;
                  result.Add(item);
              }
              searcher.Close();
              return result;
          }

    Then you need to use the custom manager in your custom provider or search result control.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Annie
    Annie avatar
    123 posts
    Registered:
    08 Apr 2009
    20 Oct 2011
    Link to this post
    Hi Ivan,

    Thank you. I have another question. how would I create the index? I want the users to create the index from the administration section

    Thanks,
    Annie
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Oct 2011
    Link to this post
    Hello Annie,

    If you add a custom provider it will appear in the UI.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
8 posts, 0 answered