7

特定のフォルダー内のすべてのアイテムにインデックスを付けるために、非常に基本的な検索インデックスを設定しようとしています。私はあまり検索を使用していませんが、非常に単純な検索であるため、すぐに使用できる機能を使用しようとしています。すべてのフィールドにインデックスを付けたいだけです。サイトコアのドキュメントは実際には多くの情報を提供していません - 私はいくつかのブログを読みましたが、高度なデータベース クローラー ( http://trac.sitecore.net/AdvancedDatabaseCrawler ) が必要であることを示唆しているようです - 基本的には、 「カスタムクローラーなしでは機能しない」という効果)。

これは正しいですか?単純なインデックスを作成して、それを使い始めたいだけです。共有モジュールなどを使わずにこれを行う最も簡単な方法は何ですか? サイトコアのドキュメントを調べましたが、あまり明確ではありません (少なくとも私には)。web.config でインデックス構成のさまざまな要素を定義しますが、それらが何をするのか、どの値を使用できるのかについては実際には説明していません。多分私は正しい場所を見ていない..

4

4 に答える 4

15

Sitecoreで新しいLuceneインデックスを作成し、特定のノードの下にあるすべてのアイテムをわずか 3 ステップで作成する簡単な方法:

1:configuration/sitecore/search/configuration/indexes以下の構成をSitecore構成に追加します。

<!-- id must be unique -->
<index id="my-custom-index" type="Sitecore.Search.Index, Sitecore.Kernel">
  <!-- name - not sure if necessary but use id and forget about it -->
  <param desc="name">$(id)</param>
  <!-- folder - name of directory on the hard drive -->
  <param desc="folder">__my-custom-index</param>
  <!-- analyzer - reference to analyzer defined in Sitecore.config -->
  <Analyzer ref="search/analyzer" />
  <!-- list of locations to index - each of the with unique xml tag -->
  <locations hint="list:AddCrawler">
    <!-- first location (and the only one in this case) - specific folder from you question -->
    <!-- type attribute is the crawler type - use default one in this scenario -->
    <specificfolder type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel">
      <!-- indexing itmes from master database -->
      <Database>master</Database>
      <!-- your folder path -->
      <Root>/sitecore/content/home/my/specific/folder</Root>
    </specificfolder>
  </locations>
</index>

2:新しいインデックスを再構築します (一度だけ、それ以降の変更はすべて自動的に検出されます):

SearchManager.GetIndex("my-custom-index").Rebuild();

3:新しいインデックスを使用します。

// use id of from the index configuration
using (IndexSearchContext indexSearchContext = SearchManager.GetIndex("my-custom-index").CreateSearchContext())
{
    // MatchAllDocsQuery will return everything. Use proper query from the link below
    SearchHits hits = indexSearchContext.Search(new MatchAllDocsQuery(), int.MaxValue);
    // Get Sitecore items from the results of the query
    List<Item> items = hits.FetchResults(0, int.MaxValue).Select(result => result.GetObject<Item>()).Where(item => item != null).ToList();
}

これは、 Sitecore の検索とインデックス作成について説明している PDFです。

また、 Sitecore Lucene の検索とインデックス作成のトラブルシューティングに関するブログ記事はこちらです。

Lucene クエリ構文のチュートリアルはこちら

およびLucene.Net の紹介

于 2013-06-27T08:01:59.457 に答える
3

Sitecore Search Contrib (高度なデータベース クローラーの新しい名前) が最適なオプションです。アプリ構成フォルダーでその構成を構成して、パス データベースなどを開始するように指示するだけです。

その後、その API を使用して、特定のフィールドに特定の値が含まれるテンプレート タイプ別にフォルダ内を検索できます。コード例を次に示します。

MultiFieldSearchParam parameters = new MultiFieldSearchParam();

parameters.Database = "web";
parameters.InnerCondition =  QueryOccurance.Should;
parameters.FullTextQuery = searchTerm;        
parameters.TemplateIds = array of pipe seperated ID's

var refinements = Filters.Select(item => new MultiFieldSearchParam.Refinement(item.Value, item.Key.ToString())).ToList();

parameters.Refinements = refinements;

//実際の検索

var returnItems = new List<Item>();
var runner = new QueryRunner(IndexName);
var skinnyItems = runner.GetItems(new[] {parameters});
skinnyItems.ForEach(x => returnItems.Add(Database.GetItem(new ItemUri(x.ItemID))));
return returnItems;

それ以外の場合は、標準の lucene 検索用に web.config を構成し、このコードを使用して検索することができます。(「web」を利用するためのデータベース、スタートアイテムなど)

public Item[] Search(string searchterms)
        {
            var children = new List<Item>();

            var searchIndx = SearchManager.GetIndex(IndexName);

            using (var searchContext = searchIndx.CreateSearchContext())
            {
                var ftQuery = new FullTextQuery(searchterms);
                var hits = searchContext.Search(ftQuery);
                var results = hits.FetchResults(0, hits.Length);

                foreach (SearchResult result in results)
                {
                    if (result.GetObject<Item>() != null)
                    {
                        //Regular sitecore item returned       
                        var resultItem = result.GetObject<Item>();

                        if (ParentItem == null)
                        {
                            children.Add(resultItem);
                        }
                        else if (resultItem.Publishing.IsPublishable(DateTime.Now, false) &&
                                 ItemUtilities.IsDecendantOfItem(ParentItem, resultItem))
                        {
                            children.Add(resultItem);
                        }
                    }
                }
            }
            return children.ToArray();
        }
于 2013-07-01T15:03:39.230 に答える
-2

ブライアン・ペダーセンはそれについて素晴らしい記事を書いています。単純なクローラーから始めます。Advanced Database Crawler をダウンロードし、ビルド後にプロジェクトへの参照を追加する必要があります。

次に、Brian のブログに記載されている構成ファイルを作成し、そのままコピーする必要があります (テンプレート ID の n すべてを除く)。基本的にここで要点を理解します。

その後、Sitecore の Lucene Index Viewer 拡張機能をダウンロードしてインデックスを表示するか、Lucene ツールをダウンロードしてインデックスを表示できます。ドキュメント (インデックス内のファイル) を作成できるかどうかを確認します。これらはLuceneでは「ドキュメント」と呼ばれ、技術的には、これらのドキュメントは指定したノードの下にあるコンテンツ アイテムです。

お役に立てれば!

グーグルで検索してみましょう。

于 2013-06-27T19:51:32.510 に答える