업데이트Sitecore 7 Linq에 분류 스타일의 쿼리
잘 내 구성, 난 sitecore하여 contentsearch 정의에서 defaultindexconfiguration를 사용하여 다시 바로 작동하지 복귀했다 밝혀졌습니다.
일단 내가 그렇게하면 모든 것이 마술처럼 작동합니다. 방금 템플릿 조건을 쿼리에 추가했는데 모두 좋았습니다.
2 일 동안 내 머리를 두드리는 소리가 들렸습니다.
시나리오 :
나는 나무/multilist의 항목에 태그 된 기사가있다.
특정 서식 파일 유형에 대해 내 사이트 전체를 살펴본 다음 일부 값 (이름, 설명, 경로, 태그)을 저장하도록 색인이 정의되어 있습니다. 이 인덱스는 작은 indexConfiguration을 사용합니다. 나는 인덱스가 너무 많아서 기본 인덱스 구성을 피하고 있습니다. 단지 슬림 한 결과 만 필요합니다.
<myConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneSearchConfiguration, Sitecore.ContentSearch.LuceneProvider">
<defaultIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<indexAllFields>true</indexAllFields>
<Analyzer ref="contentSearch/configuration/defaultIndexConfiguration/analyzer" />
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="Article Tags" storageType="yes" indexType="tokenized" vectorType="no" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
<field fieldName="Teaser Title" storageType="yes" indexType="tokenized" vectorType="no" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
<field fieldName="Teaser Description" storageType="yes" indexType="tokenized" vectorType="no" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
<field fieldName="Article Date" storageType="yes" indexType="tokenized" vectorType="no" boost="1f" type="System.DateTime" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
<field fieldName="Views" storageType="yes" indexType="tokenized" vectorType="no" boost="1f" type="System.Int32" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
<field fieldName="__Workflow state" storageType="yes" indexType="untokenized" vectorType="no" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
</fieldNames>
</fieldMap>
<fields hint="raw:AddComputedIndexField">
<field fieldName="isfinal" storageType="yes" indexType="tokenized">Core.Search.ComputedWorkflowState, Core</field>
<field fieldName="Teaser Image" storageType="yes" indexType="tokenized">Core.Search.ComputedTeaserImage, Core</field>
<field fieldName="Article Url" storageType="yes" indexType="tokenized">Core.Search.ComputeUrl, Core</field>
</fields>
<include hint="list:IncludeTemplate">
<articlePage>{28432890-0F71-4E2F-8577-7848F90FCBCC}</articlePage>
</include>
</defaultIndexConfiguration>
</myConfiguration>
루크를 사용하여 색인을 보면 태그가 올바르게 색인 된 것을 볼 수 있습니다. 각 태그는 문서에서 고유 한 행을가집니다.
SearchResultItem을 확장하는 클래스 (ArticleItem)를 만든 다음 적절한 속성을 decoration로 구현했습니다.
[IndexField("article_tags")]
public List<ID> tags{get;set;}
이제 sitecore linq 및 조건부 작성기를 사용하여 쿼리를 작성하려고합니다. 내가 그 자체로 context.GetQueryable()를 호출 할 때
using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
{
IQueryable<ArticleItem> query = context.GetQueryable<ArticleItem>();
var predicate = PredicateBuilder.True<ArticleItem>();
foreach (var id in tags)
{
var tempTerm = id;
predicate = predicate.Or(p => p.Tags.Contains(id));
}
var results = context.GetQueryable<ArticleItem>().Where(predicate).GetResults();
if (results != null)
{
if (results.Hits.Any())
{
return results.Hits.Select(x => x.Document);
}
}
}
, 그 결과를 반복, 태그는 모든 존재, 확실히 일치있다.
내가 잘못 설정 했습니까? 추가 쿼리와 검색 테스트
* 자세한 내용은
: 항목이 문자가 포함 된 GUID로 확실히있다 (결과를 반환 나던 p.Tags.Contains ("3") 3.
루크를 통해 볼 때 문서 태그내 termcount은 0입니다. 계산 필드에 필드를 돌려
내 검색 결과는 이제 (값 대신 토큰 화되는 전체 문자열로 저장되어 있지만) 노력하고 있습니다 기간 카운트가 표시됩니다.
제이의 조언 주셔서 감사합니다. 문자 3 (guid에 char 3이있는 여러 개의 태그가 있음)을 사용하고 반환 유형을 문자열로 변경하여 테스트했습니다. query.Where (i => i [ "article_tags"]. 포함 ("3")); 아무 것도 반환하지 않습니다. 결과 자체를 보면 완벽하게 모든 값을 얻을 수 있습니다. – munsense