CenterForDigitalHumanities / DigiSig

DigiSig is a new resource for the study of sigillography, particularly medieval seals from the British Isles. It aims to foster sigillographic research by linking and matching sigillographic datasets and making that information available
http://www.digisig.org
1 stars 2 forks source link

Search Results -- description #33

Open johnmcewan opened 9 years ago

johnmcewan commented 9 years ago

I searched for 'bird' and got back a table listing hits in descriptions

The information that appears in the column under ‘reference’ is the description. The description column, by contrast, has the reference link. It looks like somehow reference and description got swaped around.

thehabes commented 9 years ago

You need to make the columns in the rows in your database to their original order. Look at this screen shot (Just search Henry III if you can't see it).

search

When before all of these columns lined up, now the first result returns the content for the middle column first and the reference second. The second result returns the content for the middle column second and the reference first. The third result returns the content for the middle column first and the reference column second. This fundamentally changes how the code works, and the code can no longer work with a while loop with this inconsistency. You will either have to rewrite this while loop:

while ($row = mysqli_fetch_array($query5result)) { $value1 = $row[0]; $value2 = $row[1]; $value3 = $row[2];

                if($value1 == ""){
                    $value1 = "<i>empty</i>";
                }
                if($value2 == ""){
                    $value2 = "<i>empty</i>";
                }
                if($value3 == ""){
                    $value3 = "<i>empty</i>";
                }
                echo '<tr><td>' . $rowcount . '</td>'; //
                if(strlen($value2) >= $table_text_len){
                    $short_value2 = substr($value2, 0, $table_text_len);
                    echo '<td><a id="a_'.$value1.'" href=' . $address . '/entity/'.$value1.'>'. $short_value2 . '...</a> <a id="get_'.$value1.'" onclick="getFullText('.$value1.')">(More)</a><input type="hidden" id="full_'.$value1.'" value="'.$value2.'" /><input type="hidden" id="short_'.$value1.'" value="'.$short_value2.'" /></td><td>'. $value3. '</td></tr>';
                }else{
                    echo '<td><a id="a_'.$value1.'" href=' . $address . '/entity/'.$value1.'>'.$value2.'</a></td><td>'. $value3. '</td></tr>';
                }

                $rowcount++;
            }

and handle detecting the inconsistency and building the table in accordance

OR revert you database back to the original order it was in. You need to be careful when adding data into the database. If you reorder the columns, you will change how the code works.

thehabes commented 9 years ago

Here is what happens when I reassign value2. As you can see, the query does not return a consistent order of results anymore so changing the assignation of value2 still does not resolve the problem, since the order of results the query is returning differs from row to row, whereas before the result the query was returning was always in the same order.

search2

johnmcewan commented 9 years ago

I suspect that the problem originates in the 'field' table. Sorry for being slow to address this today. This took a bit of thought.

I would suggest that the 'description' search is behaving differently from the others because there is a difference in the variables it returns (as you suspected). In table 'field' in the 'field_returnedvariables' column is a string that defines which values the query should return for the 'description' search:

id_sealdescription, sealdescription, motif_obverse, a_index

You can see here that there are four items in the list, whereas all the other searches have just three. In the 'description' case to make the existing code work the value in the fourth position should be in the third position and the value in the third position in the second positon. This is my fault. A few days before I left I seem to recall working on a fix for completely different bug. I didn't finish so I didn't pass along the associated code but it looks like I forgot to put the 'field' table back. Sorry!

The proper fix is to just go into the table 'field' and move 'sealdescription' to the end of the list:

id_sealdescription, motif_obverse, a_index, sealdescription

I bet that will fix things.

An alternative is to leave the database alone and fix the problem on the front end. What we would need to do is ensure that in the case that some one runs a search on description that we make the adjustments

Firstly we need to assign the value in position four to a varible: $value4 = $row[3];

And then (pseudo code)

Where user searches seal descriptions then $value2 = $value3 $value3 = $value4 end if Run query as normal.

Does that make sense? Even better, does it fix the problem?

thehabes commented 9 years ago

Yes, the problem could be solved on the front end with such an algorithm. I do feel it is a more structurally sound fix to align the response from the database. With a project so dependent on database interaction it is best for future work to ensure database responses remain consistent with the way you have coded it to be dependent on the order of the response.

So the fix for this on the front end would be to always ignore the order of the response and get data from the row[] object by keys. Instead of

while ($row = mysqli_fetch_array($query5result)) { $value1 = $row[0]; $value2 = $row[1]; $value3 = $row[2]; }

use a query to get an object result instead of an array result like so:

while ($row = mysqli_fetch_object($query5result)) { $value1 = ""; $value2 = ""; $value3 = ""; $value4 = "" if($row['id_sealdescription'] !== null && $row['id_sealdescription'] !==""){ $value1 = $row['id_sealdescription'] ; } if($row['motif_obverse'] !== null && $row['motif_obverse'] !==""){ $value2 = $row['motif_obverse'] ; } if($row['a_index'] !== null && $row['a_index'] !==""){ $value3 = $row['a_index'] ; } if($row['sealdescription'] !== null && $row['sealdescription'] !==""){ $value4 = $row['sealdescription'] ; }

}

As you can see, this method does not depend on the order of the result query since it access each data piece via a key to get the data from a set of key:value pairs.

Best practice says to pick a strategy and stick with it throughout the project (when possible). There are other areas where you did it this way. If you are going to be using arrays whose order you depend on, you should make sure that order is reflected in the database itself or plan to ignore it entirely.

thehabes commented 9 years ago

Switching the order in the database did the fix. I will stick with that for now.

thehabes commented 9 years ago

After testing, it did not work. There are still spots where entries come back as empty. We may have to look at the coding schema like suggested above to try to implement a fix

thehabes commented 9 years ago

This problem still persists, even after reordering id_sealdescription, sealdescription, motif_obverse, a_index to id_sealdescription, motif_obverse, a_index, sealdescription

Search for 'henry' and look at the results returned for Catalogue. Reference is always empty.