在结果中禁用Lucene类似术语

时间:2012-02-15 15:54:03

标签: .net lucene.net sitecore

我正在使用QueryParser在Sitecore中进行Lucene搜索:

        var index = Sitecore.Context.Database.Indexes["intranet"];

        IndexSearcher searcher = index.GetSearcher(Sitecore.Context.Database);            

        Analyzer analyzer = new StandardAnalyzer();


        var qp = new QueryParser(Sitecore.Data.Indexing.Index.ContentFieldName, 
        analyzer);
        qp.SetAllowLeadingWildcard(true);
        qp.SetDefaultOperator(QueryParser.Operator.AND);            

        Query query = qp.Parse(AddQueryOptions(_searchString));            

        Hits hits = searcher.Search(query);                

        return hits;

但是当我正在搜索“Lead”的例子时,它返回带有“Lede”的条款。我可以在Lucene中禁用类似的术语搜索吗?

这是由QueryParser解析的字符串:

+_content:(lead*) _scLang:(da) NOT template:(B07B9306-227B-4DAE-884C-1FD6CF0C1282) NOT template:(89010281-856E-4464-9D52-EAD45039CACD) NOT template:(EE1DC6A2-74F9-44BE-8C41-859688165A51) NOT template:(7B721B9A-BC29-4144-A475-75AFA75F8673) NOT template:(6178A424-8B72-4446-B8D7-B919D4D30858) NOT template:(239F9CF4-E5A0-44E0-B342-0F32CD4C6D8B) NOT template:(7B99D81B-64F3-4F12-969D-1B04E4EB2F9C) NOT template:(80B63A22-F5FF-451F-9B63-FEA7E1D156ED) NOT template:(B4A2AD96-AD32-479D-B0A5-11C020A121A5) NOT template:(ADD5F473-C3C5-4671-8CDD-8C039F81EF63) NOT template:(2B225B41-7F2B-4E71-8F46-CD8FDA221975) NOT template:(DF9B3CE7-D33B-48DC-B26F-ACAF9A2C52C0) NOT template:(32F62D22-FCED-47FF-A582-E63551971B54) NOT template:(6BFBE266-F09E-4E33-BF55-094426AFCF47) NOT template:(E96EE51E-9DC8-4ACC-8206-538B72BF4EE4) NOT template:(ADD5F473-C3C5-4671-8CDD-8C039F81EF63) NOT template:(2B231428-1423-43B4-8D8F-DC0DFCEE8E21) NOT template:(93602B62-FEB7-4FDA-B975-8CDF1CA01010) NOT template:(71B30489-A719-4EC0-9103-EDCD8CF7C9D9) NOT template:(71B30489-A719-4EC0-9103-EDCD8CF7C9D9) NOT template:(E96EE51E-9DC8-4ACC-8206-538B72BF4EE4) NOT template:(3B8B970C-827A-47DF-9B7D-C0C8B2F70CD3) NOT template:(F837225B-385D-44D0-A96D-07DF92912370) NOT template:(DD1BB9E6-46F8-43E1-816C-2D3552F12944) NOT template:(C3B737DC-AB69-43E5-AA41-4E48E25607BB) NOT template:(5E7CFA06-8CC8-4EA1-B280-A81489363935) NOT template:(71B30489-A719-4EC0-9103-EDCD8CF7C9D9) NOT template:(A87A00B1-E6DB-45AB-8B54-636FEC3B5523) NOT template:(BD951C72-BEE4-46CE-8C5B-90DBF4248D67) NOT template:(48D82A9A-C8C8-4378-925F-414FF90485A7) NOT template:(155AD61E-D577-4895-B6D9-3B43F22EF5A6) NOT template:(3C20E6F2-BAFD-4F79-81FE-DC002572C8C7) NOT template:(3C6C9586-4997-49C4-BC86-06EA67467369) NOT template:(85590530-1D1B-483D-B9C3-C28C5973EF8A)

这是由QueryParser查询字符串生成的:

+_content:lead* +_scLang:da -template:b07b9306-227b-4dae-884c-1fd6cf0c1282 -template:89010281-856e-4464-9d52-ead45039cacd -template:ee1dc6a2-74f9-44be-8c41-859688165a51 -template:7b721b9a-bc29-4144-a475-75afa75f8673 -template:6178a424-8b72-4446-b8d7-b919d4d30858 -template:239f9cf4-e5a0-44e0-b342-0f32cd4c6d8b -template:7b99d81b-64f3-4f12-969d-1b04e4eb2f9c -template:80b63a22-f5ff-451f-9b63-fea7e1d156ed -template:b4a2ad96-ad32-479d-b0a5-11c020a121a5 -template:add5f473-c3c5-4671-8cdd-8c039f81ef63 -template:2b225b41-7f2b-4e71-8f46-cd8fda221975 -template:df9b3ce7-d33b-48dc-b26f-acaf9a2c52c0 -template:32f62d22-fced-47ff-a582-e63551971b54 -template:6bfbe266-f09e-4e33-bf55-094426afcf47 -template:e96ee51e-9dc8-4acc-8206-538b72bf4ee4 -template:add5f473-c3c5-4671-8cdd-8c039f81ef63 -template:2b231428-1423-43b4-8d8f-dc0dfcee8e21 -template:93602b62-feb7-4fda-b975-8cdf1ca01010 -template:71b30489-a719-4ec0-9103-edcd8cf7c9d9 -template:71b30489-a719-4ec0-9103-edcd8cf7c9d9 -template:e96ee51e-9dc8-4acc-8206-538b72bf4ee4 -template :3b8b970c-827a-47df-9b7d-c0c8b2f70cd3 -template:f837225b-385d-44d0-a96d-07df92912370 -template:dd1bb9e6-46f8-43e1-816c-2d3552f12944 -template:c3b737dc-ab69-43e5-aa41-4e48e25607bb -template:5e7cfa06-8cc8-4ea1-b280-a81489363935 -template:71b30489-a719-4ec0-9103-edcd8cf7c9d9 -template:a87a00b1-e6db-45ab-8b54-636fec3b5523 -template:bd951c72-bee4-46ce-8c5b-90dbf4248d67 -template:48d82a9a-c8c8-4378-925f-414ff90485a7 -template:155ad61e-d577-4895-b6d9-3b43f22ef5a6 -template:3c20e6f2-bafd-4f79-81fe-dc002572c8c7 -template:3c6c9586-4997-49c4-bc86-06ea67467369 -template:85590530-1d1b-483d-b9c3-c28c5973ef8a

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试使用术语查询

Term term = new Term ( "field" , "searchstring" );
Query q = new TermQuery (term);

可能您的字段是“内容”或“_内容”。 使用IndexViewer查看字段