I have the following PHP script and am using the sphinx search API. I want to search for a custom keyword but only in the title column of the MySQL database.
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_EXTENDED);
$s->SetLimits(0, 10000);
$result = $s->Query("#(title) apple");
Unfortunately this returns nothing but when i use the following script:
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_EXTENDED);
$s->SetLimits(0, 10000);
$result = $s->Query("apple");
I obtain the results, the problem is that the script searches in all columns.
What am I doing wrong?
I should also mention that on localhost (using XAMPP) it is working fine like in the first example.
One thing I do notice, you dont explicitly note which index going to search - so the Query() searches ALL indexes.
Persumably then on one server you have an index that doesnt contain #title.
... for maximum compatiblity (so it doesnt matter waht other indexes add to the server, should probably search a specific index...
$s->Query("#(title) apple",'my_index');
Related
I'm needing to create more than 1 filter to run a query to cut down the number of results found.
I am trying to do these 3 queries at once using RethinkDB for php found here
The code I am running is:
$query = \r\table('payments')->filter(
\r\row('forwarded')->eq('1'),
\r\row('bad_callbacks_sent')->lt("1"),
\r\row('confirmations')->le('7')
)->run($this->conn);
I've just also tried doing the following and it doesn't work (it's just showing all where the first argument - where forwarded = 1. It's only doing the first filter:
$query = \r\table('payments')
->filter(\r\row('forwarded')->eq('1'))
->filter(\r\row('bad_callbacks_sent')->lt("6"))
->filter(\r\row('confirmations')->le("7"))
->run($this->conn);
But it doesn't seem to be doing what I ask.
I need to make it get:
Where forwarded == 1
Where bad_callbacks_sent < 1
Where confirmations <= 7
I found this the following code from here, which shows that you can chain them in js but I'm wondering about PHP:
r.db('items').table('tokens')
.filter(r.row('valid_to').gt(r.now()))
.filter(r.row["processed"] == False)
Any ideas?
Okay so it turns out, the issue was not with my new code:
$query = \r\table('payments')
->filter(\r\row('forwarded')->eq('1'))
->filter(\r\row('bad_callbacks_sent')->lt(6))
->filter(\r\row('confirmations')->le(7))
->run($this->conn);
But with the variable type.
In my database, it was stored as an int but I was trying to read it via (le("7")) a string.
The above code works fine :)
It allows you to filter more than 1 query in retihnkdb for php.
Make sure you check your variable types in your database!
RethinkDB is very sensitive to what types they're.
Hope I save you some time.
Please can somebody be so kind to show me the syntax for using cloneblock in phpword.
So Ive got data in a MySQL DB, and for the single rows that I need to import into my word doc via phpword it works fine....to run my query and search and replace with template processor. BUT, now I want to insert multiple rows into my word document. I've researched and found that the cloneblock method is the answer. However I cannot get it working....currently my code runs but it doesn't seem to get to the second row.
I actually dnt get any error messages. My code executes fine...but the end display word file doesn't display fine....and if you see my code I got an echo statement...which echo's out in my browser exactly what I want "damaged" &"good", (as an example given of one of the row data) but that data doesn't get pulled into my word doc like that...it duplicates "damaged" , "damaged". .
$group_key=1;
do {
//loop to increase my uuid - ($repeatgroup')
$repeatgroup = $id."/"."trailer_repeat_group"."[".$group_key."]";
// query string
$trailer_repeat_grouping = mysqli_query($connect, "SELECT * FROM trailer_repeat_group LEFT JOIN main on trailer_repeat_group.PARENT_KEY = main.metainstanceID WHERE trailer_repeat_group.KEY_id = '$repeatgroup'");
$templateProcessor->cloneBlock('CLONEME', $trailer_count);
while ($row1 = mysqli_fetch_array($trailer_repeat_grouping)) {
//this echo below I am using to test exactly what happends – independent of
//PHPword/templateprocessor
echo $rttc = $row1['right_trailer_tyre_condition'];
//inserting / searching / inserting values
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc);
}
// ending of loop / checking loop
$group_key++;
} while ($group_key <= $trailer_count);
I've done investigation and found the solution.
You're cloning same blocks N times:
$templateProcessor->cloneBlock('CLONEME', $trailer_count);
and then by doing fetch You're trying to replace right_trailer_tyre_condition with some value:
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc);
Issue is that You're replacing all placeholders.
But in fact You need to replace them one by one with different values.
Solution is to define 3rd argument that means count of items to replace.
Simply change it to be:
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc, 1);
I have multiple sources, like this (say)
source src1{
...
}
source src2{
...
}
AND
index src1{
...
}
index src2{
...
}
src1 has sql query from one individual table and src2 has sql query based on another individual table.
Now, in the PHP script, how do I specify, which indexer to use?
Normally, in the PHP script, we write it this way
$ss = new SphinxClient;
$ss->setServer("localhost", 9312);
$ss->setMatchMode(SPH_MATCH_ANY);
Since, there is no mention about the indexer being used. It's useless to search both indexes (i.e., both tables). I want to search the index src2(say) i.e., data from the second table. So, how do I specify this in my php script, that sphinx should search only that particular indexer.
The Query call includes the index(s) to search
$res = $cl->Query($query,"src1");
For one index (per Barry Hunter)
$res = $cl->Query($query,"src1");
or
For multiple indexes for one query.
$res = $cl->Query($query,"src1 src2 src3 src4");
I am using the following code:
include('sphinxapi.php');
$search = "John"
$s = new SphinxClient;
$s->SetServer("localhost", 9312);
$s->SetMatchMode(SPH_MATCH_EXTENDED2);
$s->SetSortMode(SPH_SORT_EXTENDED, 'name ASC');
$nameindex = $s->Query("$search");
echo $nameindex['total_found'];
This returns a blank page however without the SetSortMode it works fine and returns the number of results. No matter what I set the SetSortMode to it does not work. Any ideas as to why this would be?
I am indexing one column called name
You can't sort by (normal) fields in Sphinx, only attributes, or fields marked with the sql_field_string setting (which creates an attribute of the same name). So you'll need to either add an attribute with the same column, or use sql_field_string - they're equivalent.
Also: I've removed the thinking-sphinx tag - you're not using Ruby, and thus not the Thinking Sphinx library.
I'm currently indexing a database with lucene. I was thinking of storing the table id in the index, but I can't find a way to retrieve the documents by that field. I guess some pseudo-code will further clarify the question:
document.add("_id", 7, Field.Index.UN_TOKENIZED, Field.Store.YES);
// How can I query the document with _id=7
// without getting the document with _id=17 or _id=71?
EDIT for Zend Lucene:
You will need a Keyword type field in order for it to be searched.
For indexing, use something like:
$doc->addField(Zend_Search_Lucene_Field::Keyword('_id', '7'));
For search, use:
$idTerm = new Zend_Search_Lucene_Index_Term('_id', '7');
$idQuery = new Zend_Search_Lucene_Search_Query_Term($idTerm);
Just to say I've just implemented this successfully on my Zend Lucene search engine. However, after some time troubleshooting I discovered that the field name and field value are the opposite way around to the way shown. To correct the example:
// Fine - no change here
$doc->addField(Zend_Search_Lucene_Field::Keyword('_id', '7'));
// Reversed order of parameters
$idTerm = new Zend_Search_Lucene_Index_Term('7', '_id',);
$idQuery = new Zend_Search_Lucene_Search_Query_Term($idTerm);
I hope that helps someone!