Search on content type

Topics: Customizing Orchard, General
Mar 1, 2011 at 5:34 PM

Hi,

Is there a easy way to search based on content type? i.e. Blog Posts or Pages

Currently all indexed content types are returned.

Coordinator
Mar 1, 2011 at 6:38 PM

You can create your own search box and controller. Sort of custom Search module. You can even copy/paste the current implementation and enhance it as your whish.
You can add any filter you want by putting more constraints on the search query. Using the Search API il would be something like .WithField("type", "BlogPost")

 


Mar 28, 2011 at 3:12 PM

Hi,

I'm back onto this and have looked into what you recommended.

I have added the following: searchBuilder.WithField("type", "BlogPost").ExactMatch().AsFilter();

Which gets added to Lucene with the following Method:

public ISearchBuilder WithField(string field, string value) {
            CreatePendingClause();

            if ( !String.IsNullOrWhiteSpace(value) ) {
                _query = new TermQuery(new Term(field, QueryParser.Escape(value.ToLower())));
            }
            
            return this;
        }
The following fails becouse of the:

value.ToLower()

I have removed the ToLower in testing and have found that I can filter by "type" correctly.

Search filtering appears to be case sensitive, any idea how to override this?

Coordinator
Mar 29, 2011 at 6:16 AM

I have submitted a modification to the source code so that this field is also searchable. If you can't synchronize to the latest version (1.x), which by the way is not recommended, you should update the class Orchard.Core.Common.Handlers.CommonPartHandler with this line:

.Add("type"

, commonPart.ContentItem.ContentType).Analyze().Store()

  

 

Jul 21, 2014 at 5:49 PM
Hi,
now it is 2014, 3 years after this I see that code is still broken. value.ToLower() is still there and .WithField("type", "BlogPost") returns nothing...

Any chanches to be fixed?
Should add a bug to tracker?
Jul 21, 2014 at 5:54 PM
Issue submitted: https://orchard.codeplex.com/workitem/20818

I confirm that removing the lower allows types to be searched correctly.
I tolower is there searchBuilder.WithField("type", "BlogPost").ExactMatch().AsFilter(); returns always 0 results...
Jul 22, 2014 at 8:32 PM
Edited Jul 22, 2014 at 8:33 PM
i think we should use
.Add("type"

, commonPart.ContentItem.ContentType.ToLower() ).Store()

right now i use sth like
searchBuilder.WithField("type", "blogpost")
and in migration
use blogpost as content type
Aug 14, 2014 at 9:53 AM
Edited Aug 14, 2014 at 9:54 AM
workitem updated... I hope someone on team take it an fix it for next release.
If you need to index types please vote up the issue:
https://orchard.codeplex.com/workitem/20818