ElkArte Community

Project Support => Support => Topic started by: Atlas on May 17, 2017, 04:39:38 am

Title: total number of search results (prior to pagination)?
Post by: Atlas on May 17, 2017, 04:39:38 am
This gives me the count AFTER pagination is applied...
Code: [Select]
count($context['topics'])

Is the total already available or will it require a SQL edit? Something like...
Code: [Select]
COUNT(*) AS [icode]total_count[/icode]


thanks
Title: Re: total number of search results (prior to pagination)?
Post by: emanuele on May 17, 2017, 08:55:41 am
I guess you want it in the template, right?
It is not passed there.
With some tricks you could extract an approximation from the paginations, but to get the exact number of results, you have to edit Search.controller.php and assign the value of $num_results to an index in $context.
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 17, 2017, 10:04:29 am
Thank you, sir. Yep, i had that idea too and have already extracted the last-page number from $context['page_index'] for another reason, i could get the approximation with that and the setting for "Number of search results per page", but this is for a semantic value so i want to be accurate. So, yep, i'm on it next.

I decided to go ahead and share this link with you.

Here's my test link for a "search results page" which is now a schema:SearchResultsPage
https://rule34.us/ontology/requests/index.php?action=search;sa=results;search=te;start=0

You can validate the semantics with Google's Structured Data Testing Tool (https://search.google.com/structured-data/testing-tool/u/0/#url=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dte%3Bstart%3D0) and the W3C's RDFa Validator (https://www.w3.org/2012/pyRdfa/extract?rdfa_lite=false&vocab_expansion=false&embedded_rdf=true&validate=yes&space_preserve=true&vocab_cache_report=false&vocab_cache_bypass=false&uri=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dth)

I've also changed the html, see the revised headings via the
W3C's HTML Validator (https://validator.w3.org/nu/?showoutline=yes&doc=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dth%3Bstart%3D2).

Title: Re: total number of search results (prior to pagination)?
Post by: emanuele on May 17, 2017, 12:51:56 pm
How do you calculate the relevance? :D
Title: Re: total number of search results (prior to pagination)?
Post by: live627 on May 17, 2017, 07:57:08 pm
Table: elkarte_log_search_results has a relevance column :D
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 17, 2017, 11:59:58 pm
re: relevance
I was surprised it wasn't output to the search-results page already. I'm going to go back to this and expose the search-weight settings as well. That info would be, um, relevant to the semantic value for the
schema:SearchAction (https://schema.org/SearchAction)'s query (https://schema.org/query) property's -output constraints (https://schema.org/docs/actions.html#part-4).
Title: Re: total number of search results (prior to pagination)?
Post by: emanuele on May 18, 2017, 04:58:34 am
Search is Spuds' domain. xD
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 19, 2017, 12:36:51 pm
(idk if you want this post here or elsewhere but it's related to this work)
Here's a search example returning both a
Topic and a Reply (https://search.google.com/structured-data/testing-tool/u/0/#url=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dreply). The missing datePublished is for the Reply's parent, a Topic. So that's another hack needed.
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 19, 2017, 01:13:52 pm
and this is how we fail query too short (https://search.google.com/structured-data/testing-tool/#url=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dr)
Title: Re: total number of search results (prior to pagination)?
Post by: Spuds on May 19, 2017, 02:01:10 pm
Good stuff ... I think adding Structured Data would be a very good thing to do in 2.0.

I've dabbled with it, but only using ld+json output in the templates, and then only for the topic listing, never considered getting in to the other templates such as search.  What is the benefit of using it on the search page (honest question). 
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 20, 2017, 02:09:49 am
The benefits of linked-data, first, let's hear from the man himself.
https://www.youtube.com/watch?v=OM6XIICm_qo&t=18s

k, posting that real quick and typing my 2cents to append here (which should answer your question and hopefully demystifies linked-data for everyone). ...to be continued...

Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 20, 2017, 03:47:37 am
Expanding upon that. So the web is a decentralized documentation system, right? Well, linked-data is a decentralized database, a hierarchy of concepts, a built-in axiomatic proofing system (https://en.wikipedia.org/wiki/Axiomatic_system), the definitive answer to localization (https://en.wikipedia.org/wiki/Internationalization_and_localization).



Machines are dumber-than-children idiots, incapable of abstract concepts, a process which we take for granted. But, if we define our objects (and link them together with relationships), machines are able to reason.
Without semantics, this is simply a block of text which is full-text searched by Google matching only the literal characters of the text, i.e. an exact-word match.
QuoteJill is pregnant.
but with semantics:
A machine can take this minimum input...
Quote<span typeof="Person"><span property="name">Jill</span></span> is pregnant.
And can produce this output about Jill on its own:
Quote<span typeof="Person"><span property="name">Jill</span></span>is pregnant. Only women Persons may be pregnant, so Jill must be a woman.
as a fact, and this as a guess...

Quote<span typeof="Person"><span property="name">Jill</span></span> is a pregnant woman Person whom might benefit from a list of OBGYNs near her geo-location.

which is a different outcome from
Quote<span typeof="Canine"><span property="name">Jill</span></span> is a pregnant female Dog whom probably has an owner who might be looking for an address to an animal shelter


And that's not even scratching the surface of the benefits, many of which are unknown until we reach a certain point in world-wide implementation (like we did with the old web).

Had much more to say about it but gotta roll, but specifically about the search/search-results pages...

Search is the most important feature of ANY site (and the web itself, for that matter), it's what we do the most online. The search feature is undoubtedly the best entry point to (potentially) any piece of data in its scope. So, in my estimation it's the best place to apply my semantic-efforts.

Also, there's Google's "
Sitelinks Searchbox (https://developers.google.com/search/docs/data-types/sitelinks-searchbox)" --but just because you have the correct markup for the schema:SearchAction (and mine is correct and then some), doesn't mean you'll get the Searchbox in your SERs, there are still many factors weighing your relevancy to the user's search. Regardless, it's an in-the-wild example of what is possible with this technology.

tl;d review


More about linked-data from one of the author's of JSON-LD.

https://www.youtube.com/watch?v=4x_xzT5eF5Q

Btw, you've been using a
semantic search via Google (https://en.wikipedia.org/wiki/Google_Hummingbird) since Aug. 2013
Title: Re: total number of search results (prior to pagination)?
Post by: emanuele on May 20, 2017, 04:21:43 am
If I'm not wrong, you may have it in either:
$message['first_post']['time']
$message['first_post']['html_time']
$message['first_post']['timestamp']
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 20, 2017, 05:56:22 am
didn't work
Title: Re: total number of search results (prior to pagination)?
Post by: emanuele on May 20, 2017, 12:26:28 pm
Blame me for looking at 1.1 code instead of 1.0... sorry for the noise. xD
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 22, 2017, 07:33:41 pm
Re: Search

There are a handful of situations where two search <form>s are in the same page (search page), the quicksearch and the advanced search. I'm adding a conditional statement to remove the quicksearch when the advanced is loaded. I'm going to double-check all the semantic markup i've added to make sure everything is pointing to the right <form> under the right condition. Perhaps a little eye-candy for the user here, something like, idk, a faux-quicksearch <form> shrinking on the page until it disappears while the advanced-search <form> expands open.  And of course the real quicksearch <form> will need a transformation reappearing when the user leaves the search-form page. idk it'd be kewl.
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 23, 2017, 07:02:38 pm
Re: Search (update)
updated again, i think this includes all instances of two search <form>s
themes/default/index.template.php
Code: [Select]
if((($context['current_action'] == 'search') && (!isset($context['get_topics'][1]))) || (($context['current_action'] == 'search') && (isset($context['did_you_mean']) || empty($context['topics'])))){	
}else{
echo  'HTML for the quicksearch <form>';
}
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 23, 2017, 08:39:41 pm
I added a dimension of time to my search results (https://validator.w3.org/nu/?showoutline=yes&doc=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dte%3B). This is what a cached Search Results Page should look like, methinks. Of course, page 2 would have a different query date and so on, which means you could actually animate search-results browsing in real-time with this design. That's all just bonus though, i like this design because it implies the very nature of a search-results-page, that it is a dated-result that needs to be reevaluated for accuracy.

 
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 24, 2017, 04:47:21 pm
My regex for the query-input pattern property isn't quite right, anyone care to take a hack at it?

view here (https://search.google.com/structured-data/testing-tool/u/0/#url=https%3A%2F%2Frule34.us%2Fontology%2Frequests%2Findex.php%3Faction%3Dsearch%3Bsa%3Dresults%3Bsearch%3Dt)

Currently, I have this, it says it ignores spaces, accepts input between two and 100 characters, but it also needs to say each space-delimited word must be two characters long.
/[^\s]{2,100}$/
Title: Re: total number of search results (prior to pagination)?
Post by: emanuele on May 24, 2017, 06:20:34 pm
A bit more details may help, it may be it's quite late at night, but I'm not sure what you want to do, sorry... :(
Title: Re: total number of search results (prior to pagination)?
Post by: Atlas on May 24, 2017, 11:31:36 pm
It's not critical or anything, just my perfectionism showing.

I'll explain though, schema.org offers a feature to annotate (https://schema.org/docs/actions.html) <form> elements with constraints for the expected values.
So the
SearchAction (https://schema.org/SearchAction)'s query property contains our search-term, and the query-input property contains the annotation.

Here's the annotation thus far.
<span property="schema:query-input" typeof="schema:PropertyValueSpecification">
     <meta property="schema:valueName" content="search" />
     <meta property="schema:valuePattern" content="/[^\s]{2,100}$/" />
     <meta property="schema:valueMinLength" content="2" />
     <meta property="schema:valueMaxLength" content="100" />
     <link property="schema:valueRequired" href="http://schema.org/True" />
     <link property="schema:multipleValues" href="http://schema.org/True" />
</span>

Note the valuePattern property, this value is a regular expression pattern for "search=term".  Currently, my regex (https://regex101.com/r/tOUeUy/1) states the <input name="search" /> accepts 2-100 characters and ignores spaces. For this to be more accurate, it should state that it accepts 2-100 characters, ignores spaces but each "word" needs to be at least 2 characters long.

The corrected regex should match like so:
t - no match
th 1 match
th r 1 match 1 fail
th re 2 matches


On Second Thought

Nevermind, i was way too focused on that regex that i didn't consider the multipleValues=true accomplishes what i intended in concert with the
existing regex (https://regex101.com/r/tOUeUy/1). So i was right and thought i was wrong and now it's all nevermind.