问题
Yes, each tag has unique Id. It is not necessary that I have to store these unique id's in a table. I can store them in this way…
$tags = array("Music","Sports","Food","Books",………)
Array is the best way for me as it is easily alterable. Moreover the array keys itself will serve as the unique Id's.
But my situation is more critical, so let me elaborate the exact situation.
I have a single table with fields like Id, Title, Description, Tags, etc. etc. etc.
Id | Title | Description | Tags
1 | Sport & Hygine| With sport & music good food is …| Sport, Food
2 | Rock Concert | Great Rock Show at … | Music, Dance
If a user selects (filter) to show records, that has Music in the Tags field. Although the Title and description does not have the word Music at all in the second row, but still it should get the first priority. Also it should be noted that Title and Description are text fields and Sphinx should search the normal way giving appropriate Weights and Ranks to Titles and Description. But Tags field cannot be searched as text indexing. Tags field needs to be filtered.
Therefore, in the above example, if Music is selected, then row 2 should only be displayed, because it is filtered based on Tags and Row 2 only has Music in the Tags field. But Music is also present in Row 1 in the Description field, but here it should be ignored. I hope I am able to clarify the situation. Any hep with this is highly appreciated.
回答1:
The unique-id needs to be unique across all documents. So that "Sports" would have the same ID on all documents, and therefore the same ID can be used for searching. So you search for the ID, not the word.
So the tags can be used to influence ranking, you can put them in a Field. But ALSO store the tag-ids in a MVA, so can use for setFilter.
Something like
Music @tags Music
should work as an extended query. BEcause it requires the word Music in Tags. But also the first term will match all feilds and help with ranking.
来源:https://stackoverflow.com/questions/17827965/sphinx-multi-value-attribute-filter