I have indexed a site using Nutch and now I am searching the index using the Zend Lucene library.
I've actually pulled the Zend libraries into Codeigniter but it is all Zend doing the work.
I can display the title, score and url fine but I can't find the name of the field to display the content from the page.
So far I have the following code
$index = new Zend_Search_Lucene('C:\nutch\nutch-0.9\my-search\index');
$query = $this->input->post('searchQuery');
$hits = $index->find($query);
echo "<p>Index contains " . $index->count() . " documents.</p>";
echo "<p>Search for '" . $query . "' returned " . count($hits) . " hits</p>";
foreach ($hits as $hit)
{
echo "<h4>" . $hit->title . "</h4>";
echo "<p><b>Score:</b> " . sprintf('%.2f', $hit->score) . "</p>";
echo "<p><b>Url:</b> " ."<a href='" . $hit->url . "'>" . $hit->url. "</a></p>";
}
Can anyone help out with the name of the field to display the content or a content summary?
Thanks
I don't know the nutch index format, but whenever I need to check a lucene index I use Luke - Lucene Index Toolbox
It allows you to open an index directory, browse fields and run queries. Very helpful if you're using an unfamiliar index.
Related
I am a bit stuck I am attempting to build out a table with HTML and PHP. Ok got that done. Now I want to add a dynamic dropdown as one of the column options but cant seem to figure out how to mix the PHP, the HTML and the needed FOR EACH loop.
I know its currently wrong but am posting a variable of what I have been trying below.
echo '<td>' . "<select>". "<option value =" . $sf_name . ' '. $sl_name . ">" . $sf_name . ' '. $sl_name . "</option>" .
foreach($Staff_On_Duty as $person){
"<option value =" . $sf_name_option=$person->Staff_First_Name . ' '. $sl_name_option=$person->Staff_Last_Name . ">" . $sf_name_option . ' '. $sl_name_option . "</option>"
}
. "</select>" .'</td>';
I need to have the currently selected individual at the top of the dropdown with the option to change that person out. the first .sf_name comes from higher in the code and gives me the name of the individual currently selected. The foreach runs from the $Staff_On_Duty query to give me everyone working right now. What is the right way to do this?
This is how I would do it, essentially only fill the dropdown and mark the option that should have been selected (other stuff is a matter of preference):
echo("<td><select>");
foreach($Staff_On_Duty as $person){
$sf_name_option=$person->Staff_First_Name; // separated for clarity, you could also use $person->Staff_First_Name everywhere
$sl_name_option=$person->Staff_Last_Name;
echo("<option value = $sf_name_option $sl_name_option");
if (($sf_name_option == $sf_name) && ($sl_name_option == $sl_name)) echo (" selected"); // this is the relevant part, but make sure variable values match!
echo(">$sf_name_option $sl_name_option</option>");
}
echo("</select></td>");
Note that I did not put any quotation marks cause I have no idea what your variables entail, but it would need them if you don't have them in yet, i.e.:
... value=\"$sf_name_option $sl_name_option\" ...
I am using a PHP script to pull large amounts of entries from a database, it looks like this:
foreach($events as $e){ //sets each set of data as a value of $e
$vidID = $e["Test Video YouTube ID"]; //stores each video ID as this variable, so that it can be called when embedding the video
echo "<br>" . '<iframe width="250" height="140" src="http://www.youtube.com/embed/' . $vidID . '?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>' . "<br>"
. '<strong> DOC: </strong>' . $e["Axial Cut"] . " " . '<strong> IPM: </strong>' . $e["Inches Per Minute"] . "<br>" .
'<strong> WOC: </strong>' . $e["Radial Cut"] . " " . '<strong> FPT: </strong>' . $e["Inch per Tooth"] . "<br>" .
'<strong> SFM: </strong>' . round($e["Surface Feet per Minute"]) . "<br>"; //each value here is displayed. use the form '$e["Column to be dislplayed"].'
This displays each field for the entry I need, then goes to the next entry and does the same, displaying every entry in the database.
My issue is that it only displays them in a vertical line, so what is the best way to format the output in such a way that it displays in a grid, with a set amount of columns?
*EDIT - To clarify, I don't want to use something like a CSS table for this. It limits me in that the data cannot automatically fill into columns, instead each entry would either appear in a single column or I would have to update each field every time the database had a new entry which would be quite tedious. So what is the best way to have data automatically flow into these columns and rows?
I'm trying to get all clients database id, but I've been unable to using foreach etc as it always returns the value as NULL.
I need to get a foreach with the database ids and put it in an array
$userchannel = $clients->cid->clientList["client_database_id"];
After some fiddling i managed to get this to work, please verifiy. If you have questions regarding the code. Feel free to ask them.
What i've done in basic is modifing the existed code from the examples shown in the teamspeak php framework site. I used the Android user list for the most code. From there on its just trying and debugging ;)
this code will print the database id of the user together with the username. (Ofcourse from this point you can do everything you want with it.)
Also, maybe take a quick look at the api documentation for the php framework. It has alot of useful coding tips and tricks.
https://docs.planetteamspeak.com/ts3/php/framework/
edit (07-01-17)
Something I also noticed, make sure the query user has enough rights, for ease I made mine server admin query (grants access to all options, Please be aware that this could be insecure in a active site!)
<?php
// load framework files
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
try {
// connect to local server, authenticate and spawn an object for the virtual server on port 9988
$ts3_ServerInstance = TeamSpeak3::factory("serverquery://###:#######:##/?server_port=9987");
$selected_sid = $ts3_ServerInstance->serverList();
$ts3_VirtualServer = $ts3_ServerInstance->serverGetById($selected_sid);
/* walk through list of clients */
echo "<table class=\"list\">\n";
echo "<tr>\n" .
" <th>DB id</th>\n" .
" <th>Nickname</th>\n" .
"</tr>\n";
foreach($ts3_VirtualServer->clientList() as $client) {
echo "<tr>\n" .
" <td>" . $client['client_database_id'] . "</td>" .
" <td>" . htmlspecialchars($client) . "</td>" .
"</tr>\n";
}
echo "</table>\n";
}
catch(Exception $e) {
/* catch exceptions and display error message if anything went wrong */
echo "<span class='error'><b>Error " . $e->getCode() . ":</b> " . $e->getMessage() . "</span>\n";
}
I managed to fix it.
$ts3_VirtualServer->channelGetById(152) // 152 is the channel ID
When I create/edit post to my website, and when I use html tags (either type it by my self or using WYSIWYG editor (in this case nicEdit, but I've used different one - same problem)) it does not show anything on the page.
to be more specific: I have article container which imports php code, which than iterates through the db table and echo posts. This is the code:
<h3>Wydarzenia</h3>
<?php
//collects data from table "events" and sort it by "id" date in descending oreder
$event_table_data = mysqli_query($db_con, "SELECT * FROM events ORDER BY id DESC")
or die(mysqli_error());
//puts the data from "events" into an array
$event_content_array = mysqli_fetch_array($event_table_data);
//makes variables from table columns
$id = id;
$title = title;
$happeninng_date = happen;
$created_date = created;
$content = content;
$author = author;
//add new post button
if((isset($_SESSION['sess_wizardrights'])) && ($_SESSION['sess_wizardrights'] == true)){
echo "<a class='e_event_addpost_link' href='./index.php?link=add_post'><button class='e_event_addpost_button' type='button'>Dodaj nowy post</button></a>";
}
do{
//echo each event for main event article
echo "<span class='b_events_span' id='" . $event_content_array[$id] . "'>";
echo " <a class='b_events_anchor' id='" . $event_content_array[$id] . "'></a>";
echo " <h2 class='b_events_title'>" . $event_content_array[$title] . "</h2>";
if((isset($_SESSION['sess_wizardrights'])) && ($_SESSION['sess_wizardrights'] == true)){
echo "<form class='b_events_edit_form' name='edit_post' action='./index.php?link=edit_post' method='post'>";
echo " <input type='hidden' name='id' value='" . $event_content_array[$id] . "'> ";
echo " <input class='e_events_edit_submit' type='submit' value='Edytuj wydarzenie'>";
echo "</form>";
}
echo " <div class='fb-share-button' data-href='http://www.zhppgkaberdeen.co.uk/index.php?link=events#" . $event_content_array[$id] . "'></div>";
echo " <p class='b_events_happening_date'><i>Data wydarzenia: " . $event_content_array[$happeninng_date] . "</i></p>";
echo " <p class='b_events_content'>" . $event_content_array[$content] . "</p>";
echo " <p class='b_events_created_date'>Utworzono: " . $event_content_array[$created_date] . "</p>";
echo " <p class='b_events_author'><b>Czuwaj!</b><br/>" . $event_content_array[$author] . "</p>";
echo "</span>";
}while($event_content_array = mysqli_fetch_array( $event_table_data ));
?>
When I add tags like <img> for instance with alt="" parameter it completely ruins web page. What I mean by that is that the article container is not shown at all (I've checked that with firebug) as well as everything after the article tag (like footer for instance). What is even more strange is that this: alt="text" did not break the page but every other random word does, how ever it does not show the "text" at image at all.
Similar thing happen when I tried to create table within the post and title or target parameter, I cant remember which one.
I have tried to use htmlentities($event_content_array[$content]), htmlspecialchar($event_content_array[$content]) and mysqli_real_escape_string($do_con, $event_content_array[$content]) -> non of this helped.
Is there a way to fix that or I just need to give up using this tags/parameters?
Thank you for any help or explanation
if you are using e.g echo "<img alt="text">";try to escape the " such as alt=\"text\"
I'm looking to create a formatted product list from an SQL database. My aim is to have a store on my website with a series of small boxes containing some shorthand information about each product, that when clicked will open a pop-up containing detailed information. (I have a working Javascript/JQuery code to create the pop-ups.)
Here is the PHP code so far, simply to get the information from the database and display it on a webpage...
(I've been using XAMPP to provide an environment for me to test the code in)
<?php
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("Database1") or die(mysql_error());
$strSQL = "SELECT * FROM Products";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "<br />";
}
mysql_close();
?>
I want the echoed line to be displayed in a divider, with a divider generated for each record in the SQL database (say I have 10 products available, there would be ten dividers, and 10 different boxes on the webpage). The divider's class is "ProductBox".
echo "<div class=\"ProductBox\">"; $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
This was the closest I have come to a solution, which was simply managing to write a code with no syntax errors - alas, nothing actually displays on the webpage.
If I'm going about this entirely the wrong way please tell me - I'm fairly sure I need to use a SQL database to dynamically update stock on a live website, but if I need to implement a different programming language or whatever then just tell me what you think would work and help me with a solution.
You have an extra semicolon in your code
echo "<div class=\"ProductBox\">"; $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
Replace with
echo "<div class=\"ProductBox\">". $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
mysql_fetch_array needs to be used like this (see PHP Doc):
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
}
or you could just use "mysql_fetch_assoc" instead.
HOWEVER, if you're new to PHP, I HIGHLY RECOMMEND that you get started on the right foot. mysql_query functions are soon to be deprecated. DON'T USE THEM. Most recommend using "PDO" for querying your database. Here's a great tutorial to teach you: http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
Also, as mentioned, you have an extra semi-colon.
Dont forget these basics markups :
`<HTML>
<HEAD>
</HEAD>
<BODY> put in here your divs
</BODY>
</HTML>`