Blog

Textpattern: Suche auf custom-fields erweitern / Expand search of textpattern to custom fields

Gerrit hatte gerade das Problem, dass die Standardsuche von Textpattern die custom-Felder nicht durchsucht. Da ich auch einige Seiten mit Txp und custom-Feldern erstellt habe, dachte ich mir, ihm kann sicher geholfen werden, und siehe da, es geht!

Anleitung

  1. Öffne phpMyAdmin (eine Shell tut's wohl auch, aber da kenne ich den Befehl nicht auswendig), suche die Tabelle "textpattern", öffne sie in der Struktur-Ansicht, suche unten bei Indizes den Wert "searching" und füge die Felder hinzu, die du durchsucht haben möchtest. (Dazu klickt man auf den Stift, und kann einfach weitere Spalten hinzufügen.) Achtung: Nicht unbedingt alle Felder hinzufügen, wenn man sie nicht wirklich braucht, da dadurch die Suche langsamer werden könnte.
  2. Öffne Datei textpattern/publish.php und ändere die Zeilen $match = ... und $search = ... (um 515 in 4.0.1) entsprechend diesem Beispiel für das Feld custom_1 ab:
    $match = ", match (Title,Body,custom_1) against ('$q') as score";
    $search = " and (Title rlike '$q' or Body rlike '$q' or custom_1 rlike '$q') $s_filter";
    
    Wenn noch weitere Felder duchsucht werden sollen, diese einfach in beiden Zeilen hinten dran hängen.
  3. Das war's ;)

Vielleicht hilft's ja noch jemandem; im Txp-Forum gab es schon einige Anfragen danach, daher auch die folgende englische Version.

Instruction in english

For expanding the search of the cms textpattern to custom fields, the following 2 steps are necessare:

  1. Open phpMyAdmin, search for the table "textpattern", open it in the structure-view, find below at the Indexes the value "searching" and add the fields you wanted to search in. (For this you click on the pen, and then you can add easily more columns.)
  2. Open the file textpattern/publish.php and modify the lines $match = ... and $search = ... (around 515 in 4.0.1) according this example for field custom_1:
    $match = ", match (Title,Body,custom_1) against ('$q') as score";
    $search = " and (Title rlike '$q' or Body rlike '$q' or custom_1 rlike '$q') $s_filter";
    
    If you wanted to search in more fields, add the corresponding expression in the brackets above for more fields.
  3. That's it!

30.10.05 | in | Tags:

0 Kommentare bisher

Kommentare geschlossen.

|

Suche

Meta

RSS / Atom

Archiv

CC CreativeCommons

Ich lese:

uninformation.org, Gerrit, Jens, Thomas, Oliver, jot-be, fukami und viele andere mehr...