I've been banging my head with a problem using Sphinx: I need that the query results are returned in alphabetical order by name.
Simplistically, I have a table with two fields only: 'name' and 'address'.
When I use $sp->SetSortMode(SPH_SORT_RELEVANCE) the results come correctly in order of relevance (no alphabetical order instead)
But I need the results orderd by name, so I've tried both:
$sp->SetSortMode(SPH_SORT_ATTR_ASC,'name');
and
$sp->SetSortMode(SPH_SORT_EXTENDED,'name ASC');
Both with no success.
What am I doing wrong?
Field 'name' should be declared as attribute:
sql_attr_str2ordinal = name
You could sort it in alphabetical order using:
$sp->SetSortMode(SPH_SORT_ATTR_ASC,'name');
Related
Assume you're given an InfluxDB measurement you haven't seen before and you run,
SELECT * FROM measurement
How can you tell which of the keys returned are tags, and which are fields? The InfluxDB shell sorts the keys alphabetically, so unlike the Line Protocol, fields don't come before tags.
You can see which is which with
show field keys from <measurement>; show tag keys from <measurement>
There seems to be no indication of which SELECT result columns are fields and which are tags, but you can select all fields separately from tags with
SELECT *::field FROM <measurement>
I have made an Xamarin forms application and the problem that I have a list named lista2 which has an object named poli. Poli is the city that it is located. I want to make a list based on distinct cities, which i have done using this command
var poleislist = lista2.Select(x => x.poli).Distinct();
now I want this poleislist to be sorted based on the amount of times that each element is on the lista2. For example the bigger cities appear more often and I want them in the first places of the list because this list(poleislist) is going to be the itemsource of a picker.
Thank you very much!
Instead of using Distinct you could Group the list, sort it by count descending then Select the poli.
It would be something like this:
var poleislist = lista2.GroupBy(item => item.poli)
.OrderByDescending(a => a.Count())
.Select(x => x.Key)
.ToList();
Note: sorry did not get to test it but this should work. Basically this should get you all the cities in the list, ordered descending by the number of times it appears.
Hope this helps.-
I'm trying to add some items (strings) to a pick list in VSTS. The items get auto sorted alphabetically (ascending order).
Below is the scenario:
I entered 'test' then 'abc' and then 'xyz', but it auto sorts and displays 'abc' then 'test' and then 'xyz'.
Is there any way to avoid this sorting and the items should be inserted in the order they were entered?
And I want to achieve this without writing an extension.
Yes, the values for the picklist (string) Type field can only ordered by alphabet so far.
But there has an user voice Custom Sort Order for TFS Fields (for VSTS, added in comment) about customzing sort order for fields, and you can vote and follow up.
if you are using VSTS, you cannot avoid the sorting or have your own sorting for a list field.
I have the following text fields I search with Sphinx: Title, Description, keywords.
However, sometimes things are narrowed down using categories. We have 3 category fields: CatID1, CatID2 and CatID3.
So, for example, I need to see if the word "Kittens" is in the Title, Description, or Keywords, but I also want to filter so that only items that have the categories (Animals - ID Number 8) or (Pets - ID Number 9) or (Felines - Category ID Number 10) in either of those CatID fields.
To clarify, only show items that have a 8,9 or 10 in CatID1, 2 or 3.
Any ideas on how I would accomplish this using sphinx filtering or searching the CatID1 fields as keywords?
Note: I am able to filter and it works great only using one category, i.e:
if(!empty($cat_str)) {
$cl->SetFilter( 'catid1', array( $cat_str ));
}
Thanks!
Craig
SetFilter takes an array. In your example you are putting $cat_str into an array. A array of one item.
So you just needs to build array with all the ids.
$cl->SetFilter( 'catid', array( $cat1, $cat2, $cat3 ));
But thats not very flexible. So you probably build the array dynamically, rather than hard-coded like that. But thats upto your application how to build the array.
But also storing the ids, in three sperate attributes, makes it hard to search. Notice in the above example, just noticed a attribute called catid. This would be a single multi-value attribute, that contains the ids from all three cat fields. That way its easy to search for ids in ANY of the columns at once.
http://sphinxsearch.com/docs/current.html#mva
if using a sql source, could do with something like
sql_query = SELECT id, title ... , CONCAT_WS(',', CatID1, CatID2 and CatID3) as catid FROM ...
sql_attr_multi = uint catid from field;
I am querying a Model*, which has a field that refers to another Model. Is it possible to order the results using a field in the linked Model?
So for example:
Car contains a field which refers to its OWner. I want to show all Cars sorted by their owner.
(I don't want to use the statement() method since in that case I would have to write the whole query myself)
(*) using http://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_persistence_1_1_generic_1_1_query.html
Yes, it is possible (don't care for the $constraint for the moment):
$query->matching($constraint)->setOrderings(
array('owner.sorting' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING)
)->execute();
Assuming the field in you Car model is named owner and you want to sort by sorting field of the Owner model/table.
When working with 6.2
->setOrderings(Array('model.yourfield' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING))
#Michael and #rob-ot are right. There is one pitfall that took me many hours and that I'd like to mention here:
If your sort field in your related table contains underscores, you have to provide its name to setSortOrderings in lowerCamelCase:
// with database column name my_car_sorting you must define:
$query->matching($constraint)->setOrderings(
array('owner.myCarSorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING)
)->execute();