Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Search in both topics(discussions) and comments

edited January 2008 in Vanilla 1.0 Help
Hi all, I'm customizing Vanilla. Already have done a lot of custimized work, but now I'm stuck with this. I need to customize the search option in such a way it will search both in comments and in topics(discussions). It should display results in the same way the "comment" search is displayed in this page. If the keyword(s) is(are) found in a discussion, then the 1st post text should be displayed in the results list. I have the SQL sentence to show these results; it's fairly trivial and easy. But I don't know how to use it. I've taken a look into the code and I see the search method has to be used for one of these classes: topic, comment or user. Do I have to create a new class, maybe called "all"? I don't see the point of this. Lots of work for a simple feature. I don't even know how to deal with the query class. My SQL query should have a subquery and a union. Can this be accomplished with it or should I make the query directly? As you can see, I'm a little lost with this. Any help will be greatly appreciated ;)

Comments

  • Noone?
  • If you already have the SQL query that works, then you could look to see how the LiveSearch add-on works. You could create a new add-on from it.
  • Hi, I investigated a bit before I saw Jim's post. I have something quite working replacing two classes. The biggest problem to me is pagination.
    Here is my draft.
  • Hi again and thanks for the feedback. I've taken a look to LiveSearch. In fact, I did that before posting here. The problem is that, as far as I've deduced by looking at the code, it searches in discussions, comments or users, depending on the context. I want to search BOTH in discussions and comments, at the same time. If the keyword is in a discussion, it should return its 1st comment. If it is in a comment, it returnts the comment itself... That's an easy SQL statement. But I don't know how to use it inside Vanilla. It uses classes Topic and Comment to launch their respective searches and there isn't an "All" class. The approach Grahack has taken seems more familiar to me. In fact, it is almost the same that I started coding (I made the modifications directly to the existing classes). The problem is... I don't know how to continue now. The logic between the different kinds of searches and how to add an "All" option seems fairly easy to me. But the hard part is where to put the queries and how to lanch them. I'm kind of lost with that. Anyway, thanks a lot for helping!
  • My approach is to use already existing search functions like GetDiscussionSearch() in the DiscussionManager and GetCommentSearch() in the CommentManager. It's a mess because of the pagination. Maybe some additions and substractions will do the job though from what I've done.

    Now if you have a working SQL query, I wonder if you implemented a pagination management within it, because you'll need to.
    What you could do is to replace my code in the constructor of MultiSearchForm
    }else if ($this->Search->Type == 'MultiSearch') { // ... }
    and build $this->Data and $this->DataCount with your own query using $this->Context->Configuration['SEARCH_RESULTS_PER_PAGE'], $CurrentPage and $this->Search, because that's what it's all about now I think. Then do a pretty results display in Render_NoPostBack() of MultiSearchForm.
This discussion has been closed.