Gravatar for

Question by dwebb, Dec 8, 2014 10:08 PM

Using the Searchbox to refine a programmatically-filtered query

Hi - I am building a web page using the Search View (MVC) component. This page returns a filtered list of results (it is only showing News Release pages). Since I am using the free version of Coveo for Sitecore, I do not have access to the rules engine, so I am using the programmatic way of injecting template id filtering into the query (using the args.queryBuilder.constantExpression.add() method as described in this article:

Now my analyst has asked if we can enable the OmniBox on the page so that the users can "refine" their search with a keyword - so when the user clicks the search button, I want the components to combine my template id filtering in the javascript code with the keyword(s) entered in the search box.

When I try this, the search results consistently says "Your query did not match any documents", even if I enter a word that is in the search results. Looking at the query logs in the CES Admin tool, it appears that the search component is not appending my keyword query to the constant expressions defined programmatically, but is issuing just the keyword query.

Is there a way to do this?

Cheers David

Gravatar for

Comment by dwebb, Dec 9, 2014 2:17 AM

Update: I used Fiddler to trace the original query with nothing in the search box (which works) and the query with text in the search box (which doesn't).

The original query has an "aq" parameter (which contains filtering to exclude buckets and media folders -- this must be OOTB as I didn't add this). It also has a "cq" parameter which I set up to include only the template id I want to get back, and to exclude the __Standard Values item.

The second query is exactly the same except that it has a q= at the start of the query. Otherwise everything is exactly the same.

Gravatar for

Comment by Jean-François L'Heureux, Dec 9, 2014 8:59 AM

Do you really have markup as the value of the q parameter? You should have q=search keywords without markup.

Gravatar for

Comment by dwebb, Dec 9, 2014 10:47 AM

No, that was my mistake. The actual value is something like q=test.

1 Reply
Gravatar for

Answer by Martin Laporte, Dec 9, 2014 3:08 AM

What you describe seems perfectly normal (user query ending in q= and your constant filter in cq=). Those are combined inside the index.

Can you validate that the filter you put in cq= effectively matches some items? What happens if you replace it with @uri (this is an expression that matches everything)?

Gravatar for

Comment by dwebb, Dec 9, 2014 10:50 AM

Yes, the cq by itself is fine. Without the q=test, I get back 28 documents, which is exactly what I'm expecting.

I created an OOTB Coveo search results page and tried searching for the page titles (like "water course") -- these are what I'm putting in the search box, and therefore into the q= parameter.

When I do that, I get no matches. It looks to me like my custom page title isn't getting searched - although when I look at the CES Admin tool, I can see that the documents have the correct values in those fields.

Why would that field be crawled but not searched?

Gravatar for

Comment by dwebb, Dec 9, 2014 11:21 AM

Update - actually NONE of my custom fields on the page are matching the q= query. I have several custom page fields (document abstract, document title, document number) and if I put those terms in the search box, I do not get a match. The only field that consistently matches is the page "name" - the last part of the URL.

However, the CES Admin tool shows that the indexed documents all have the correct values in those fields, so the indexing process is working. The problem is that those fields are not matching when I do a search against their contents.

Gravatar for

Comment by Vincent Séguin, Dec 9, 2014 11:46 AM

It means your fields are not configured as free text searchable. In the fieldMap on your Coveo.SearchProvider.config, there's an attribute name includeForFreeTextSearch that you can set to true and then reindex your related items.

More info can be found here :'s+Configuration+File

Gravatar for

Comment by dwebb, Dec 9, 2014 3:20 PM

Thanks, Vincent. I configured the field for free-text search, and it now works correctly.

Just out of curiosity - Sitecore includes a checkbox on all its field templates named "Exclude From Text Search - Turn on to ignore the contents of this field in the full text search index".

For this field, this box is NOT checked. I assumed that this field would therefore be included in free text search.

Does Coveo for Sitecore ignore this attribute? Does it look only at the definition of the field in the fieldMap?

Cheers David

Gravatar for

Comment by Vincent Séguin, Dec 9, 2014 3:21 PM

Hi David,

Coveo for Sitecore ignores this attribute, it only looks in the field map.

Gravatar for

Comment by Dan Cruickshank, Dec 10, 2014 9:51 AM

David - in my experience the "exclude" and "include" checkboxes on field templates are only used by Sitecore when searching and displaying results inside the content editor using the search tab.

Ask a question