+ Start a Discussion
Adam FranklinAdam Franklin 

Knowledge Search in visualforce pages

Hi,

I'm working to identify some options around how to improve our knowledge search performance.

At the moment, our knowledge search is coming from a custom controller where the query seems to be something like this:
 
public PageReference searchArticle(){
    
        //Set<Id> articleIds = new Set<Id>();
            
        SearchArticlesByCategory sabc = new SearchArticlesByCategory();
    
        allArticlesBySearch = sabc.searchArticlesByCategory(artTypes, visibleCats, searchString, language, prefix, null);
        
        Integer listSize = allArticlesBySearch.size();
        
        Integer i;
        
        for (i = 0; i < listSize; i++){
        
            articleIds.add(allArticlesBySearch[i].Id);
        }
        
        articleListBySearch = [SELECT Title,UrlName,Summary FROM KnowledgeArticleVersion WHERE Id IN :articleIds AND Title LIKE :'%' + String.escapeSingleQuotes(searchString) + '%'];
        
        if(articleListBySearch.size() == 0){
        
            articleListBySearch = allArticlesBySearch;
        }
                
        CheckAttInArticle caia = new CheckAttInArticle();
        
        attInArticle = caia.checkAttInArticle(articleListBySearch, mapContainsAtt);
        
        setPageState(method_search, articleListBySearch.size());
        
        return null;
    }

I didn't write this code, but in researching the knowledge search functionality, I've learned that the native Salesforce Knowledge search offers a lot of value in terms of things like tf/idf relevancy, lemmatization, and synonym expansion.   I also know that the newest edition includes default and/or and search term highlighting.

What I'm working to figure out is :
  1. What could be done to improve our existing custom search controller?
  2. Does the search controller as outlined in the knowledge developers guide provide the functionality mentioned above?
  3. Are there any ways to embed the salesforce knowledge search in a custom page without using the knowledge tab or completely recoding?
  4. Would using the connect api and the getSuggestions class be a way to provide more 'instant' results and utilize SFDC's native search power?
Thanks!
Best Answer chosen by Adam Franklin
Sagar PareekSagar Pareek
Hi Adam,

Answers to your questions

1.You can use SOSL instead of SOQL to improve existing custom search controller 
 Example : Using  IN ALL FIELDS RETURNING in SOSL you can allow users to search across all articles having a particular keyword.

2.  Yes it provides. You can also try out searching on specific article type.
Example : You have FAQ article type , you try to search on FAQ__kav only.

3. You will need to create custom visual force page.

4.Not sure about this.
 

All Answers

Sagar PareekSagar Pareek
Hi Adam,

Answers to your questions

1.You can use SOSL instead of SOQL to improve existing custom search controller 
 Example : Using  IN ALL FIELDS RETURNING in SOSL you can allow users to search across all articles having a particular keyword.

2.  Yes it provides. You can also try out searching on specific article type.
Example : You have FAQ article type , you try to search on FAQ__kav only.

3. You will need to create custom visual force page.

4.Not sure about this.
 
This was selected as the best answer
Adam FranklinAdam Franklin
Hi Sagar, thanks for the answers.

I was aware of SOSL, which I would expect to return more results, but i think what we're working towards is how to return the best results.  

Can I confirm that for question #2, using the search controller designed in the knowledge developers guide would have the functionality to optimize search results based on relevancy, stemming, synonym expansion?    I ask because when looking through the controller's code, i'm not seeing that logic explicitly written out anywhere.  

I'm trying to understand why our search doesn't return good results and form a concrete proposal as to what we could do differently.

When I explore the connect api and the getsuggestions class a bit more, I will try to share my learnings with the community. 
Richard MillsRichard Mills
Hi Adam,

I am working on the same issue, did you find anything usefull in your research?
Adam FranklinAdam Franklin
Hi Richard,

My research led me to conclude that trying to reproduce the knowledge search through visualforce/apex doesn't really provide great results.    

I believe that the native knowledge search just has a lot of good features that can't easily be leveraged using a standard query.   I think that SFDC also utilizes Apache's SOLR search, which seems to return different results from the native search page.

My testing revealed a 30-80% discrepancy in results among the first 10 results returned.    Between that and losing some of the suggested search terms/article suggestion UX, I've encouraged our team to utilize the native knowledge search for now.

What seems to be the best route for customization, and the solution I'm pursuing for deflection, is to use the API and pass the queries through there to utilize Salesforce technology while presenting it in a custom shell.    With plugins like typeahead, you could probably get to a very good looking UI that has comparable results.