tag:blogger.com,1999:blog-5251195438749660493.post7431877801576788621..comments2024-03-27T18:06:31.934-07:00Comments on Sitecore Gadgets: Working with Lucene Search Index in Sitecore 6. Part III - Code examplesIvanhttp://www.blogger.com/profile/09998430037866709466noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-5251195438749660493.post-76084649790323956082012-10-17T01:44:48.711-07:002012-10-17T01:44:48.711-07:00Currently it is a limitation in functionality of F...Currently it is a limitation in functionality of FullTextQuery type. It does not allow you to enable relevancy of coordinates of searched phrase.<br />I'd recommend you to go with standard Lucene methods for now to solve this challenge.<br />Thank you for bringing this up! I'll pass this to Sitecore devs as an enhancement for Lucene search integration.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-1924850436261108012012-10-03T07:22:17.252-07:002012-10-03T07:22:17.252-07:00so when I try to use the FullTextQuery - It seems ...so when I try to use the FullTextQuery - It seems the query is executed by an OR operator. How can I force an AND operator? e.g. If I search for "Dora the Explorer" - it brings results that have any of the above results and some of them are extremely irrelevant. <br /><br />The original Lucene QueryParser class has a function for this SetDefaultOperator(QueryParser.Operator.AND)but I don't know how can we do this using Sitecore API<br /><br /><br />DQnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-1874043342659377682012-09-21T06:47:11.954-07:002012-09-21T06:47:11.954-07:00Yes, you're correct. Sitecore adds prefix quer...Yes, you're correct. Sitecore adds prefix query on item name every time when you search by BuiltinFields.Content field using TermQuery and calling to IndexSearchContext.Search() method.<br />If you want to avoid this, just call to Lucene native search methods.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-11644411085440094752012-09-21T02:15:07.517-07:002012-09-21T02:15:07.517-07:00Hi,
I am using the following piece of code to sea...Hi,<br /><br />I am using the following piece of code to search for a user typed text: <br /><br />BooleanQuery query = new BooleanQuery();<br /> <br /> query.Add(new TermQuery(new Term(BuiltinFields.Content, searchString)), BooleanClause.Occur.MUST);<br /><br />but somehow I get more results than those returned when I use the Index viewer search option for my index. It looks like it is returning even items of which names contain the searched word. Any idea why could be this happening?<br /><br />Thank you.<br /><br />Aura P.Anonymoushttps://www.blogger.com/profile/08634834890323714994noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-9905925046903913922011-12-21T12:01:49.588-08:002011-12-21T12:01:49.588-08:00Try to use Luke tool to see if there is a value fo...Try to use Luke tool to see if there is a value for your droplink in the index. If it's not there check whether the field type is registered in /App_Config/FieldTypes.config file. If not, add it.<br />It's possible that a raw ID gets written into the index. Then you either would search by raw ID which has a lot of pitfalls or use Advanced Database Crawler to index it in an appropriate format.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-65583113911802829652011-12-20T08:49:29.986-08:002011-12-20T08:49:29.986-08:00Having trouble still querying on a droplink field....Having trouble still querying on a droplink field. I expect the value to be a GUID, so I'm doing a fieldquery on the field and have tried multiple combinations of values: shortID, shortID ToLowerInvariant, ToLowerInvariant, etc. I still get no matches. (Yes, I've re-indexed.) What am I doing wrong?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-90766100807561820992011-12-05T18:21:57.827-08:002011-12-05T18:21:57.827-08:00Hi Maulik,
To combine Range query with other type...Hi Maulik,<br /><br />To combine Range query with other types of queries, you have to use Lucene BooleanQuery. There you can combine different types of queries. To search for items under specific branch of Sitecore content tree, I would suggest to use BuiltinFields.Path field.<br />Also consider using AdvancedDatabaseCrawler component as a main Lucene integration. It extends default Sitecore DatabaseCrawler with very useful features. Here the link: http://trac.sitecore.net/AdvancedDatabaseCrawlerIvanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-69948746822839843212011-12-03T12:37:53.083-08:002011-12-03T12:37:53.083-08:00Hi Ivan,
This is really a great Article.
Sitecore...Hi Ivan,<br />This is really a great Article.<br /><br />Sitecore Support suggested this article to me. I have implemented Lucene Index on CE using this article. Its working great.<br />And it gets the results quickly too.<br /><br />I have a query regarding Range.<br />Can you help me in my query.<br /><br />I want to find items below specific path(I can Achieve using 7) and from that list I want to find items which are updated in last month.<br /><br />Range Query does not work with Combined query. so I am stuck.<br /><br />Can you help me out.Maulikhttps://www.blogger.com/profile/03868995847182919938noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-81582702966543585272011-10-13T05:28:06.108-07:002011-10-13T05:28:06.108-07:00Hi Evan,
Thanks for all your help.
Using Luke i...Hi Evan,<br /><br />Thanks for all your help. <br /><br />Using Luke i found that _links was not returning any hits, which lead me to proper direction and finally i got search returning proper data.<br /><br />Once again thanks for your help :)<br /><br />Regards,<br />AzzyAzzynoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-84523592092515895222011-10-07T08:56:56.627-07:002011-10-07T08:56:56.627-07:00Can you check if SourceFieldID for those records i...Can you check if SourceFieldID for those records in Links table matches your TreelistEx field. If it does, try to research your Lucene query. Use Luke to construct and execute the query to see if it returns any hits. Try to search just "_links" field for a targeting marketid.<br />When you rebuild link database check the log file to see if any related errors get registered.<br />You can also use Luke to see if there are any values in _links field for the item.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-73908424744451947152011-10-06T23:11:30.989-07:002011-10-06T23:11:30.989-07:00Hi Ivan,
Yes there is entry for TreeListEx in fiel...Hi Ivan,<br />Yes there is entry for TreeListEx in fields.config file<br />and Links database returns few records when i execute query.<br /><br />Select * from Links where SourceItemID='ITEMIDHERE' <br /><br />My Link database points to Core database and there are records in Links table in core database.<br /><br />am i missing any other configuration?<br /><br />Regards,<br />AzzyAzzynoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-14706280411778632172011-10-05T13:16:57.752-07:002011-10-05T13:16:57.752-07:00Azzy,
First make sure that TreelistEx is listed in...Azzy,<br />First make sure that TreelistEx is listed in the /App_Config/FieldTypes.config file.<br />If it's there, check if there are entries for the item in Link database. The "_links" field gets populated out of LinkDatabase API. If there are no entries in Links table for that item, they won't appear in index "_links" field.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-29615882784358881152011-10-04T23:24:16.701-07:002011-10-04T23:24:16.701-07:00Hi,
I am trying to find references to particular ...Hi,<br /><br />I am trying to find references to particular item using _links, but it does not return any data.<br /><br />We have items(products) related to an item(market segment) through TreeListEx.<br /><br />I am trying to find all products related to market segment using _links as you suggested.<br /><br /><br />BooleanQuery mainquery = new BooleanQuery();<br /> mainquery.Add(new TermQuery(new Term("_content", searchString)), BooleanClause.Occur.MUST);<br /><br />BooleanQuery marketquery = new BooleanQuery();<br />marketquery.Add(new TermQuery(new Term(BuiltinFields.Links, ShortID.Encode(marketid).ToLowerInvariant())), BooleanClause.Occur.SHOULD);<br />mainquery.Add(marketquery, BooleanClause.Occur.MUST);<br />SearchHits hits = context.Search(mainquery);<br /><br />But i dont get any result.<br />I also rebuild Link Database then rebuild the search indexes.<br /><br />any idea?<br /><br />Thanks,<br />AzzyAzzynoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-16766813631777740002011-08-26T11:03:02.988-07:002011-08-26T11:03:02.988-07:00Larry,
When you rebuild indexes all item versions...Larry,<br /><br />When you rebuild indexes all item versions in all languages get indexed. When you save/remove a specific item version, only that version gets indexed.<br />Try to use Luke to see all indexed languages in your index. I'm sure your Spanish language is in there.<br />One thing that I can think of is a language region that gets added to language name through dash, e.g. "es-MX". Indexed value of this language will be "es-mx". That dash could cause a problem for StandardAnalyzer which replaces dashes with space character. Thus you cannot match the value when you search by the language name.<br />If you use AdvancedDatabaseCrawler module, you can solve this issue by making the Lucene "_language" field as TOKENIZED. Otherwise you will have to customize DatabaseCrawler to reformat the field value.<br />Another possible solution could be to escape dash character by prefixing it with '\' one. The search value should look like this: "en\-mx". It should work if StandardAnalyzer let it go through. I haven't tested it though.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-75108908542925065492011-08-25T13:01:20.814-07:002011-08-25T13:01:20.814-07:00Is there anything special you have to do to get th...Is there anything special you have to do to get the language versions indexed? I have both English and Spanish versions of content, but when I run:<br /><br /> CombinedQuery cq = new CombinedQuery();<br /> cq.Add(new FieldQuery(BuiltinFields.Language, Sitecore.Context.Language.Name), QueryOccurance.Must);<br /><br /> SearchHits hits = context.Search(cq);<br /><br />I get results for English, but none for Spanish. Looking at the index with the IndexViewer shared source module, it doesn't look like the Spanish versions are actually being indexed.Chris Bernardhttps://www.blogger.com/profile/11934898366908653458noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-24607135352784561132011-03-21T11:53:52.639-07:002011-03-21T11:53:52.639-07:00Could you rephrase the question. I'm not quite...Could you rephrase the question. I'm not quite sure what you mean by: "...you needed to add the index in the node of the database."Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-82078649952762001612011-03-21T09:31:19.847-07:002011-03-21T09:31:19.847-07:00in the old method of lucene index you needed to ad...in the old method of lucene index you needed to add the index in the node of the database. Do you still have to do this:Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-49409944940916436952010-12-19T12:59:04.087-08:002010-12-19T12:59:04.087-08:00Try to use your main query as MUST one and then ad...Try to use your main query as MUST one and then add a BooleanQuery with SHOULD option that would include other SHOULD queries.<br />Something like this:<br />BooleanQuery mainQuery = new BooleanQuery();<br />mainQuery.Add(new TermQuery (new Term (*field*, *value*)), BooleanClause.Occur.MUST);<br />BooleanQuery subQuery = new BooleanQuery();<br />subQuery.Add(new TermQuery (new Term (*field*, *value*)), BooleanClause.Occur.SHOULD);<br />subQuery.Add(new TermQuery (new Term (*field*, *value*)), BooleanClause.Occur.SHOULD);<br /><br />// Add subQuery to the main one.<br />mainQuery.Add(subQuery, BooleanClause.Occur.SHOULD);Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-74009343760717794522010-12-13T13:44:45.847-08:002010-12-13T13:44:45.847-08:00Hi Ivan
This might be more of a Lucene question th...Hi Ivan<br />This might be more of a Lucene question than Sitecore.<br /><br />Am searching for items using _links as you suggested and it works great when finding items linking to one particular item.<br /><br />For that I create a field query and add it to my base query:<br /><br />QueryBase tagQuery = new FieldQuery (BuiltinFields.Links, ShortID.Encode(categoryId).ToLowerInvariant());<br /> query.Add(tagQuery, QueryOccurance.Must);<br /><br />Am having trouble when trying to find items that might be linked to any of the items given a list of items. So basically I want to do an OR query.<br /><br />If I use the above code and keep adding queries with Query Occurence of MUST then the results are only items linking to all the categories.<br /><br />I tried SHOULD but it seems to return wrong results. Is there a way to do an OR? Or should I search multiple times and then consolidate the results?<br /><br />Thanks.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-1090895792260432112010-09-21T00:47:31.545-07:002010-09-21T00:47:31.545-07:00Hi Ivan,
Thanks for your great articles on the ne...Hi Ivan,<br /><br />Thanks for your great articles on the new Lucene search in sitecore, they seem to be the only documentation at the moment :)<br /><br />I think i have the same issue as Asif.<br />When I search with the Shared Source component “Index Viewer” I can find records for a search on id. When I do the same with the Sitecore Search API I can’t find these records. Also when I try to give a PrefixQuery (from Lucene API) to the search context this does not work. In my example Residence Type is a treelist field.<br /><br />//Old way does return results<br />Term term = new Term("residence type", "{B0D17C71-8FAA-4D5D-B87E-C7BBD93AEF69}");//b0d17c718faa4d5db87ec7bbd93aef69<br />PrefixQuery rd = new PrefixQuery(term);<br />Hits hits = context.Searcher.Search(rd);<br /><br />//No results with the new way<br />SearchHits results = context.Search(rd);<br /><br />Another one is related to the Link Database. This should be filling the Lucene field “_links” indeed. But I’ve seen that when you’re using a source like this on your sitecore field:<br />“DataSource={0AFABE4C-7C24-4468-8250-12CD7BE8B405}&IncludeTemplatesForSelection=ListValue” this isn’t updating the link database. Adding DatabaseName mostly does the trick to get this solved, like so:<br />“DataSource={0AFABE4C-7C24-4468-8250-12CD7BE8B405}&IncludeTemplatesForSelection=ListValue&DatabaseName=master”. Feature request: IncludeTemplatesForSelection is still not able to work with id’s! :)<br /><br />TomTomnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-230954540425377822010-08-19T19:06:10.717-07:002010-08-19T19:06:10.717-07:00You should use _links field (Builtin.Links) for th...You should use _links field (Builtin.Links) for that. It has all the reference to an item. References stored in ShortID format.<br />Values of standard Sitecore fields, that contain references to other items, get indexed into the _links field.<br />If it cannot find the value for some reason, try to rebuild Link Database and then rebuild your search indexes.<br />Another reason why it can happen is if you use custom field and forgot to add it to /App_Config/FieldTypes.config file.<br /><br />Here is a query example:<br />FieldQuery(Builtin.Links, ShortID.Encode("4C174B16-7193-49A7-88C6-7F696003F8BF").ToLowerInvatiant());Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-8391108064928522212010-08-19T13:39:05.239-07:002010-08-19T13:39:05.239-07:00Thanks for that.
One more question regarding searc...Thanks for that.<br />One more question regarding search items linked to the current one.<br /><br />It seems that the _links field only provides items that have a link to the current item using a droplink for example.<br /><br />We have items "tagged" with other items using a multilist. When I search content tagged with a particular item I want to get all items that have the current item in the "Tag" field which is a multilist.<br /><br />Tried the following 2 without any results but when I do the same in the Index Viewer using a Term Query it returns the correct result. Any thoughts?<br /><br />QueryBase tagQuery = new FieldQuery("tag", "{4C174B16-7193-49A7-88C6-7F696003F8BF}");<br /> QueryBase tagQuery = new FieldQuery("tag", ShortID.Encode(new Guid("4C174B16-7193-49A7-88C6-7F696003F8BF")).ToLowerInvariant());Asif Maniarnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-46064409513298621082010-08-19T12:51:18.212-07:002010-08-19T12:51:18.212-07:00Language.Name is basically the name of language it...Language.Name is basically the name of language item in the content tree.<br />By default English has name as "en" but not "en-US".<br />If you want to search by ISO code, you need to add a custom field that would store ISO code of the language.<br />Then you could search by the culture.Ivanhttps://www.blogger.com/profile/09998430037866709466noreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-73746987663051433112010-08-19T11:25:08.983-07:002010-08-19T11:25:08.983-07:00When I use the Language.Name and the current conte...When I use the Language.Name and the current context is a specific culture like en-US then the search returns nothing. It seems that the language is indexed by the 2 letter language code but not the culture is that right?<br /><br />I was able to get this to return results for each culture:<br />QueryBase langQuery = new FieldQuery(BuiltinFields.Language, Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName);<br /><br />The only problem is that this will return all items in the current language not just the current culture. Any work around for this?Asif Maniarhttp://www.asifmaniar.comnoreply@blogger.comtag:blogger.com,1999:blog-5251195438749660493.post-34056970720574384392010-08-18T11:27:33.592-07:002010-08-18T11:27:33.592-07:00Thanks Ivan!Thanks Ivan!Asif Maniarnoreply@blogger.com