• Gamers

    So, let's say I create a new Topic, and set as tag for that topic "development" . In the title and in the body I don't write the word "development'.

    If I search 'development' that topic wont appear in the results.

    How can I make it that the search results also searches in the tags, or how can I make the tags to be indexed so the search finds that topic?

  • NodeBB

    Once https://github.com/NodeBB/NodeBB/issues/9976 is done you can do something like below using filter:search.query

    myPlugin.filterSearchQuery = async (hookData) => {
    		if (hookData.index === 'topic') {
    			// split the search term into multiple tags 
    			const tags = String(hookData.content).split(' ');
    			
    			const tidsArray = await Promise.all(tags.map(async (tag) => {
    				// for each tag get the topics tagged by it
    				if (hookData.cids.length) {
    					return await Topics.getTagTidsByCids(tag, hookData.cids, 0, -1);
    				}
    				return await Topics.getTagTids(tag, 0, -1);
    			}));
    			hookData.ids = hookData.ids.concat(_.uniq(_.flatten(tidsArray)));
    		} 
    		return hookData;
    	};
    

    This will include all topics tagged by your search query in the results of the actual search. However this won't work until we close the above issue.

  • Gamers

    @baris another "solution" / hack I though is this:

    to hook into the post save action/filter , and add at the end of the body of the post a div or parragraph like this

    '<p class="list-of-tags">tag1, tag2, tag3</p>'
    

    and hide by css this element

    this way the search engine may index the tags, right?

  • NodeBB

    Yeah if you put the tags in the content of the posts they will get indexed and search should find them, keep in mind the body of the posts are searched when you search in "posts" so if you are only searching for titles they wont show up.

Suggested Topics

| |