Sortien in einer Suche

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Sortien in einer Suche

    Hoihoi,

    bin hier immernoch an meiner Softwaresuche. Mittlerweile funktioniert sie echt gut.

    Allerdings gefällt mir die Sortierung noch nicht so gut.

    Bsp:
    PHP-Code:
    $query "SELECT * FROM software WHERE ".
             
    "MATCH(bezeichnung, kurzbeschreibung, beschreibung) ".
             
    "AGAINST('+dvd*','+player*' IN BOOLEAN MODE)"
    Natürlich kann ich das ganze jetzt nach einer beliebigen Spalte sortieren.

    Meine Frage nun: Kann ich zB nach Bezeichnung sortieren, wenn beide Suchworte (hab ich noch in PHP-Variablen) in einer Spalte vorkommen?

    Beispiel (nicht repräsentatives Suchergebnis):
    DVD Archiv
    Datenbank für DVDs
    DVD-Player

    Ich möchte jetzt das DVD-Player ganz nach oben sortiert wird.


    Für irgendwelche Ratschläge oder Ideen bin ich dankbar.

    PS: Ja ich weiß, ich kann natürlich das Ergebniss in PHP durchlaufen und dann entsprechend meinen Kriterien sortieren


    EDIT:
    Sinnhaltigkeit hergestellt *G*
    IN BOOLEAN MODE hinzugefügt

    Zuletzt geändert von prego; 09.08.2005, 15:58.

  • #2
    Aus dem Manual: "When MATCH() is used in a WHERE clause, as in the preceding example, the rows returned are automatically sorted with the highest relevance first. Relevance values are non-negative floating-point numbers. Zero relevance means no similarity. Relevance is computed based on the number of words in the row, the number of unique words in that row, the total number of words in the collection, and the number of documents (rows) that contain a particular word."

    Auf http://dev.mysql.com/doc/mysql/en/fulltext-search.html findest du auch ein Beispiel, wie man an diese relevance values herankommt.
    Ich hoffe es hilft.

    Kommentar


    • #3
      Danke, aber:

      Aus dem MySQL handbuch:
      Boolean full-text searches have these characteristics:
      * They do not automatically sort rows in order of decreasing relevance. You can see this from the preceding query result: The row with the highest relevance is the one that contains “MySQL” twice, but it is listed last, not first.
      Ich mach ja nen Bolean, weil die Worte ja Sinnverkettet sind. Damit sind so Sachen wie "dvd -player" möglich....

      Kommentar


      • #4
        Hab übrigens auch mal folgendes probiert.

        PHP-Code:
        $query "SELECT *, ".
                 
        "MATCH(bezeichnung, kurzbeschreibung, beschreibung) ".
                 
        "AGAINST('+dvd*','+player*' IN BOOLEAN MODE) AS score ".
                 
        " FROM software WHERE ".
                 
        "MATCH(bezeichnung, kurzbeschreibung, beschreibung) ".
                 
        "AGAINST('+dvd*','+player*' IN BOOLEAN MODE)"
        Allerdings ist die Score immer 1... wenn ich das richtig verstanden habe, liegt das am boolean mode.

        Kommentar


        • #5
          Das AGAINST() im Select-Teil mal ohne BOOLEAN MODE versucht?

          "To enhance sorting of the results in boolean mode you can do the following:

          SELECT id, text, MATCH (text) AGAINST ('word1 word2 word3')
          AS score FROM table1
          WHERE MATCH (text) AGAINST ('+word1 +word2 +word3' in boolean mode) order by score desc;

          Using the first MATCH() we get the score in non-boolean search mode (more distinctive). The second MATCH() ensures we really get back only the results we want (with all 3 words)."

          Kommentar


          • #6
            Wenn ich das ohne BOOLEAN mache, dann geht kein "pdf -creator" (finde alles mit pdf ohne creator)

            Wie in meine letzten Beitrag geschrieben kommt so bei "score" immer 1 raus - ich mach es jetzt anders:

            Boolean searching has two deficiencies: 1) results are not sorted by relevance and; 2) no method by which to weigh certain columns. There is a way around both of these problems. For example, if I have a table of articles and want to weigh the title more heavily than the text, I can do the following:

            SELECT *, ( (1.3 * (MATCH(title) AGAINST ('+term +term2' IN BOOLEAN MODE))) + (0.6 * (MATCH(text) AGAINST ('+term +term2' IN BOOLEAN MODE))) ) AS relevance FROM [table_name] WHERE ( MATCH(title,text) AGAINST ('+term +term2' IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY relevance DESC;

            Here we artificially manipulate the relevancy score to give title more weight by multiplying by the constant 1.3.

            Das funktioniert sogar richtig gut. Ist mit Sicherheit nicht der elganteste Weg, aber es funktioniert.

            Besten Dank trotzdem.

            Kommentar

            Lädt...
            X